From bd3ee80b96e54d0695c9fd78d1f1d00b55541888 Mon Sep 17 00:00:00 2001 From: Marc Morera Date: Mon, 25 Nov 2019 13:31:42 +0100 Subject: [PATCH] Fixed kernel when --debug and no stopwatch - Using the regular event dispatcher --- .circleci/config.yml | 15 +++++-- .formatter.yml | 2 +- .php_cs | 1 + AsyncEventDispatcher.php | 2 +- AsyncEventDispatcherInterface.php | 25 ++++++++--- AsyncEventDispatcherMethods.php | 26 ++++++++--- AsyncHttpKernel.php | 9 ++-- AsyncKernel.php | 4 +- .../AsyncEventDispatcherNeededException.php | 2 +- Exception/AsyncHttpKernelNeededException.php | 2 +- Tests/AsyncKernelFunctionalTest.php | 26 +++++++---- Tests/{ => Base}/AsyncDebugFunctionalTest.php | 8 ++-- Tests/{ => Base}/AsyncFunctionalTest.php | 6 ++- Tests/{ => Base}/AutowiringDebugTest.php | 27 ++++++++--- Tests/{ => Base}/AutowiringTest.php | 23 +++++++--- .../GetResponsePromiseFunctionalTest.php | 6 ++- ...sponsesPromiseFunctionalMidPromiseTest.php | 6 ++- ...esponsesPromiseFunctionalNoPromiseTest.php | 6 ++- .../GetResponsesPromiseFunctionalTest.php | 6 ++- Tests/Base/KernelServicesTest.php | 35 +++++++++++++++ Tests/{ => Base}/SyncFunctionalTest.php | 5 ++- Tests/{ => Base}/TwigTest.php | 6 ++- Tests/Controller.php | 2 +- Tests/KernelServicesTest.php | 22 --------- Tests/Listener.php | 2 +- .../NoStopwatch/AsyncDebugFunctionalTest.php | 34 ++++++++++++++ Tests/NoStopwatch/AutowiringDebugTest.php | 45 +++++++++++++++++++ Tests/Services/AService.php | 25 ++++++++--- TraceableAsyncEventDispatcher.php | 2 +- composer.json | 19 ++++---- phpunit.xml | 39 +++------------- 31 files changed, 296 insertions(+), 142 deletions(-) rename Tests/{ => Base}/AsyncDebugFunctionalTest.php (93%) rename Tests/{ => Base}/AsyncFunctionalTest.php (93%) rename Tests/{ => Base}/AutowiringDebugTest.php (55%) rename Tests/{ => Base}/AutowiringTest.php (57%) rename Tests/{ => Base}/GetResponsePromiseFunctionalTest.php (94%) rename Tests/{ => Base}/GetResponsesPromiseFunctionalMidPromiseTest.php (94%) rename Tests/{ => Base}/GetResponsesPromiseFunctionalNoPromiseTest.php (93%) rename Tests/{ => Base}/GetResponsesPromiseFunctionalTest.php (93%) create mode 100644 Tests/Base/KernelServicesTest.php rename Tests/{ => Base}/SyncFunctionalTest.php (90%) rename Tests/{ => Base}/TwigTest.php (91%) delete mode 100644 Tests/KernelServicesTest.php create mode 100644 Tests/NoStopwatch/AsyncDebugFunctionalTest.php create mode 100644 Tests/NoStopwatch/AutowiringDebugTest.php diff --git a/.circleci/config.yml b/.circleci/config.yml index ace2177..a0fe38c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,16 +11,23 @@ jobs: - run: name: Install PHPUnit command: | - composer require phpunit/phpunit:7.* + composer require phpunit/phpunit:7.5.17 --no-update - run: name: Run tests / Symfony 4^3 command: | - composer update -n --prefer-dist --prefer-stable --no-suggest - php vendor/bin/phpunit + composer update -n --prefer-dist --prefer-lowest --no-suggest + php vendor/bin/phpunit --testsuite=base - run: name: Run tests / Symfony 5^0 command: | composer update -n --prefer-dist --no-suggest - php vendor/bin/phpunit \ No newline at end of file + php vendor/bin/phpunit --testsuite=base + + - run: + name: Run tests / No Stopwatch + command: | + composer require symfony/stopwatch:^5.0 + composer update -n --prefer-dist --no-suggest + php vendor/bin/phpunit --testsuite=no-stopwatch \ No newline at end of file diff --git a/.formatter.yml b/.formatter.yml index 67f5fdb..0cf6336 100644 --- a/.formatter.yml +++ b/.formatter.yml @@ -7,7 +7,7 @@ use-sort: strict: true header: | /* - * This file is part of the Symfony Async Kernel + * This file is part of the Drift Http Kernel * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/.php_cs b/.php_cs index 7ed0b96..393510b 100644 --- a/.php_cs +++ b/.php_cs @@ -13,6 +13,7 @@ return PhpCsFixer\Config::create() '@PSR2' => true, '@Symfony' => true, 'single_line_after_imports' => false, + 'no_superfluous_phpdoc_tags' => false ]) ->setFinder($finder) ; \ No newline at end of file diff --git a/AsyncEventDispatcher.php b/AsyncEventDispatcher.php index 5852a77..78f055c 100644 --- a/AsyncEventDispatcher.php +++ b/AsyncEventDispatcher.php @@ -1,7 +1,7 @@ + */ -namespace Drift\HttpKernel; +declare(strict_types=1); +namespace Drift\HttpKernel; use React\Promise\PromiseInterface; -use Symfony\Component\HttpKernel\Event\KernelEvent as Event; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\HttpKernel\Event\KernelEvent as Event; /** - * Interface AsyncEventDispatcherInterface + * Interface AsyncEventDispatcherInterface. */ interface AsyncEventDispatcherInterface extends EventDispatcherInterface { @@ -17,7 +28,7 @@ interface AsyncEventDispatcherInterface extends EventDispatcherInterface * Dispatch an event asynchronously. * * @param string $eventName - * @param Event $event + * @param Event $event * * @return PromiseInterface */ @@ -33,8 +44,8 @@ public function asyncDispatch( * for each listener. * * @param callable[] $listeners - * @param string $eventName - * @param Event $event + * @param string $eventName + * @param Event $event * * @return PromiseInterface */ @@ -43,4 +54,4 @@ public function doAsyncDispatch( string $eventName, Event $event ); -} \ No newline at end of file +} diff --git a/AsyncEventDispatcherMethods.php b/AsyncEventDispatcherMethods.php index 1f794d6..3d820f6 100644 --- a/AsyncEventDispatcherMethods.php +++ b/AsyncEventDispatcherMethods.php @@ -1,5 +1,17 @@ + */ + +declare(strict_types=1); namespace Drift\HttpKernel; @@ -8,15 +20,15 @@ use Symfony\Component\HttpKernel\Event\KernelEvent as Event; /** - * Trait AsyncEventDispatcherMethods + * Trait AsyncEventDispatcherMethods. */ trait AsyncEventDispatcherMethods { /** * Dispatch an event asynchronously. * - * @param string $eventName - * @param Event $event + * @param string $eventName + * @param Event $event * * @return PromiseInterface */ @@ -37,9 +49,9 @@ public function asyncDispatch( * This method can be overridden to add functionality that is executed * for each listener. * - * @param callable[] $listeners - * @param string $eventName - * @param Event $event + * @param callable[] $listeners + * @param string $eventName + * @param Event $event * * @return PromiseInterface */ @@ -65,4 +77,4 @@ public function doAsyncDispatch( return $event; }); } -} \ No newline at end of file +} diff --git a/AsyncHttpKernel.php b/AsyncHttpKernel.php index b42d6b7..92ed5fd 100644 --- a/AsyncHttpKernel.php +++ b/AsyncHttpKernel.php @@ -1,7 +1,7 @@ resolver->getController($request)) { - throw new NotFoundHttpException( - sprintf('Unable to find the controller for path "%s". The route is wrongly configured.', $request->getPathInfo()) - ); + throw new NotFoundHttpException(sprintf('Unable to find the controller for path "%s". The route is wrongly configured.', $request->getPathInfo())); } $event = new ControllerEvent($this, $controller, $request, $type); @@ -297,7 +295,6 @@ private function handleExceptionPromise( ->dispatcher ->asyncDispatch(KernelEvents::EXCEPTION, $event) ->then(function (ExceptionEvent $event) use ($request, $type) { - // Supporting both 4.3 and 5.0 $throwable = ($event instanceof GetResponseForExceptionEvent) ? $event->getException() diff --git a/AsyncKernel.php b/AsyncKernel.php index 4e55dae..404c9b1 100644 --- a/AsyncKernel.php +++ b/AsyncKernel.php @@ -1,7 +1,7 @@ hasDefinition('debug.event_dispatcher')) { + $this->processEventDispatcher($container); + return; } diff --git a/Exception/AsyncEventDispatcherNeededException.php b/Exception/AsyncEventDispatcherNeededException.php index f534399..8f607a0 100644 --- a/Exception/AsyncEventDispatcherNeededException.php +++ b/Exception/AsyncEventDispatcherNeededException.php @@ -1,7 +1,7 @@ true, 'factory' => [ Factory::class, - 'create' - ] - ] + 'create', + ], + ], ], ]; @@ -112,7 +112,7 @@ protected static function getKernel(): KernelInterface ], static::decorateConfiguration($configuration), static::decorateRoutes($routes), - 'dev', static::debug() + static::environment(), static::debug() ); } @@ -141,7 +141,7 @@ protected static function decorateRoutes(array $routes): array } /** - * Kernel in debug mode + * Kernel in debug mode. * * @return bool */ @@ -149,4 +149,14 @@ protected static function debug(): bool { return false; } + + /** + * Kernel in debug mode. + * + * @return string + */ + protected static function environment(): string + { + return 'dev'; + } } diff --git a/Tests/AsyncDebugFunctionalTest.php b/Tests/Base/AsyncDebugFunctionalTest.php similarity index 93% rename from Tests/AsyncDebugFunctionalTest.php rename to Tests/Base/AsyncDebugFunctionalTest.php index b32d8cc..e4ceadb 100644 --- a/Tests/AsyncDebugFunctionalTest.php +++ b/Tests/Base/AsyncDebugFunctionalTest.php @@ -1,7 +1,7 @@ + */ + +declare(strict_types=1); -namespace Drift\HttpKernel\Tests; +namespace Drift\HttpKernel\Tests\Base; +use Drift\HttpKernel\Tests\AsyncKernelFunctionalTest; use Drift\HttpKernel\Tests\Services\AService; /** - * Class AutowiringDebugTest + * Class AutowiringDebugTest. */ class AutowiringDebugTest extends AsyncKernelFunctionalTest { @@ -21,24 +34,24 @@ protected static function decorateConfiguration(array $configuration): array { $configuration = parent::decorateConfiguration($configuration); $configuration['imports'] = [ - ['resource' => dirname(__FILE__) . '/autowiring.yml'] + ['resource' => dirname(__FILE__).'/../autowiring.yml'], ]; return $configuration; } /** - * Test autowiring + * Test autowiring. */ public function testAutowiring() { $aService = $this->get(AService::class); $this->assertTrue($aService->equal); - $this->assertTrue($aService->isTraceable); + $this->assertFalse($aService->isTraceable); } /** - * Kernel in debug mode + * Kernel in debug mode. * * @return bool */ @@ -46,4 +59,4 @@ protected static function debug(): bool { return true; } -} \ No newline at end of file +} diff --git a/Tests/AutowiringTest.php b/Tests/Base/AutowiringTest.php similarity index 57% rename from Tests/AutowiringTest.php rename to Tests/Base/AutowiringTest.php index 63be133..af8a4c0 100644 --- a/Tests/AutowiringTest.php +++ b/Tests/Base/AutowiringTest.php @@ -1,12 +1,25 @@ + */ + +declare(strict_types=1); -namespace Drift\HttpKernel\Tests; +namespace Drift\HttpKernel\Tests\Base; +use Drift\HttpKernel\Tests\AsyncKernelFunctionalTest; use Drift\HttpKernel\Tests\Services\AService; /** - * Class AutowiringTest + * Class AutowiringTest. */ class AutowiringTest extends AsyncKernelFunctionalTest { @@ -21,14 +34,14 @@ protected static function decorateConfiguration(array $configuration): array { $configuration = parent::decorateConfiguration($configuration); $configuration['imports'] = [ - ['resource' => dirname(__FILE__) . '/autowiring.yml'] + ['resource' => dirname(__FILE__).'/../autowiring.yml'], ]; return $configuration; } /** - * Test autowiring + * Test autowiring. */ public function testAutowiring() { @@ -36,4 +49,4 @@ public function testAutowiring() $this->assertTrue($aService->equal); $this->assertFalse($aService->isTraceable); } -} \ No newline at end of file +} diff --git a/Tests/GetResponsePromiseFunctionalTest.php b/Tests/Base/GetResponsePromiseFunctionalTest.php similarity index 94% rename from Tests/GetResponsePromiseFunctionalTest.php rename to Tests/Base/GetResponsePromiseFunctionalTest.php index d7b279f..31b0645 100644 --- a/Tests/GetResponsePromiseFunctionalTest.php +++ b/Tests/Base/GetResponsePromiseFunctionalTest.php @@ -1,7 +1,7 @@ + */ + +declare(strict_types=1); + +namespace Drift\HttpKernel\Tests\Base; + +use Drift\HttpKernel\Tests\AsyncKernelFunctionalTest; +use React\EventLoop\LoopInterface; +use React\Filesystem\Filesystem; + +/** + * Class KernelServicesTest. + */ +class KernelServicesTest extends AsyncKernelFunctionalTest +{ + /** + * Test autowiring. + */ + public function testServices() + { + $this->assertInstanceof(LoopInterface::class, $this->get('reactphp.event_loop')); + $this->assertInstanceof(Filesystem::class, $this->get('drift.filesystem')); + } +} diff --git a/Tests/SyncFunctionalTest.php b/Tests/Base/SyncFunctionalTest.php similarity index 90% rename from Tests/SyncFunctionalTest.php rename to Tests/Base/SyncFunctionalTest.php index 06117ea..2206cea 100644 --- a/Tests/SyncFunctionalTest.php +++ b/Tests/Base/SyncFunctionalTest.php @@ -1,7 +1,7 @@ assertInstanceof(LoopInterface::class, $this->get('reactphp.event_loop')); - $this->assertInstanceof(Filesystem::class, $this->get('drift.filesystem')); - } -} \ No newline at end of file diff --git a/Tests/Listener.php b/Tests/Listener.php index d926a34..2515e4d 100644 --- a/Tests/Listener.php +++ b/Tests/Listener.php @@ -1,7 +1,7 @@ + */ + +declare(strict_types=1); + +namespace Drift\HttpKernel\Tests\NoStopwatch; + +use Drift\HttpKernel\Tests\Base\AsyncDebugFunctionalTest as BaseTest; + +/** + * Class AsyncDebugFunctionalTest. + */ +class AsyncDebugFunctionalTest extends BaseTest +{ + /** + * Kernel in debug mode. + * + * @return string + */ + protected static function environment(): string + { + return 'devnostopwatch'; + } +} diff --git a/Tests/NoStopwatch/AutowiringDebugTest.php b/Tests/NoStopwatch/AutowiringDebugTest.php new file mode 100644 index 0000000..b7f50a2 --- /dev/null +++ b/Tests/NoStopwatch/AutowiringDebugTest.php @@ -0,0 +1,45 @@ + + */ + +declare(strict_types=1); + +namespace Drift\HttpKernel\Tests\NoStopwatch; + +use Drift\HttpKernel\Tests\Base\AutowiringDebugTest as BaseTest; +use Drift\HttpKernel\Tests\Services\AService; + +/** + * Class AutowiringDebugTest. + */ +class AutowiringDebugTest extends BaseTest +{ + /** + * Kernel in debug mode. + * + * @return string + */ + protected static function environment(): string + { + return 'devnostopwatch'; + } + + /** + * Test autowiring. + */ + public function testAutowiring() + { + $aService = $this->get(AService::class); + $this->assertTrue($aService->equal); + $this->assertTrue($aService->isTraceable); + } +} diff --git a/Tests/Services/AService.php b/Tests/Services/AService.php index f04cf8b..5108380 100644 --- a/Tests/Services/AService.php +++ b/Tests/Services/AService.php @@ -1,5 +1,17 @@ + */ + +declare(strict_types=1); namespace Drift\HttpKernel\Tests\Services; @@ -10,7 +22,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** - * Class AService + * Class AService. */ final class AService { @@ -20,19 +32,18 @@ final class AService /** * AService constructor. * - * @param EventDispatcherInterface $dispatcher + * @param EventDispatcherInterface $dispatcher * @param AsyncEventDispatcherInterface $dispatcher - * @param LoopInterface $loop - * @param Filesystem $filesystem + * @param LoopInterface $loop + * @param Filesystem $filesystem */ public function __construct( EventDispatcherInterface $dispatcher1, AsyncEventDispatcherInterface $dispatcher2, LoopInterface $loop, Filesystem $filesystem - ) - { + ) { $this->equal = ($dispatcher1 === $dispatcher2); $this->isTraceable = ($dispatcher2 instanceof TraceableAsyncEventDispatcher); } -} \ No newline at end of file +} diff --git a/TraceableAsyncEventDispatcher.php b/TraceableAsyncEventDispatcher.php index 8590673..47ef2ed 100644 --- a/TraceableAsyncEventDispatcher.php +++ b/TraceableAsyncEventDispatcher.php @@ -1,7 +1,7 @@ - - ./Tests + + ./Tests/Base - - ./Plugin/*/Tests + + + ./Tests/NoStopwatch - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file