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