diff --git a/src/DispatcherWrapper.php b/src/DispatcherWrapper.php new file mode 100644 index 0000000..5a9b014 --- /dev/null +++ b/src/DispatcherWrapper.php @@ -0,0 +1,29 @@ +dispatch($eventObject, $eventType); + } else { + //Symfony 2,3 or 4 + $dispatcher->dispatch($eventType, $eventObject); + } + + } +} diff --git a/src/Listener.php b/src/Listener.php index 6a127cb..0af5c05 100644 --- a/src/Listener.php +++ b/src/Listener.php @@ -1,17 +1,18 @@ dispatcher->dispatch('suite.start', new SuiteEvent($suite)); + $this->dispatch($this->dispatcher, 'suite.start', new SuiteEvent($suite)); } public function endTestSuite(\PHPUnit\Framework\TestSuite $suite) : void { - $this->dispatcher->dispatch('suite.end', new SuiteEvent($suite)); + $this->dispatch($this->dispatcher, 'suite.end', new SuiteEvent($suite)); } public function startTest(\PHPUnit\Framework\Test $test) : void { - $this->dispatcher->dispatch(Events::TEST_START, new TestEvent($test)); + $this->dispatch($this->dispatcher, Events::TEST_START, new TestEvent($test)); if (!$test instanceof TestInterface) { return; } @@ -119,7 +120,7 @@ public function endTest(\PHPUnit\Framework\Test $test, float $time) : void $this->fire(Events::TEST_AFTER, new TestEvent($test, $time)); } - $this->dispatcher->dispatch(Events::TEST_END, new TestEvent($test, $time)); + $this->dispatch($this->dispatcher, Events::TEST_END, new TestEvent($test, $time)); } protected function fire($event, TestEvent $eventType) @@ -127,9 +128,9 @@ protected function fire($event, TestEvent $eventType) $test = $eventType->getTest(); if ($test instanceof TestInterface) { foreach ($test->getMetadata()->getGroups() as $group) { - $this->dispatcher->dispatch($event . '.' . $group, $eventType); + $this->dispatch($this->dispatcher, $event . '.' . $group, $eventType); } } - $this->dispatcher->dispatch($event, $eventType); + $this->dispatch($this->dispatcher, $event, $eventType); } } diff --git a/src/ResultPrinter/UI.php b/src/ResultPrinter/UI.php index c7c6e92..f628c07 100644 --- a/src/ResultPrinter/UI.php +++ b/src/ResultPrinter/UI.php @@ -3,12 +3,15 @@ use Codeception\Event\FailEvent; use Codeception\Events; +use Codeception\PHPUnit\DispatcherWrapper; use Codeception\Test\Unit; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\EventDispatcher\EventDispatcher; class UI extends \PHPUnit\TextUI\ResultPrinter { + use DispatcherWrapper; + /** * @var EventDispatcher */ @@ -23,7 +26,8 @@ public function __construct(EventDispatcher $dispatcher, $options, $out = null) protected function printDefect(\PHPUnit\Framework\TestFailure $defect, int $count): void { $this->write("\n---------\n"); - $this->dispatcher->dispatch( + $this->dispatch( + $this->dispatcher, Events::TEST_FAIL_PRINT, new FailEvent($defect->failedTest(), null, $defect->thrownException(), $count) );