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