|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Enqueue\Tests\Client; |
| 4 | + |
| 5 | +use Enqueue\Client\Config; |
| 6 | +use Enqueue\Client\DriverInterface; |
| 7 | +use Enqueue\Client\DriverPreSend; |
| 8 | +use Enqueue\Client\Message; |
| 9 | +use Enqueue\Client\ProducerInterface; |
| 10 | +use Enqueue\Test\ClassExtensionTrait; |
| 11 | +use PHPUnit\Framework\TestCase; |
| 12 | + |
| 13 | +class DriverPreSendTest extends TestCase |
| 14 | +{ |
| 15 | + use ClassExtensionTrait; |
| 16 | + |
| 17 | + public function testShouldBeFinal() |
| 18 | + { |
| 19 | + self::assertClassFinal(DriverPreSend::class); |
| 20 | + } |
| 21 | + |
| 22 | + public function testCouldBeConstructedWithExpectedArguments() |
| 23 | + { |
| 24 | + new DriverPreSend( |
| 25 | + new Message(), |
| 26 | + $this->createProducerMock(), |
| 27 | + $this->createDriverMock() |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + public function testShouldAllowGetArgumentSetInConstructor() |
| 32 | + { |
| 33 | + $expectedMessage = new Message(); |
| 34 | + $expectedProducer = $this->createProducerMock(); |
| 35 | + $expectedDriver = $this->createDriverMock(); |
| 36 | + |
| 37 | + $context = new DriverPreSend( |
| 38 | + $expectedMessage, |
| 39 | + $expectedProducer, |
| 40 | + $expectedDriver |
| 41 | + ); |
| 42 | + |
| 43 | + $this->assertSame($expectedMessage, $context->getMessage()); |
| 44 | + $this->assertSame($expectedProducer, $context->getProducer()); |
| 45 | + $this->assertSame($expectedDriver, $context->getDriver()); |
| 46 | + } |
| 47 | + |
| 48 | + public function testShouldAllowGetCommand() |
| 49 | + { |
| 50 | + $message = new Message(); |
| 51 | + $message->setProperty(Config::PARAMETER_TOPIC_NAME, Config::COMMAND_TOPIC); |
| 52 | + $message->setProperty(Config::PARAMETER_COMMAND_NAME, 'theCommand'); |
| 53 | + |
| 54 | + $context = new DriverPreSend( |
| 55 | + $message, |
| 56 | + $this->createProducerMock(), |
| 57 | + $this->createDriverMock() |
| 58 | + ); |
| 59 | + |
| 60 | + $this->assertFalse($context->isEvent()); |
| 61 | + $this->assertSame('theCommand', $context->getCommand()); |
| 62 | + } |
| 63 | + |
| 64 | + public function testShouldAllowGetTopic() |
| 65 | + { |
| 66 | + $message = new Message(); |
| 67 | + $message->setProperty(Config::PARAMETER_TOPIC_NAME, 'theTopic'); |
| 68 | + |
| 69 | + $context = new DriverPreSend( |
| 70 | + $message, |
| 71 | + $this->createProducerMock(), |
| 72 | + $this->createDriverMock() |
| 73 | + ); |
| 74 | + |
| 75 | + $this->assertTrue($context->isEvent()); |
| 76 | + $this->assertSame('theTopic', $context->getTopic()); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * @return \PHPUnit_Framework_MockObject_MockObject |
| 81 | + */ |
| 82 | + private function createDriverMock(): DriverInterface |
| 83 | + { |
| 84 | + return $this->createMock(DriverInterface::class); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * @return \PHPUnit_Framework_MockObject_MockObject |
| 89 | + */ |
| 90 | + private function createProducerMock(): ProducerInterface |
| 91 | + { |
| 92 | + return $this->createMock(ProducerInterface::class); |
| 93 | + } |
| 94 | +} |
0 commit comments