From a568da021bbe66b8a4b092c0337757b8ba826b4a Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Tue, 17 Mar 2020 21:57:07 +0100 Subject: [PATCH] Fix FC layer for the event dispatcher under Symfony < 4.3 --- phpstan.neon | 4 +++ .../ParallelContainerDefinition.php | 5 +-- .../ForwardCompatEventDispatcher.php | 31 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/Lifecycle/ForwardCompatEventDispatcher.php diff --git a/phpstan.neon b/phpstan.neon index 24e1e668..4ecaab07 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -21,6 +21,10 @@ parameters: message: "#^Method Tests\\\\Unit\\\\Configuration\\\\CoverageConfigurationTest\\:\\:getService\\(\\) has no return typehint specified\\.$#" count: 1 path: tests/Unit/Configuration/CoverageConfigurationTest.php + - + message: "#^Method Tests\\\\Unit\\\\Configuration\\\\OutputFileTest\\:\\:testIsEmpty\\(\\) has parameter \\$emptyFile with no typehint specified\\.$#" + count: 1 + path: tests/Unit/Configuration/OutputFileTest.php excludes_analyse: - tests/Stub/ - src/Lifecycle/ForwardCompatEventDispatcher.php diff --git a/src/Configuration/DependencyInjection/ParallelContainerDefinition.php b/src/Configuration/DependencyInjection/ParallelContainerDefinition.php index 2f3aca86..5522fff8 100644 --- a/src/Configuration/DependencyInjection/ParallelContainerDefinition.php +++ b/src/Configuration/DependencyInjection/ParallelContainerDefinition.php @@ -11,6 +11,7 @@ use Paraunit\File\Cleaner; use Paraunit\File\TempDirectory; use Paraunit\Filter\Filter; +use Paraunit\Lifecycle\ForwardCompatEventDispatcher; use Paraunit\Printer\ConsoleFormatter; use Paraunit\Printer\FailuresPrinter; use Paraunit\Printer\FilesRecapPrinter; @@ -83,9 +84,9 @@ private function configureConfiguration(ContainerBuilder $container): void private function configureEventDispatcher(ContainerBuilder $container): void { $eventDispatcher = new Definition(EventDispatcher::class); - if (class_exists(LegacyEventDispatcherProxy::class)) { + if (! class_exists(LegacyEventDispatcherProxy::class)) { $container->setDefinition(LegacyEventDispatcherProxy::class, new Definition(LegacyEventDispatcherProxy::class)); - $eventDispatcher->setDecoratedService(LegacyEventDispatcherProxy::class); + $eventDispatcher->setDecoratedService(ForwardCompatEventDispatcher::class); } $container->setDefinition(SymfonyEventDispatcherInterface::class, $eventDispatcher); diff --git a/src/Lifecycle/ForwardCompatEventDispatcher.php b/src/Lifecycle/ForwardCompatEventDispatcher.php new file mode 100644 index 00000000..4fa63ea3 --- /dev/null +++ b/src/Lifecycle/ForwardCompatEventDispatcher.php @@ -0,0 +1,31 @@ +eventDispatcher = $eventDispatcher; + } + + public static function decorate(SymfonyEventDispatcherInterface $dispatcher): self + { + return new self($dispatcher); + } + + public function dispatch(object $event): object + { + $this->eventDispatcher->dispatch(\get_class($event), $event); + + return $event; + } +}