RedisMessageProviderTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 81
Duplicated Lines 24.69 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 20
loc 81
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testInstance() 0 4 1
A testGet() 0 20 1
A testNack() 10 10 1
A testNackWithNoRequeue() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Dekalee\RedisSwarrot\Tests\Unit\MessageProvider;
4
5
use Dekalee\RedisSwarrot\MessageProvider\RedisMessageProvider;
6
7
/**
8
 * Class RedisMessageProviderTest
9
 */
10
class RedisMessageProviderTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var RedisMessageProvider
14
     */
15
    private $provider;
16
17
    private $redis;
18
    private $queueName;
19
20
    /**
21
     * Set up the test.
22
     */
23
    public function setUp()
24
    {
25
        $this->redis = $this->prophesize('\Redis');
26
        $this->queueName = 'foo';
27
28
        $this->provider = new RedisMessageProvider($this->redis->reveal(), $this->queueName);
29
    }
30
31
    /**
32
     * Test instance
33
     */
34
    public function testInstance()
35
    {
36
        $this->assertInstanceOf('Swarrot\Broker\MessageProvider\MessageProviderInterface', $this->provider);
37
    }
38
39
    /**
40
     * Test get method
41
     */
42
    public function testGet()
43
    {
44
        $data = json_encode(['bar' => 'baz']);
45
        $this->redis->lLen('foo')->willReturn(1);
46
        $this->redis->brPop('foo', 0)
47
            ->shouldBeCalled()
48
            ->willReturn(
49
            [
50
                'foo',
51
                $data,
52
            ]
53
        );
54
55
        $message = $this->provider->get();
56
57
        $this->assertInstanceOf('Swarrot\Broker\Message', $message);
58
        $this->assertSame($data, $message->getBody());
59
        $this->assertSame(['channel' => 'foo'], $message->getProperties());
60
        $this->assertNull($message->getId());
61
    }
62
63
    /**
64
     * Test nack with requeue
65
     */
66 View Code Duplication
    public function testNack()
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...
67
    {
68
        $data = json_encode(['bar' => 'baz']);
69
        $message = $this->prophesize('Swarrot\Broker\Message');
70
        $message->getBody()->willReturn($data);
71
72
        $this->redis->lPush($this->queueName, $data)->shouldBeCalled();
73
74
        $this->provider->nack($message->reveal(), true);
75
    }
76
77
    /**
78
     * Test nack with requeue
79
     */
80 View Code Duplication
    public function testNackWithNoRequeue()
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...
81
    {
82
        $data = json_encode(['bar' => 'baz']);
83
        $message = $this->prophesize('Swarrot\Broker\Message');
84
        $message->getBody()->willReturn($data);
85
86
        $this->redis->lPush($this->queueName, $data)->shouldNotBeCalled();
87
88
        $this->provider->nack($message->reveal(), false);
89
    }
90
}
91