Completed
Push — master ( cb28f1...0f41ba )
by
unknown
13:57
created

testIterations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
rs 9.2
cc 2
eloc 14
nc 2
nop 0
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 Doctrine\Common\Persistence\ManagerRegistry;
15
use Sonata\NotificationBundle\Tests\Helpers\PHPUnit_Framework_TestCase;
16
17
/**
18
 * @author Kevin Nedelec <[email protected]>
19
 */
20
class MessageManagerMessageIteratorTest extends PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * @var ManagerRegistry
24
     */
25
    private $registry;
26
27
    protected function setUp()
28
    {
29
        $this->registry = $this->createMock('Doctrine\Common\Persistence\ManagerRegistry');
30
    }
31
32
    public function testBufferize()
33
    {
34
        $iterator = new MessageManagerMessageIterator($this->registry, 0);
35
36
        $iterator->_bufferize();
37
38
        $this->assertEquals(10, count($iterator->getBuffer()));
39
    }
40
41
    public function testIterations()
42
    {
43
        $size = 10;
44
45
        $iterator = new MessageManagerMessageIterator($this->registry, 0);
46
47
        $iterator->rewind();
48
        $this->assertTrue($iterator->valid());
49
        $this->assertNotNull($iterator->current());
50
51
        $iterator->next();
52
        $this->assertTrue($iterator->valid());
53
        $this->assertNotNull($iterator->current());
54
55
        --$size;
56
        while (--$size >= 1) {
57
            $iterator->next();
58
        }
59
60
        $this->assertTrue($iterator->valid());
61
        $this->assertNotNull($iterator->current());
62
    }
63
64
    public function testLongForeach()
65
    {
66
        $iterator = new MessageManagerMessageIterator($this->registry, 500000, 2);
67
68
        $count = 0;
69
70
        foreach ($iterator as $message) {
71
            ++$count;
72
            $this->assertNotNull($message);
73
            if ($count > 20) {
74
                return;
75
            }
76
        }
77
    }
78
}
79