Skip to content

Commit

Permalink
IBX-7055: Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikadamczyk authored and alongosz committed Dec 6, 2023
1 parent f6bf237 commit 4e73c46
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/lib/Event/TrashServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,41 @@ public function testTrashStopPropagationInBeforeEvents()
]);
}

public function testTrashStopPropagationInBeforeEventsSetsNullResult(): void
{
$traceableEventDispatcher = $this->getEventDispatcher(
BeforeTrashEvent::class,
TrashEvent::class
);

$parameters = [
$this->createMock(Location::class),
];

$innerServiceMock = $this->createMock(TrashServiceInterface::class);
$innerServiceMock->expects(self::never())->method('trash');

$traceableEventDispatcher->addListener(BeforeTrashEvent::class, static function (BeforeTrashEvent $event) {
$event->setResult(null);
$event->stopPropagation();
}, 10);

$service = new TrashService($innerServiceMock, $traceableEventDispatcher);
$result = $service->trash(...$parameters);

$calledListeners = $this->getListenersStack($traceableEventDispatcher->getCalledListeners());
$notCalledListeners = $this->getListenersStack($traceableEventDispatcher->getNotCalledListeners());

self::assertNull($result);
self::assertSame($calledListeners, [
[BeforeTrashEvent::class, 10],
]);
self::assertSame($notCalledListeners, [
[BeforeTrashEvent::class, 0],
[TrashEvent::class, 0],
]);
}

public function testRecoverEvents()
{
$traceableEventDispatcher = $this->getEventDispatcher(
Expand Down

0 comments on commit 4e73c46

Please sign in to comment.