| @@ 15-79 (lines=65) @@ | ||
| 12 | use Cmobi\RabbitmqBundle\Transport\Worker\WorkerBuilder; |
|
| 13 | use Cmobi\RabbitmqBundle\Transport\Worker\WorkerQueueBag; |
|
| 14 | ||
| 15 | class WorkerBuilderTest extends BaseTestCase |
|
| 16 | { |
|
| 17 | public function testGetConnectionManager() |
|
| 18 | { |
|
| 19 | $workerServer = new WorkerBuilder($this->getConnectionManagerMock(), $this->getLoggerMock(), []); |
|
| 20 | $connectionManager = $workerServer->getConnectionManager(); |
|
| 21 | ||
| 22 | $this->assertInstanceOf(ConnectionManager::class, $connectionManager); |
|
| 23 | } |
|
| 24 | ||
| 25 | public function testBuildQueue() |
|
| 26 | { |
|
| 27 | $workerServer = new WorkerBuilder($this->getConnectionManagerMock(), $this->getLoggerMock(), []); |
|
| 28 | $workerBag = new WorkerQueueBag('test_queue'); |
|
| 29 | $queue = $workerServer->buildQueue('test', $this->getQueueServiceMock(), $workerBag); |
|
| 30 | ||
| 31 | $this->assertInstanceOf(QueueInterface::class, $queue); |
|
| 32 | } |
|
| 33 | ||
| 34 | /** |
|
| 35 | * @return CmobiAMQPConnectionInterface |
|
| 36 | */ |
|
| 37 | protected function getAMQPStreamConnectionMock() |
|
| 38 | { |
|
| 39 | $class = $this->getMockBuilder(CmobiAMQPConnection::class) |
|
| 40 | ->disableOriginalConstructor() |
|
| 41 | ->getMock(); |
|
| 42 | ||
| 43 | $channelMock = $this->getMockBuilder(CmobiAMQPChannel::class) |
|
| 44 | ->disableOriginalConstructor() |
|
| 45 | ->getMock(); |
|
| 46 | $channelMock->expects($this->any()) |
|
| 47 | ->method('basic_qos') |
|
| 48 | ->willReturn(true); |
|
| 49 | ||
| 50 | $class->method('channel') |
|
| 51 | ->willReturn($channelMock); |
|
| 52 | ||
| 53 | return $class; |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * @return ConnectionManager |
|
| 58 | */ |
|
| 59 | protected function getConnectionManagerMock() |
|
| 60 | { |
|
| 61 | $connectionManagerMock = $this->getMockBuilder(ConnectionManager::class) |
|
| 62 | ->disableOriginalConstructor() |
|
| 63 | ->getMock(); |
|
| 64 | ||
| 65 | return $connectionManagerMock; |
|
| 66 | } |
|
| 67 | ||
| 68 | /** |
|
| 69 | * @return QueueServiceInterface |
|
| 70 | */ |
|
| 71 | protected function getQueueServiceMock() |
|
| 72 | { |
|
| 73 | $queueCallback = $this->getMockBuilder(QueueServiceInterface::class) |
|
| 74 | ->disableOriginalConstructor() |
|
| 75 | ->getMock(); |
|
| 76 | ||
| 77 | return $queueCallback; |
|
| 78 | } |
|
| 79 | } |
|
| 80 | ||
| @@ 15-85 (lines=71) @@ | ||
| 12 | use Cmobi\RabbitmqBundle\Transport\Subscriber\SubscriberBuilder; |
|
| 13 | use Cmobi\RabbitmqBundle\Transport\Subscriber\SubscriberQueueBag; |
|
| 14 | ||
| 15 | class SubscriberBuilderTest extends BaseTestCase |
|
| 16 | { |
|
| 17 | public function testGetConnectionManager() |
|
| 18 | { |
|
| 19 | $subscriberBuilder = new SubscriberBuilder( |
|
| 20 | $this->getConnectionManagerMock(), |
|
| 21 | $this->getLoggerMock(), [] |
|
| 22 | ); |
|
| 23 | $connectionManager = $subscriberBuilder->getConnectionManager(); |
|
| 24 | ||
| 25 | $this->assertInstanceOf(ConnectionManager::class, $connectionManager); |
|
| 26 | } |
|
| 27 | ||
| 28 | public function testBuildQueue() |
|
| 29 | { |
|
| 30 | $subscriberBuilder = new SubscriberBuilder( |
|
| 31 | $this->getConnectionManagerMock(), |
|
| 32 | $this->getLoggerMock() |
|
| 33 | ); |
|
| 34 | $subscriberQueueBag = new SubscriberQueueBag('test_exchange'); |
|
| 35 | $queue = $subscriberBuilder->buildQueue('test', $this->getQueueServiceMock(), $subscriberQueueBag); |
|
| 36 | ||
| 37 | $this->assertInstanceOf(QueueInterface::class, $queue); |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * @return CmobiAMQPConnectionInterface |
|
| 42 | */ |
|
| 43 | protected function getAMQPStreamConnectionMock() |
|
| 44 | { |
|
| 45 | $class = $this->getMockBuilder(CmobiAMQPConnection::class) |
|
| 46 | ->disableOriginalConstructor() |
|
| 47 | ->getMock(); |
|
| 48 | ||
| 49 | $channelMock = $this->getMockBuilder(CmobiAMQPChannel::class) |
|
| 50 | ->disableOriginalConstructor() |
|
| 51 | ->getMock(); |
|
| 52 | $channelMock->expects($this->any()) |
|
| 53 | ->method('basic_qos') |
|
| 54 | ->willReturn(true); |
|
| 55 | ||
| 56 | $class->method('channel') |
|
| 57 | ->willReturn($channelMock); |
|
| 58 | ||
| 59 | return $class; |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * @return ConnectionManager |
|
| 64 | */ |
|
| 65 | protected function getConnectionManagerMock() |
|
| 66 | { |
|
| 67 | $connectionManagerMock = $this->getMockBuilder(ConnectionManager::class) |
|
| 68 | ->disableOriginalConstructor() |
|
| 69 | ->getMock(); |
|
| 70 | ||
| 71 | return $connectionManagerMock; |
|
| 72 | } |
|
| 73 | ||
| 74 | /** |
|
| 75 | * @return QueueServiceInterface |
|
| 76 | */ |
|
| 77 | protected function getQueueServiceMock() |
|
| 78 | { |
|
| 79 | $queueCallback = $this->getMockBuilder(QueueServiceInterface::class) |
|
| 80 | ->disableOriginalConstructor() |
|
| 81 | ->getMock(); |
|
| 82 | ||
| 83 | return $queueCallback; |
|
| 84 | } |
|
| 85 | } |
|
| 86 | ||