|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\Knp\RadBundle\DomainEvent\Dispatcher; |
|
4
|
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
|
6
|
|
|
use Prophecy\Argument; |
|
7
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
8
|
|
|
use Doctrine\ORM\Event\PostFlushEventArgs; |
|
9
|
|
|
use Doctrine\ORM\EntityManager; |
|
10
|
|
|
use Doctrine\ORM\UnitOfWork; |
|
11
|
|
|
use Knp\RadBundle\DomainEvent\Provider; |
|
12
|
|
|
use Knp\RadBundle\DomainEvent\Event; |
|
13
|
|
|
use Doctrine\ORM\Event\LifecycleEventArgs; |
|
14
|
|
|
|
|
15
|
|
|
class DoctrineSpec extends ObjectBehavior |
|
16
|
|
|
{ |
|
17
|
|
|
function let(EventDispatcherInterface $dispatcher) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->beConstructedWith($dispatcher); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
function it_dispatches_domain_events_after_doctrine_unit_of_work_has_been_flushed( |
|
|
|
|
|
|
23
|
|
|
PostFlushEventArgs $postFlushEvent, |
|
24
|
|
|
LifecycleEventArgs $postPersistEvent, |
|
25
|
|
|
LifecycleEventArgs $postRemoveEvent, |
|
26
|
|
|
Provider $provider, |
|
27
|
|
|
Event $entityCreated, |
|
28
|
|
|
Event $propertyUpdated, |
|
29
|
|
|
NonProvider $nonProvider, |
|
30
|
|
|
$dispatcher |
|
31
|
|
|
) { |
|
32
|
|
|
$postPersistEvent->getEntity()->willReturn($provider); |
|
33
|
|
|
$postRemoveEvent->getEntity()->willReturn($nonProvider); |
|
34
|
|
|
|
|
35
|
|
|
$provider->popEvents()->willReturn([$entityCreated, $propertyUpdated]); |
|
36
|
|
|
$entityCreated->getName()->willReturn('EntityCreated'); |
|
37
|
|
|
$propertyUpdated->getName()->willReturn('PropertyUpdated'); |
|
38
|
|
|
|
|
39
|
|
|
$entityCreated->setSubject($provider)->shouldBeCalled(); |
|
40
|
|
|
$propertyUpdated->setSubject($provider)->shouldBeCalled(); |
|
41
|
|
|
$dispatcher->dispatch('EntityCreated', $entityCreated)->shouldBeCalled(); |
|
42
|
|
|
$dispatcher->dispatch('PropertyUpdated', $propertyUpdated)->shouldBeCalled(); |
|
43
|
|
|
|
|
44
|
|
|
$this->postPersist($postPersistEvent); |
|
45
|
|
|
$this->postRemove($postRemoveEvent); |
|
46
|
|
|
$this->postFlush($postFlushEvent); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
class NonProvider |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
|
|
} |
|
53
|
|
|
|