Completed
Pull Request — master (#1)
by Adam
05:22 queued 03:01
created

RedisDriverTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 58
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testPush() 0 13 1
A testPop() 0 12 1
A testPopEmpty() 0 12 1
1
<?php
2
3
namespace Equip\Queue\Driver;
4
5
use Equip\Queue\TestCase;
6
use Redis;
7
8
class RedisDriverTest extends TestCase
9
{
10
    /**
11
     * @var Redis
12
     */
13
    private $redis;
14
15
    /**
16
     * @var RedisDriver
17
     */
18
    private $driver;
19
20
    protected function setUp()
21
    {
22
        $this->redis = $this->createMock(Redis::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Redis::class) of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<Redis> of property $redis.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
23
        $this->driver = new RedisDriver($this->redis);
24
    }
25
26
    public function testPush()
27
    {
28
        $queue = 'test-queue';
29
        $message = json_encode(['test' => 'example']);
30
31
        $this->redis
32
            ->expects($this->once())
33
            ->method('rPush')
34
            ->with($queue, $message)
35
            ->willReturn(true);
36
37
        $this->assertTrue($this->driver->push($queue, $message));
38
    }
39
40
    public function testPop()
41
    {
42
        $queue = 'test-queue';
43
44
        $this->redis
45
            ->expects($this->once())
46
            ->method('blPop')
47
            ->with([$queue], 5)
48
            ->willReturn(['test', 'example']);
49
50
        $this->assertSame('example', $this->driver->pop($queue));
51
    }
52
53
    public function testPopEmpty()
54
    {
55
        $queue = 'test-queue';
56
57
        $this->redis
58
            ->expects($this->once())
59
            ->method('blPop')
60
            ->with([$queue], 5)
61
            ->willReturn(null);
62
63
        $this->assertNull($this->driver->pop($queue));
64
    }
65
}
66