Skip to content

Commit

Permalink
Merge pull request #5 from driftphp/fix/fixed-debug-event-dispatcher
Browse files Browse the repository at this point in the history
Fixed kernel when --debug and no stopwatch
  • Loading branch information
mmoreram authored Nov 25, 2019
2 parents 503afe8 + bd3ee80 commit db3129f
Show file tree
Hide file tree
Showing 31 changed files with 296 additions and 142 deletions.
15 changes: 11 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
2 changes: 1 addition & 1 deletion .formatter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ return PhpCsFixer\Config::create()
'@PSR2' => true,
'@Symfony' => true,
'single_line_after_imports' => false,
'no_superfluous_phpdoc_tags' => false
])
->setFinder($finder)
;
2 changes: 1 addition & 1 deletion AsyncEventDispatcher.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* 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.
Expand Down
25 changes: 18 additions & 7 deletions AsyncEventDispatcherInterface.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
<?php

/*
* 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.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <yuhu@mmoreram.com>
*/

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
{
/**
* Dispatch an event asynchronously.
*
* @param string $eventName
* @param Event $event
* @param Event $event
*
* @return PromiseInterface
*/
Expand All @@ -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
*/
Expand All @@ -43,4 +54,4 @@ public function doAsyncDispatch(
string $eventName,
Event $event
);
}
}
26 changes: 19 additions & 7 deletions AsyncEventDispatcherMethods.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?php

/*
* 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.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <yuhu@mmoreram.com>
*/

declare(strict_types=1);

namespace Drift\HttpKernel;

Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -65,4 +77,4 @@ public function doAsyncDispatch(
return $event;
});
}
}
}
9 changes: 3 additions & 6 deletions AsyncHttpKernel.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* 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.
Expand Down Expand Up @@ -60,7 +60,7 @@ class AsyncHttpKernel extends HttpKernel
/**
* AsyncHttpKernel constructor.
*
* @param EventDispatcherInterface $dispatcher
* @param EventDispatcherInterface $dispatcher
* @param ControllerResolverInterface $resolver
* @param RequestStack|null $requestStack
* @param ArgumentResolverInterface|null $argumentResolver
Expand Down Expand Up @@ -159,9 +159,7 @@ private function handleAsyncRaw(Request $request): PromiseInterface
private function callAsyncController(Request $request, int $type): PromiseInterface
{
if (false === $controller = $this->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);
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion AsyncKernel.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* 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.
Expand Down Expand Up @@ -117,6 +117,8 @@ private function processEventDispatcher(ContainerBuilder $container)
private function processEventDispatcherDebug(ContainerBuilder $container)
{
if (!$container->hasDefinition('debug.event_dispatcher')) {
$this->processEventDispatcher($container);

return;
}

Expand Down
2 changes: 1 addition & 1 deletion Exception/AsyncEventDispatcherNeededException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* 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.
Expand Down
2 changes: 1 addition & 1 deletion Exception/AsyncHttpKernelNeededException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* 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.
Expand Down
26 changes: 18 additions & 8 deletions Tests/AsyncKernelFunctionalTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* 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.
Expand All @@ -15,13 +15,13 @@

namespace Drift\HttpKernel\Tests;

use Drift\HttpKernel\AsyncEventDispatcher;
use Drift\HttpKernel\AsyncHttpKernel;
use Mmoreram\BaseBundle\Kernel\DriftBaseKernel;
use Mmoreram\BaseBundle\Tests\BaseFunctionalTest;
use React\EventLoop\Factory;
use React\EventLoop\LoopInterface;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Drift\HttpKernel\AsyncEventDispatcher;
use Drift\HttpKernel\AsyncHttpKernel;
use Symfony\Component\HttpKernel\KernelInterface;

/**
Expand Down Expand Up @@ -72,9 +72,9 @@ protected static function getKernel(): KernelInterface
'public' => true,
'factory' => [
Factory::class,
'create'
]
]
'create',
],
],
],
];

Expand Down Expand Up @@ -112,7 +112,7 @@ protected static function getKernel(): KernelInterface
],
static::decorateConfiguration($configuration),
static::decorateRoutes($routes),
'dev', static::debug()
static::environment(), static::debug()
);
}

Expand Down Expand Up @@ -141,12 +141,22 @@ protected static function decorateRoutes(array $routes): array
}

/**
* Kernel in debug mode
* Kernel in debug mode.
*
* @return bool
*/
protected static function debug(): bool
{
return false;
}

/**
* Kernel in debug mode.
*
* @return string
*/
protected static function environment(): string
{
return 'dev';
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* 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.
Expand All @@ -13,9 +13,11 @@

declare(strict_types=1);

namespace Drift\HttpKernel\Tests;
namespace Drift\HttpKernel\Tests\Base;

use Clue\React\Block;
use Drift\HttpKernel\Tests\AsyncKernelFunctionalTest;
use Drift\HttpKernel\Tests\Listener;
use React\EventLoop\StreamSelectLoop;
use React\Promise;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -56,7 +58,7 @@ protected static function decorateConfiguration(array $configuration): array
}

/**
* Kernel in debug mode
* Kernel in debug mode.
*
* @return bool
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* 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.
Expand All @@ -13,9 +13,11 @@

declare(strict_types=1);

namespace Drift\HttpKernel\Tests;
namespace Drift\HttpKernel\Tests\Base;

use Clue\React\Block;
use Drift\HttpKernel\Tests\AsyncKernelFunctionalTest;
use Drift\HttpKernel\Tests\Listener;
use React\EventLoop\StreamSelectLoop;
use React\Promise;
use Symfony\Component\HttpFoundation\Request;
Expand Down
Loading

0 comments on commit db3129f

Please sign in to comment.