Completed
Push — 3.x ( e46a84...5eb231 )
by
unknown
03:10
created

IteratorProxyMessageIteratorTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 65
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testIteratorProxiesIteratorMethods() 0 16 2
B expectIterator() 0 42 3
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[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 Sonata\NotificationBundle\Tests\Iterator;
13
14
use Sonata\NotificationBundle\Iterator\IteratorProxyMessageIterator;
15
16
/**
17
 * @covers Sonata\NotificationBundle\Iterator\IteratorProxyMessageIterator
18
 */
19
class IteratorProxyMessageIteratorTest extends \PHPUnit_Framework_TestCase
20
{
21
    public function testIteratorProxiesIteratorMethods()
22
    {
23
        $content = array(
24
            'foo',
25
            'bar',
26
        );
27
28
        $actualIterator = $this->getMock('Iterator');
29
        $this->expectIterator($actualIterator, $content, true);
30
31
        $proxy = new IteratorProxyMessageIterator($actualIterator);
32
        foreach ($proxy as $eachKey => $eachEntry) {
33
            $this->assertNotNull($eachKey);
34
            $this->assertNotEmpty($eachEntry);
35
        }
36
    }
37
38
    /**
39
     * @link https://gist.github.com/2852498
40
     */
41
    public function expectIterator($mock, array $content, $withKey = false, $counter = 0)
42
    {
43
        $mock
44
            ->expects($this->at($counter))
45
            ->method('rewind')
46
        ;
47
48
        foreach ($content as $key => $value) {
49
            $mock
50
                ->expects($this->at(++$counter))
51
                ->method('valid')
52
                ->will($this->returnValue(true))
53
            ;
54
55
            $mock
56
                ->expects($this->at(++$counter))
57
                ->method('current')
58
                ->will($this->returnValue($value))
59
            ;
60
61
            if ($withKey) {
62
                $mock
63
                    ->expects($this->at(++$counter))
64
                    ->method('key')
65
                    ->will($this->returnValue($key))
66
                ;
67
            }
68
69
            $mock
70
                ->expects($this->at(++$counter))
71
                ->method('next')
72
            ;
73
        }
74
75
        $mock
76
            ->expects($this->at(++$counter))
77
            ->method('valid')
78
            ->will($this->returnValue(false))
79
        ;
80
81
        return ++$counter;
82
    }
83
}
84