dsantang /
domain-events-doctrine
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | declare(strict_types=1); |
||||||
| 4 | |||||||
| 5 | namespace Dsantang\DomainEventsDoctrine\Tests\Integration; |
||||||
| 6 | |||||||
| 7 | use Doctrine\ORM\EntityManagerInterface; |
||||||
| 8 | use Doctrine\ORM\Event\OnFlushEventArgs; |
||||||
| 9 | use Doctrine\ORM\UnitOfWork; |
||||||
| 10 | use Dsantang\DomainEvents\Counter; |
||||||
| 11 | use Dsantang\DomainEvents\DomainEvent; |
||||||
| 12 | use Dsantang\DomainEvents\EventAware; |
||||||
| 13 | use Dsantang\DomainEvents\Registry\OrderedEventRegistry; |
||||||
| 14 | use Dsantang\DomainEventsDoctrine\Dispatcher\SimpleEventsDispatcher; |
||||||
| 15 | use Dsantang\DomainEventsDoctrine\Dispatcher\SymfonyEvent; |
||||||
| 16 | use Dsantang\DomainEventsDoctrine\EventsRecorder\OrderedDoctrineEventsRecorder; |
||||||
| 17 | use Dsantang\DomainEventsDoctrine\EventsTracker; |
||||||
| 18 | use PHPUnit\Framework\MockObject\MockObject; |
||||||
| 19 | use PHPUnit\Framework\TestCase; |
||||||
| 20 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
||||||
| 21 | |||||||
| 22 | final class OrderedEventsIntegrationTest extends TestCase |
||||||
| 23 | { |
||||||
| 24 | /** @var EventsTracker */ |
||||||
| 25 | private $tracker; |
||||||
| 26 | |||||||
| 27 | /** @var OrderedDoctrineEventsRecorder */ |
||||||
| 28 | private $recorder; |
||||||
| 29 | |||||||
| 30 | /** @var MockObject|EventDispatcherInterface */ |
||||||
| 31 | private $eventDispatcher; |
||||||
| 32 | |||||||
| 33 | /** @var SimpleEventsDispatcher */ |
||||||
| 34 | private $doctrineDispatcher; |
||||||
| 35 | |||||||
| 36 | /** |
||||||
| 37 | * @before |
||||||
| 38 | */ |
||||||
| 39 | public function setUpDependencies() : void |
||||||
| 40 | { |
||||||
| 41 | $this->tracker = new EventsTracker(); |
||||||
| 42 | $this->recorder = new OrderedDoctrineEventsRecorder($this->tracker); |
||||||
| 43 | $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); |
||||||
| 44 | $this->doctrineDispatcher = new SimpleEventsDispatcher( |
||||||
| 45 | $this->tracker, |
||||||
| 46 | $this->eventDispatcher |
||||||
| 47 | ); |
||||||
| 48 | } |
||||||
| 49 | |||||||
| 50 | /** |
||||||
| 51 | * @test |
||||||
| 52 | */ |
||||||
| 53 | public function eventOfOrdersIsPreserved() : void |
||||||
| 54 | { |
||||||
| 55 | $event1 = new class implements DomainEvent { |
||||||
| 56 | public function getName() : string |
||||||
| 57 | { |
||||||
| 58 | return 'first'; |
||||||
| 59 | } |
||||||
| 60 | }; |
||||||
| 61 | $event2 = new class implements DomainEvent { |
||||||
| 62 | public function getName() : string |
||||||
| 63 | { |
||||||
| 64 | return 'second'; |
||||||
| 65 | } |
||||||
| 66 | }; |
||||||
| 67 | $event3 = new class implements DomainEvent { |
||||||
| 68 | public function getName() : string |
||||||
| 69 | { |
||||||
| 70 | return 'third'; |
||||||
| 71 | } |
||||||
| 72 | }; |
||||||
| 73 | |||||||
| 74 | $entity1 = new class implements EventAware{ |
||||||
| 75 | use OrderedEventRegistry; |
||||||
| 76 | |||||||
| 77 | public function trigger(DomainEvent $event) : void |
||||||
| 78 | { |
||||||
| 79 | $this->triggeredA($event); |
||||||
| 80 | } |
||||||
| 81 | }; |
||||||
| 82 | |||||||
| 83 | $entity2 = new class implements EventAware { |
||||||
| 84 | use OrderedEventRegistry; |
||||||
| 85 | |||||||
| 86 | public function trigger(DomainEvent $event) : void |
||||||
| 87 | { |
||||||
| 88 | $this->triggeredA($event); |
||||||
| 89 | } |
||||||
| 90 | }; |
||||||
| 91 | |||||||
| 92 | $entity1->trigger($event1); |
||||||
| 93 | $entity2->trigger($event2); |
||||||
| 94 | $entity1->trigger($event3); |
||||||
| 95 | |||||||
| 96 | $uow = $this->createMock(UnitOfWork::class); |
||||||
| 97 | |||||||
| 98 | $uow->expects(self::once()) |
||||||
| 99 | ->method('getScheduledEntityInsertions') |
||||||
| 100 | ->willReturn([$entity1]); |
||||||
| 101 | |||||||
| 102 | $uow->expects(self::once()) |
||||||
| 103 | ->method('getScheduledEntityUpdates') |
||||||
| 104 | ->willReturn([$entity2]); |
||||||
| 105 | |||||||
| 106 | $uow->expects(self::once()) |
||||||
| 107 | ->method('getScheduledEntityDeletions') |
||||||
| 108 | ->willReturn([]); |
||||||
| 109 | |||||||
| 110 | $em = $this->createMock(EntityManagerInterface::class); |
||||||
| 111 | |||||||
| 112 | $em->expects(self::once())->method('getUnitOfWork')->willReturn($uow); |
||||||
| 113 | |||||||
| 114 | $eventArgs = $this->createMock(OnFlushEventArgs::class); |
||||||
| 115 | $eventArgs->method('getEntityManager')->willReturn($em); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 116 | |||||||
| 117 | $this->eventDispatcher->expects(self::exactly(3)) |
||||||
|
0 ignored issues
–
show
The method
expects() does not exist on Symfony\Component\EventD...ventDispatcherInterface. It seems like you code against a sub-type of Symfony\Component\EventD...ventDispatcherInterface such as Symfony\Component\EventD...raceableEventDispatcher.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 118 | ->method('dispatch') |
||||||
| 119 | ->withConsecutive( |
||||||
| 120 | ['first', new SymfonyEvent($event1)], |
||||||
| 121 | ['second', new SymfonyEvent($event2)], |
||||||
| 122 | ['third', new SymfonyEvent($event3)] |
||||||
| 123 | ); |
||||||
| 124 | |||||||
| 125 | self::assertEquals(3, Counter::getNext()); |
||||||
| 126 | |||||||
| 127 | $this->recorder->onFlush($eventArgs); |
||||||
| 128 | |||||||
| 129 | self::assertEquals(0, Counter::getNext()); |
||||||
| 130 | |||||||
| 131 | $this->doctrineDispatcher->postFlush(); |
||||||
| 132 | } |
||||||
| 133 | } |
||||||
| 134 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.