Skip to content

Commit

Permalink
Merge pull request #872 from cakephp/4.x-fix-middleware-loading
Browse files Browse the repository at this point in the history
fix middleware also being inserted in phpunit tests
  • Loading branch information
othercorey authored Jun 7, 2022
2 parents df8dc9e + bd51c6d commit 344fd1a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class Plugin extends BasePlugin
{
/**
* @var \DebugKit\ToolbarService
* @var \DebugKit\ToolbarService|null
*/
protected $service;

Expand Down Expand Up @@ -66,7 +66,10 @@ public function bootstrap(PluginApplicationInterface $app): void
*/
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
{
$middlewareQueue->insertAt(0, new DebugKitMiddleware($this->service));
// Only insert middleware if Toolbar Service is available (not in phpunit run)
if ($this->service) {
$middlewareQueue->insertAt(0, new DebugKitMiddleware($this->service));
}

return $middlewareQueue;
}
Expand Down

0 comments on commit 344fd1a

Please sign in to comment.