Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-7055: Allowed to return null when content is not deleted #297

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6220,11 +6220,6 @@ parameters:
count: 1
path: src/contracts/Repository/Events/Trash/BeforeRecoverEvent.php

-
message: "#^Method Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Events\\\\Trash\\\\BeforeTrashEvent\\:\\:getResult\\(\\) should return Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\TrashItem but returns Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\TrashItem\\|null\\.$#"
count: 1
path: src/contracts/Repository/Events/Trash/BeforeTrashEvent.php

-
message: "#^Property Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Events\\\\Trash\\\\RecoverEvent\\:\\:\\$newParentLocation \\(Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Location\\) does not accept Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Location\\|null\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/Repository/Events/Trash/BeforeTrashEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getLocation(): Location
return $this->location;
}

public function getResult(): TrashItem
public function getResult(): ?TrashItem
{
if (!$this->isResultSet()) {
throw new UnexpectedValueException(sprintf('Return value is not set or not of type %s (or null). Check isResultSet() or set it using setResult() before you call the getter.', TrashItem::class));
Expand Down
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
Loading