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

MessageManagerMessageIteratorTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
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 59
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testBufferize() 0 8 1
A testIterations() 0 22 2
A testLongForeach() 0 14 3
A setUp() 0 4 1
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