TypeSafeQueueTest::testCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Phive Queue package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phive\Queue\Tests\Queue;
13
14
use Phive\Queue\TypeSafeQueue;
15
16
class TypeSafeQueueTest extends \PHPUnit_Framework_TestCase
17
{
18
    use Util;
19
20
    protected $innerQueue;
21
    protected $queue;
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected function setUp()
27
    {
28
        $this->innerQueue = $this->getQueueMock();
29
        $this->queue = new TypeSafeQueue($this->innerQueue);
30
    }
31
32
    /**
33
     * @dataProvider provideItemsOfSupportedTypes
34
     */
35
    public function testPush($item)
36
    {
37
        $serializedItem = null;
38
39
        $this->innerQueue->expects($this->once())->method('push')
40
            ->with($this->callback(function ($subject) use (&$serializedItem) {
41
                $serializedItem = $subject;
42
43
                return is_string($subject) && ctype_print($subject);
44
            }));
45
46
        $this->queue->push($item);
47
48
        return ['original' => $item, 'serialized' => $serializedItem];
49
    }
50
51
    /**
52
     * @depends testPush
53
     */
54
    public function testPop($data)
55
    {
56
        $this->innerQueue->expects($this->once())->method('pop')
57
            ->will($this->returnValue($data['serialized']));
58
59
        $this->assertEquals($data['original'], $this->queue->pop());
60
    }
61
62
    public function testCount()
63
    {
64
        $this->innerQueue->expects($this->once())->method('count')
65
            ->will($this->returnValue(42));
66
67
        $this->assertSame(42, $this->queue->count());
68
    }
69
70
    public function testClear()
71
    {
72
        $this->innerQueue->expects($this->once())->method('clear');
73
        $this->queue->clear();
74
    }
75
}
76