1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cmobi\RabbitmqBundle\Tests\Transport\PubSub; |
4
|
|
|
|
5
|
|
|
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPChannel; |
6
|
|
|
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPConnection; |
7
|
|
|
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPConnectionInterface; |
8
|
|
|
use Cmobi\RabbitmqBundle\Connection\ConnectionManager; |
9
|
|
|
use Cmobi\RabbitmqBundle\Queue\QueueInterface; |
10
|
|
|
use Cmobi\RabbitmqBundle\Queue\QueueServiceInterface; |
11
|
|
|
use Cmobi\RabbitmqBundle\Tests\BaseTestCase; |
12
|
|
|
use Cmobi\RabbitmqBundle\Transport\PubSub\ExchangeType; |
13
|
|
|
use Cmobi\RabbitmqBundle\Transport\PubSub\SubscriberBuilder; |
14
|
|
|
|
15
|
|
|
class SubscriberBuilderTest extends BaseTestCase |
16
|
|
|
{ |
17
|
|
|
public function testGetConnectionManager() |
18
|
|
|
{ |
19
|
|
|
$subscriberBuilder = new SubscriberBuilder( |
20
|
|
|
'test', |
21
|
|
|
ExchangeType::FANOUT, |
22
|
|
|
$this->getConnectionManagerMock(), |
23
|
|
|
$this->getLoggerMock(), [] |
24
|
|
|
); |
25
|
|
|
$connectionManager = $subscriberBuilder->getConnectionManager(); |
26
|
|
|
|
27
|
|
|
$this->assertInstanceOf(ConnectionManager::class, $connectionManager); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
View Code Duplication |
public function testBuildQueue() |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$subscriberBuilder = new SubscriberBuilder( |
33
|
|
|
'test', |
34
|
|
|
ExchangeType::FANOUT, |
35
|
|
|
$this->getConnectionManagerMock(), |
36
|
|
|
$this->getLoggerMock(), |
37
|
|
|
[] |
38
|
|
|
); |
39
|
|
|
$queue = $subscriberBuilder->buildQueue('test', $this->getQueueServiceMock()); |
40
|
|
|
|
41
|
|
|
$this->assertInstanceOf(QueueInterface::class, $queue); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function testGetExchange() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$subscriberBuilder = new SubscriberBuilder( |
47
|
|
|
'test_exchange', |
48
|
|
|
ExchangeType::FANOUT, |
49
|
|
|
$this->getConnectionManagerMock(), |
50
|
|
|
$this->getLoggerMock(), |
51
|
|
|
[] |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$this->assertEquals('test_exchange', $subscriberBuilder->getExchangeName()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
View Code Duplication |
public function testGetExchangeType() |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$subscriberBuilder = new SubscriberBuilder( |
60
|
|
|
'test_exchange', |
61
|
|
|
ExchangeType::DIRECT, |
62
|
|
|
$this->getConnectionManagerMock(), |
63
|
|
|
$this->getLoggerMock(), |
64
|
|
|
[] |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$this->assertEquals(ExchangeType::DIRECT, $subscriberBuilder->getExchangeType()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return CmobiAMQPConnectionInterface |
72
|
|
|
*/ |
73
|
|
View Code Duplication |
protected function getAMQPStreamConnectionMock() |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
$class = $this->getMockBuilder(CmobiAMQPConnection::class) |
76
|
|
|
->disableOriginalConstructor() |
77
|
|
|
->getMock(); |
78
|
|
|
|
79
|
|
|
$channelMock = $this->getMockBuilder(CmobiAMQPChannel::class) |
80
|
|
|
->disableOriginalConstructor() |
81
|
|
|
->getMock(); |
82
|
|
|
$channelMock->expects($this->any()) |
83
|
|
|
->method('basic_qos') |
84
|
|
|
->willReturn(true); |
85
|
|
|
|
86
|
|
|
$class->method('channel') |
87
|
|
|
->willReturn($channelMock); |
88
|
|
|
|
89
|
|
|
return $class; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return ConnectionManager |
94
|
|
|
*/ |
95
|
|
|
protected function getConnectionManagerMock() |
96
|
|
|
{ |
97
|
|
|
$connectionManagerMock = $this->getMockBuilder(ConnectionManager::class) |
98
|
|
|
->disableOriginalConstructor() |
99
|
|
|
->getMock(); |
100
|
|
|
|
101
|
|
|
return $connectionManagerMock; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return QueueServiceInterface |
106
|
|
|
*/ |
107
|
|
|
protected function getQueueServiceMock() |
108
|
|
|
{ |
109
|
|
|
$queueCallback = $this->getMockBuilder(QueueServiceInterface::class) |
110
|
|
|
->disableOriginalConstructor() |
111
|
|
|
->getMock(); |
112
|
|
|
|
113
|
|
|
return $queueCallback; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.