Completed
Pull Request — 3.x (#241)
by
unknown
03:17 queued 01:05
created

MessageManagerMessageIteratorTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 56
rs 10
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
use Doctrine\Common\Persistence\ManagerRegistry;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Cannot use Doctrine\Common\Persistence\ManagerRegistry as ManagerRegistry because the name is already in use
Loading history...
17
18
/**
19
 * @author Kevin Nedelec <[email protected]>
20
 */
21
class MessageManagerMessageIteratorTest extends PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var ManagerRegistry
25
     */
26
    private $registry;
27
28
    protected function setUp()
29
    {
30
        $this->registry = $this->createMock('Doctrine\Common\Persistence\ManagerRegistry');
31
    }
32
33
    public function testBufferize()
34
    {
35
        $iterator = new MessageManagerMessageIterator($this->registry, 0);
36
37
        $iterator->_bufferize();
38
39
        $this->assertEquals(10, count($iterator->getBuffer()));
40
    }
41
42
    public function testIterations()
43
    {
44
        $size = 10;
45
46
        $iterator = new MessageManagerMessageIterator($this->registry, 0);
47
48
        $iterator->rewind();
49
        $this->assertTrue($iterator->valid());
50
        $this->assertNotNull($iterator->current());
51
52
        $iterator->next();
53
        $this->assertTrue($iterator->valid());
54
        $this->assertNotNull($iterator->current());
55
56
        --$size;
57
        while (--$size >= 1) {
58
            $iterator->next();
59
        }
60
61
        $this->assertTrue($iterator->valid());
62
        $this->assertNotNull($iterator->current());
63
    }
64
65
    public function testLongForeach()
66
    {
67
        $iterator = new MessageManagerMessageIterator($this->registry, 500000, 2);
68
69
        $count = 0;
70
71
        foreach ($iterator as $message) {
72
            ++$count;
73
            $this->assertNotNull($message);
74
            if ($count > 20) {
75
                return;
76
            }
77
        }
78
    }
79
}
80