Completed
Push — master ( c5590c...0db478 )
by Daniel
13:19 queued 09:08
created

TaskTest::testGetFromName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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());
17
18
        $this->assertEquals('test', $taskClient->getQueueName());
19
    }
20
21
    public function testRefreshChannel()
22
    {
23
        $taskClient = new Task('test', $this->getConnectionManagerMock());
24
25
        $this->assertInstanceOf(CmobiAMQPChannel::class, $taskClient->refreshChannel());
26
    }
27
28
    public function testGetChannel()
29
    {
30
        $taskClient = new Task('test', $this->getConnectionManagerMock());
31
32
        $this->assertInstanceOf(CmobiAMQPChannel::class, $taskClient->refreshChannel());
33
    }
34
35
    public function testGetFromName()
36
    {
37
        $taskClient = new Task('test', $this->getConnectionManagerMock(), 'caller_test');
38
39
        $this->assertEquals('caller_test', $taskClient->getFromName());
40
    }
41
42
    /**
43
     * @return ConnectionManager
44
     */
45 View Code Duplication
    protected function getConnectionManagerMock()
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
        $connectionManagerMock = $this->getMockBuilder(ConnectionManager::class)
48
            ->disableOriginalConstructor()
49
            ->getMock();
50
        $connectionManagerMock->method('getConnection')
51
            ->willReturn($this->getConnectionMock());
52
53
        return $connectionManagerMock;
54
    }
55
56
    /**
57
     * @return CmobiAMQPConnection
58
     */
59 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...
60
    {
61
        $connectionMock = $this->getMockBuilder(CmobiAMQPConnection::class)
62
            ->disableOriginalConstructor()
63
            ->getMock();
64
        $connectionMock->method('isConnected')
65
            ->willReturn(true);
66
        $connectionMock->method('reconnect')
67
            ->willReturn(true);
68
        $connectionMock->method('channel')
69
            ->willReturn($this->getChannelMock());
70
71
        return $connectionMock;
72
    }
73
74
    /**
75
     * @return CmobiAMQPChannel
76
     */
77 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...
78
    {
79
        $channelMock = $this->getMockBuilder(CmobiAMQPChannel::class)
80
            ->disableOriginalConstructor()
81
            ->getMock();
82
        $channelMock
83
            ->expects($this->any())
84
            ->method('basic_publish')
85
            ->willReturn(true);
86
        $channelMock
87
            ->method('basicConsume')
88
            ->willReturn(true);
89
90
        return $channelMock;
91
    }
92
93
    /**
94
     * @param string $msg
95
     * @param null   $correlationId
96
     *
97
     * @return CmobiAMQPMessage
98
     */
99 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...
100
    {
101
        $msgMock = $this->getMockBuilder(CmobiAMQPMessage::class)
102
            ->disableOriginalConstructor()
103
            ->getMock();
104
        $msgMock->method('get')
105
            ->willReturn('correlation_id')
106
            ->willReturn($correlationId);
107
        $msgMock->method('getBody')
108
            ->willReturn($msg);
109
110
        return $msgMock;
111
    }
112
}
113