From 460da65f30972475a0188ecc388c85b37563b824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Sat, 16 Dec 2023 10:10:59 +0100 Subject: [PATCH] Fix event dispatcher provider --- .../Provider/EventDispatcherProvider.php | 6 ++++-- .../Provider/EventDispatcherProviderSpec.php | 20 +++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Component/src/State/Provider/EventDispatcherProvider.php b/src/Component/src/State/Provider/EventDispatcherProvider.php index cfde9b7c0..fdda90b50 100644 --- a/src/Component/src/State/Provider/EventDispatcherProvider.php +++ b/src/Component/src/State/Provider/EventDispatcherProvider.php @@ -26,13 +26,15 @@ final class EventDispatcherProvider implements ProviderInterface { public function __construct( - private ProviderInterface $decorated, + private ProviderInterface $provider, private OperationEventDispatcherInterface $operationEventDispatcher, ) { } public function provide(Operation $operation, Context $context): object|array|null { + $data = $this->provider->provide($operation, $context); + if ( $operation instanceof CollectionOperationInterface || $operation instanceof ShowOperationInterface @@ -40,6 +42,6 @@ public function provide(Operation $operation, Context $context): object|array|nu $this->operationEventDispatcher->dispatch(null, $operation, $context); } - return $this->decorated->provide($operation, $context); + return $data; } } diff --git a/src/Component/tests/spec/State/Provider/EventDispatcherProviderSpec.php b/src/Component/tests/spec/State/Provider/EventDispatcherProviderSpec.php index 9e4476e64..58389247d 100644 --- a/src/Component/tests/spec/State/Provider/EventDispatcherProviderSpec.php +++ b/src/Component/tests/spec/State/Provider/EventDispatcherProviderSpec.php @@ -26,10 +26,10 @@ final class EventDispatcherProviderSpec extends ObjectBehavior { function let( - ProviderInterface $decorated, + ProviderInterface $provider, OperationEventDispatcherInterface $operationEventDispatcher, ): void { - $this->beConstructedWith($decorated, $operationEventDispatcher); + $this->beConstructedWith($provider, $operationEventDispatcher); } function it_is_initializable(): void @@ -38,7 +38,7 @@ function it_is_initializable(): void } function it_dispatches_events_for_index_operation( - ProviderInterface $decorated, + ProviderInterface $provider, OperationEventDispatcherInterface $operationEventDispatcher, ): void { $operation = new Index(provider: '\App\Provider'); @@ -46,10 +46,10 @@ function it_dispatches_events_for_index_operation( $operationEvent = new OperationEvent(); - $decorated->provide($operation, $context)->shouldBeCalled(); + $provider->provide($operation, $context)->shouldBeCalled(); $operationEventDispatcher->dispatch(null, $operation, $context)->willReturn($operationEvent)->shouldBeCalled(); - $decorated->provide($operation, $context)->shouldBeCalled(); + $provider->provide($operation, $context)->shouldBeCalled(); $operationEventDispatcher->dispatch(null, $operation, $context)->shouldBeCalled(); @@ -57,7 +57,7 @@ function it_dispatches_events_for_index_operation( } function it_dispatches_events_for_show_operation( - ProviderInterface $decorated, + ProviderInterface $provider, OperationEventDispatcherInterface $operationEventDispatcher, ): void { $operation = new Show(provider: '\App\Provider'); @@ -65,10 +65,10 @@ function it_dispatches_events_for_show_operation( $operationEvent = new OperationEvent(); - $decorated->provide($operation, $context)->shouldBeCalled(); + $provider->provide($operation, $context)->shouldBeCalled(); $operationEventDispatcher->dispatch(null, $operation, $context)->willReturn($operationEvent)->shouldBeCalled(); - $decorated->provide($operation, $context)->shouldBeCalled(); + $provider->provide($operation, $context)->shouldBeCalled(); $operationEventDispatcher->dispatch(null, $operation, $context)->shouldBeCalled(); @@ -76,13 +76,13 @@ function it_dispatches_events_for_show_operation( } function it_does_not_dispatch_events_for_create_operation( - ProviderInterface $decorated, + ProviderInterface $provider, OperationEventDispatcherInterface $operationEventDispatcher, ): void { $operation = new Create(provider: '\App\Provider'); $context = new Context(); - $decorated->provide($operation, $context)->shouldBeCalled(); + $provider->provide($operation, $context)->shouldBeCalled(); $operationEventDispatcher->dispatch(null, $operation, $context)->shouldNotBeCalled();