RedisMessageProviderTest::testInstance()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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