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\Entity; |
13
|
|
|
|
14
|
|
|
use Sonata\NotificationBundle\Event\DoctrineOptimizeListener; |
15
|
|
|
use Sonata\NotificationBundle\Event\IterateEvent; |
16
|
|
|
|
17
|
|
|
class DoctrineOptimizeListenerTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @expectedException \RuntimeException |
21
|
|
|
*/ |
22
|
|
|
public function testWithClosedManager() |
23
|
|
|
{ |
24
|
|
|
$manager = $this->getMockBuilder('Doctrine\ORM\EntityManager') |
25
|
|
|
->disableOriginalConstructor() |
26
|
|
|
->getMock(); |
27
|
|
|
$manager->expects($this->once())->method('isOpen')->will($this->returnValue(false)); |
28
|
|
|
|
29
|
|
|
$registry = $this->getMock('Symfony\Bridge\Doctrine\RegistryInterface'); |
30
|
|
|
$registry->expects($this->once())->method('getManagers')->will($this->returnValue(array( |
31
|
|
|
'default' => $manager, |
32
|
|
|
))); |
33
|
|
|
|
34
|
|
|
$optimizer = new DoctrineOptimizeListener($registry); |
35
|
|
|
$optimizer->iterate(new IterateEvent( |
36
|
|
|
$this->getMock('Sonata\NotificationBundle\Iterator\MessageIteratorInterface'), |
37
|
|
|
$this->getMock('Sonata\NotificationBundle\Backend\BackendInterface') |
38
|
|
|
)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testOptimize() |
42
|
|
|
{ |
43
|
|
|
$unitofwork = $this->getMockBuilder('Doctrine\ORM\UnitOfWork') |
44
|
|
|
->disableOriginalConstructor() |
45
|
|
|
->getMock(); |
46
|
|
|
$unitofwork->expects($this->once())->method('clear'); |
47
|
|
|
|
48
|
|
|
$manager = $this->getMockBuilder('Doctrine\ORM\EntityManager') |
49
|
|
|
->disableOriginalConstructor() |
50
|
|
|
->getMock(); |
51
|
|
|
$manager->expects($this->once())->method('isOpen')->will($this->returnValue(true)); |
52
|
|
|
$manager->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($unitofwork)); |
53
|
|
|
|
54
|
|
|
$registry = $this->getMock('Symfony\Bridge\Doctrine\RegistryInterface'); |
55
|
|
|
$registry->expects($this->once())->method('getManagers')->will($this->returnValue(array( |
56
|
|
|
'default' => $manager, |
57
|
|
|
))); |
58
|
|
|
|
59
|
|
|
$optimizer = new DoctrineOptimizeListener($registry); |
60
|
|
|
$optimizer->iterate(new IterateEvent( |
61
|
|
|
$this->getMock('Sonata\NotificationBundle\Iterator\MessageIteratorInterface'), |
62
|
|
|
$this->getMock('Sonata\NotificationBundle\Backend\BackendInterface') |
63
|
|
|
)); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|