Completed
Push — master ( 1fce20...c903a9 )
by Daniel
03:12
created

TaskTest::getConnectionMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Tests\Transport\Worker;
4
5
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPChannel;
6
use Cmobi\RabbitmqBundle\Connection\CmobiAMQPConnection;
7
use Cmobi\RabbitmqBundle\Connection\ConnectionManager;
8
use Cmobi\RabbitmqBundle\Queue\CmobiAMQPMessage;
9
use Cmobi\RabbitmqBundle\Tests\BaseTestCase;
10
use Cmobi\RabbitmqBundle\Transport\Worker\Task;
11
12
class TaskTest extends BaseTestCase
13
{
14
    public function testGetQueueName()
15
    {
16
        $taskClient = new Task('test', $this->getConnectionManagerMock(), 'test');
17
18
        $this->assertEquals('test', $taskClient->getQueueName());
19
    }
20
21
    public function testGetFromName()
22
    {
23
        $taskClient = new Task('test', $this->getConnectionManagerMock(), 'caller_test');
24
25
        $this->assertEquals('caller_test', $taskClient->getFromName());
26
    }
27
28
    /**
29
     * @return ConnectionManager
30
     */
31
    protected function getConnectionManagerMock()
32
    {
33
        $connectionManagerMock = $this->getMockBuilder(ConnectionManager::class)
34
            ->disableOriginalConstructor()
35
            ->getMock();
36
        $connectionManagerMock->method('getConnection')
37
            ->willReturn($this->getConnectionMock());
38
39
        return $connectionManagerMock;
40
    }
41
42
    /**
43
     * @return CmobiAMQPConnection
44
     */
45 View Code Duplication
    protected function getConnectionMock()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
46
    {
47
        $connectionMock = $this->getMockBuilder(CmobiAMQPConnection::class)
48
            ->disableOriginalConstructor()
49
            ->getMock();
50
        $connectionMock->method('isConnected')
51
            ->willReturn(true);
52
        $connectionMock->method('reconnect')
53
            ->willReturn(true);
54
        $connectionMock->method('channel')
55
            ->willReturn($this->getChannelMock());
56
57
        return $connectionMock;
58
    }
59
60
    /**
61
     * @return CmobiAMQPChannel
62
     */
63 View Code Duplication
    protected function getChannelMock()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
64
    {
65
        $channelMock = $this->getMockBuilder(CmobiAMQPChannel::class)
66
            ->disableOriginalConstructor()
67
            ->getMock();
68
        $channelMock
69
            ->expects($this->any())
70
            ->method('basic_publish')
71
            ->willReturn(true);
72
        $channelMock
73
            ->method('basicConsume')
74
            ->willReturn(true);
75
76
        return $channelMock;
77
    }
78
79
    /**
80
     * @param string $msg
81
     * @param null   $correlationId
82
     *
83
     * @return CmobiAMQPMessage
84
     */
85 View Code Duplication
    protected function getCmobiAMQPMessage($msg = '', $correlationId = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
86
    {
87
        $msgMock = $this->getMockBuilder(CmobiAMQPMessage::class)
88
            ->disableOriginalConstructor()
89
            ->getMock();
90
        $msgMock->method('get')
91
            ->willReturn('correlation_id')
92
            ->willReturn($correlationId);
93
        $msgMock->method('getBody')
94
            ->willReturn($msg);
95
96
        return $msgMock;
97
    }
98
}
99