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
|
|
|
|