Completed
Push — 3.x-dev-kit ( cc4dbe )
by
unknown
03:15
created

MessageManagerMessageIteratorTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRegistryMock() 0 6 1
A testBufferize() 0 8 1
A testIterations() 0 22 2
A testLongForeach() 0 14 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
/**
15
 * @author Kevin Nedelec <[email protected]>
16
 *
17
 * Class MessageManagerMessageIteratorTest
18
 */
19
class MessageManagerMessageIteratorTest extends \PHPUnit_Framework_TestCase
20
{
21
    public function testBufferize()
22
    {
23
        $iterator = new MessageManagerMessageIterator($this->getRegistryMock(), 0);
24
25
        $iterator->_bufferize();
26
27
        $this->assertEquals(10, count($iterator->getBuffer()));
28
    }
29
30
    public function testIterations()
31
    {
32
        $size = 10;
33
34
        $iterator = new MessageManagerMessageIterator($this->getRegistryMock(), 0);
35
36
        $iterator->rewind();
37
        $this->assertTrue($iterator->valid());
38
        $this->assertNotNull($iterator->current());
39
40
        $iterator->next();
41
        $this->assertTrue($iterator->valid());
42
        $this->assertNotNull($iterator->current());
43
44
        --$size;
45
        while (--$size >= 1) {
46
            $iterator->next();
47
        }
48
49
        $this->assertTrue($iterator->valid());
50
        $this->assertNotNull($iterator->current());
51
    }
52
53
    public function testLongForeach()
54
    {
55
        $iterator = new MessageManagerMessageIterator($this->getRegistryMock(), 500000, 2);
56
57
        $count = 0;
58
59
        foreach ($iterator as $message) {
60
            ++$count;
61
            $this->assertNotNull($message);
62
            if ($count > 20) {
63
                return;
64
            }
65
        }
66
    }
67
68
    protected function getRegistryMock()
69
    {
70
        $registry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
71
72
        return $registry;
73
    }
74
}
75