1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cmobi\RabbitmqBundle\Tests\Transport\Subscriber; |
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\Subscriber\SubscriberBuilder; |
13
|
|
|
use Cmobi\RabbitmqBundle\Transport\Subscriber\SubscriberQueueBag; |
14
|
|
|
|
15
|
|
View Code Duplication |
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
|
|
|
|
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.