1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cmobi\RabbitmqBundle\Tests\Transport\Rpc; |
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\Worker\WorkerBuilder; |
13
|
|
|
|
14
|
|
|
class WorkerBuilderTest extends BaseTestCase |
15
|
|
|
{ |
16
|
|
View Code Duplication |
public function testGetConnectionManager() |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
$workerServer = new WorkerBuilder($this->getConnectionManagerMock(), $this->getLoggerMock(), []); |
19
|
|
|
$connectionManager = $workerServer->getConnectionManager(); |
20
|
|
|
|
21
|
|
|
$this->assertInstanceOf(ConnectionManager::class, $connectionManager); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
View Code Duplication |
public function testBuildQueue() |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$workerServer = new WorkerBuilder($this->getConnectionManagerMock(), $this->getLoggerMock(), []); |
27
|
|
|
$queue = $workerServer->buildQueue('test', $this->getQueueServiceMock()); |
28
|
|
|
|
29
|
|
|
$this->assertInstanceOf(QueueInterface::class, $queue); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @return CmobiAMQPConnectionInterface |
34
|
|
|
*/ |
35
|
|
View Code Duplication |
protected function getAMQPStreamConnectionMock() |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
$class = $this->getMockBuilder(CmobiAMQPConnection::class) |
38
|
|
|
->disableOriginalConstructor() |
39
|
|
|
->getMock(); |
40
|
|
|
|
41
|
|
|
$channelMock = $this->getMockBuilder(CmobiAMQPChannel::class) |
42
|
|
|
->disableOriginalConstructor() |
43
|
|
|
->getMock(); |
44
|
|
|
$channelMock->expects($this->any()) |
45
|
|
|
->method('basic_qos') |
46
|
|
|
->willReturn(true); |
47
|
|
|
|
48
|
|
|
$class->method('channel') |
49
|
|
|
->willReturn($channelMock); |
50
|
|
|
|
51
|
|
|
return $class; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return ConnectionManager |
56
|
|
|
*/ |
57
|
|
|
protected function getConnectionManagerMock() |
58
|
|
|
{ |
59
|
|
|
$connectionManagerMock = $this->getMockBuilder(ConnectionManager::class) |
60
|
|
|
->disableOriginalConstructor() |
61
|
|
|
->getMock(); |
62
|
|
|
|
63
|
|
|
return $connectionManagerMock; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return QueueServiceInterface |
68
|
|
|
*/ |
69
|
|
|
protected function getQueueServiceMock() |
70
|
|
|
{ |
71
|
|
|
$queueCallback = $this->getMockBuilder(QueueServiceInterface::class) |
72
|
|
|
->disableOriginalConstructor() |
73
|
|
|
->getMock(); |
74
|
|
|
|
75
|
|
|
return $queueCallback; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
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.