diff --git a/.github/workflows/cs-tests.yml b/.github/workflows/cs-tests.yml
new file mode 100644
index 0000000..3da9965
--- /dev/null
+++ b/.github/workflows/cs-tests.yml
@@ -0,0 +1,46 @@
+on:
+ - push
+
+name: Run phpcs checks
+
+jobs:
+ mutation:
+ name: PHP ${{ matrix.php }}-${{ matrix.os }}
+
+ runs-on: ${{ matrix.os }}
+
+ strategy:
+ matrix:
+ os:
+ - ubuntu-latest
+
+ php:
+ - "8.1"
+ - "8.2"
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+
+ - name: Install PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: "${{ matrix.php }}"
+ tools: composer:v2, cs2pr
+ coverage: none
+
+ - name: Determine composer cache directory
+ run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
+
+ - name: Cache dependencies installed with composer
+ uses: actions/cache@v3
+ with:
+ path: ${{ env.COMPOSER_CACHE_DIR }}
+ key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
+ restore-keys: |
+ php${{ matrix.php }}-composer-
+ - name: Install dependencies with composer
+ run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
+
+ - name: Run phpcs checks
+ run: vendor/bin/phpcs
diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml
new file mode 100644
index 0000000..74550fc
--- /dev/null
+++ b/.github/workflows/static-analysis.yml
@@ -0,0 +1,46 @@
+on:
+ - push
+
+name: Run static analysis
+
+jobs:
+ mutation:
+ name: PHP ${{ matrix.php }}-${{ matrix.os }}
+
+ runs-on: ${{ matrix.os }}
+
+ strategy:
+ matrix:
+ os:
+ - ubuntu-latest
+
+ php:
+ - "8.1"
+ - "8.2"
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+
+ - name: Install PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: "${{ matrix.php }}"
+ tools: composer:v2, cs2pr
+ coverage: none
+
+ - name: Determine composer cache directory
+ run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
+
+ - name: Cache dependencies installed with composer
+ uses: actions/cache@v3
+ with:
+ path: ${{ env.COMPOSER_CACHE_DIR }}
+ key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
+ restore-keys: |
+ php${{ matrix.php }}-composer-
+ - name: Install dependencies with composer
+ run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
+
+ - name: Run static analysis
+ run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4
diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml
new file mode 100644
index 0000000..d2ab8e7
--- /dev/null
+++ b/.github/workflows/unit-tests.yml
@@ -0,0 +1,47 @@
+on:
+ - push
+
+name: Run PHPUnit tests
+
+jobs:
+ mutation:
+ name: PHP ${{ matrix.php }}-${{ matrix.os }}
+
+ runs-on: ${{ matrix.os }}
+
+ strategy:
+ matrix:
+ os:
+ - ubuntu-latest
+
+ php:
+ - "8.1"
+ - "8.2"
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+
+ - name: Install PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: "${{ matrix.php }}"
+ tools: composer:v2, cs2pr
+ coverage: none
+
+ - name: Determine composer cache directory
+ run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
+
+ - name: Cache dependencies installed with composer
+ uses: actions/cache@v3
+ with:
+ path: ${{ env.COMPOSER_CACHE_DIR }}
+ key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
+ restore-keys: |
+ php${{ matrix.php }}-composer-
+
+ - name: Install dependencies with composer
+ run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
+
+ - name: Run PHPUnit tests
+ run: vendor/bin/phpunit --colors=always
diff --git a/.gitignore b/.gitignore
index 670d08c..178a6df 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
clover.xml
coveralls-upload.json
-phpunit.xml
+.phpcs-cache
+.phpunit.result.cache
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
diff --git a/README.md b/README.md
index 77e1be8..da93d69 100644
--- a/README.md
+++ b/README.md
@@ -3,20 +3,22 @@
DotKernel's debug bar built on top of [maximebf/php-debugbar](https://github.com/maximebf/php-debugbar).

+
[](https://github.com/dotkernel/dot-debugbar/issues)
[](https://github.com/dotkernel/dot-debugbar/network)
[](https://github.com/dotkernel/dot-debugbar/stargazers)
-[](https://github.com/dotkernel/dot-debugbar/blob/main/LICENSE.md)
+[](https://github.com/dotkernel/dot-debugbar/blob/1.0/LICENSE.md)
-
+[](https://github.com/dotkernel/dot-debugbar/actions/workflows/static-analysis.yml)
+
+[](https://insight.symfony.com/projects/c1dc83af-a4b3-4a46-a80c-d87dff782089)
## Install
Install dot-debugbar in your application by running the following command:
-```bash
-$ composer require dotkernel/dot-debugbar
-```
+
+ composer require dotkernel/dot-debugbar
## Setup
@@ -27,7 +29,7 @@ Once installed, the following components need to be registered by adding:
Locate the library's assets directory, called `assets` and copy **its contents** to your application under `public/debugbar` directory.
-Locate the library's config file `config/debugbar.local.php.dist` and clone it inside your application as:
+Locate the library's config file `config/debugbar.local.php` and clone it inside your application as:
* `config/autoload/debugbar.local.php.dist`
* `config/autoload/debugbar.local.php`
@@ -56,9 +58,9 @@ This feature can be useful if you need to add custom logic for when dot-debugbar
Other than the data being automatically collected during a session, dot-debugbar can also be used to log messages, measure durations, debug database queries and more...
When you need an instance of DebugBar, locate an instance of it in your application's container using:
-```php
-$debugBar = $container->get(\Dot\DebugBar\DebugBar::class);
-```
+
+ $debugBar = $container->get(\Dot\DebugBar\DebugBar::class);
+
then your factory can inject `$debugBar` as a dependency in your class.
OR
diff --git a/composer.json b/composer.json
index 7d42ba7..1ad8a11 100644
--- a/composer.json
+++ b/composer.json
@@ -16,7 +16,10 @@
}
],
"config": {
- "sort-packages": true
+ "sort-packages": true,
+ "allow-plugins": {
+ "dealerdirect/phpcodesniffer-composer-installer": true
+ }
},
"autoload": {
"psr-4": {
@@ -24,10 +27,31 @@
}
},
"require": {
- "php": "~7.4.0||~8.0.0||~8.1.0",
+ "php": "~8.1.0 || ~8.2.0",
"doctrine/orm": "^2.7",
"dotkernel/dot-twigrenderer": "^3.1",
"laminas/laminas-stratigility": "^3.9",
"maximebf/debugbar": "^1.17"
+ },
+ "autoload-dev": {
+ "psr-4": {
+ "DotTest\\DebugBar\\": "test/"
+ }
+ },
+ "require-dev": {
+ "laminas/laminas-coding-standard": "^2.5",
+ "phpunit/phpunit": "^10.2",
+ "vimeo/psalm": "^5.13"
+ },
+ "scripts": {
+ "check": [
+ "@cs-check",
+ "@test"
+ ],
+ "cs-check": "phpcs",
+ "cs-fix": "phpcbf",
+ "test": "phpunit --colors=always",
+ "test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
+ "static-analysis": "psalm --shepherd --stats"
}
}
diff --git a/config/debugbar.local.php.dist b/config/debugbar.local.php
similarity index 84%
rename from config/debugbar.local.php.dist
rename to config/debugbar.local.php
index 16e0820..a15cc9d 100644
--- a/config/debugbar.local.php.dist
+++ b/config/debugbar.local.php
@@ -27,9 +27,9 @@
* @see \DebugBar\JavascriptRenderer::setOptions()
*/
'javascript_renderer' => [
- 'base_url' => '',
- 'base_path' => '',
- 'disable_jquery' => false,
+ 'base_url' => '',
+ 'base_path' => '',
+ 'disable_jquery' => false,
'disable_fontawesome' => false,
'disable_highlightjs' => false,
],
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..0d4c1dc
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ config
+ src
+ test
+
+
+
+
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 0000000..555b100
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,17 @@
+
+
+
+
+ ./test
+
+
+
+
+
+ ./src
+
+
+
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
new file mode 100644
index 0000000..53d3486
--- /dev/null
+++ b/psalm-baseline.xml
@@ -0,0 +1,16 @@
+
+
+
+
+ getJavascriptRenderer
+ getJavascriptRenderer
+ getJavascriptRenderer
+
+
+
+
+ ErrorResponseGenerator
+ ErrorResponseGenerator
+
+
+
diff --git a/psalm.xml b/psalm.xml
new file mode 100644
index 0000000..9dd8f07
--- /dev/null
+++ b/psalm.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php
index 276fb6f..749985b 100644
--- a/src/ConfigProvider.php
+++ b/src/ConfigProvider.php
@@ -1,6 +1,6 @@
$this->getDependencyConfig()
+ 'dependencies' => $this->getDependencyConfig(),
];
}
@@ -29,14 +29,15 @@ public function __invoke(): array
public function getDependencyConfig(): array
{
return [
- 'aliases' => [
- DebugBarMiddlewareInterface::class => DebugBarMiddleware::class
+ 'aliases' => [
+ DebugBarInterface::class => DebugBar::class,
+ DebugBarMiddlewareInterface::class => DebugBarMiddleware::class,
],
'factories' => [
- DebugBar::class => DebugBarFactory::class,
- DebugBarExtension::class => DebugBarExtensionFactory::class,
- DebugBarMiddleware::class => DebugBarMiddlewareFactory::class
- ]
+ DebugBar::class => DebugBarFactory::class,
+ DebugBarExtension::class => DebugBarExtensionFactory::class,
+ DebugBarMiddleware::class => DebugBarMiddlewareFactory::class,
+ ],
];
}
}
diff --git a/src/DebugBar.php b/src/DebugBar.php
index b8d05aa..83992a1 100644
--- a/src/DebugBar.php
+++ b/src/DebugBar.php
@@ -1,6 +1,6 @@
getConnection()->getConfiguration()->setSQLLogger($debugStack);
+ $configuration->setSQLLogger($debugStack);
$this->addCollector($this->memoryCollector = new MemoryCollector());
$this->addCollector($this->phpInfoCollector = new PhpInfoCollector());
@@ -52,43 +58,48 @@ public function __construct(EntityManager $entityManager, array $config)
$this->addCollector($this->timeDataCollector = new TimeDataCollector());
$this->addCollector($this->exceptionsCollector = new ExceptionsCollector());
- $this->config = $config[DebugBar::class] ?? [];
+ $this->config = $config;
$this->getJavascriptRenderer()->addAssets(
[
- 'dotkernel.css'
- ], []
+ 'dotkernel.css',
+ ],
+ []
);
$this->getJavascriptRenderer()->setOptions($this->config['javascript_renderer'] ?? []);
- if (!empty($this->config['javascript_renderer']['disable_jquery'])) {
+ if (! empty($this->config['javascript_renderer']['disable_jquery'])) {
$this->getJavascriptRenderer()->disableVendor('jquery');
}
- if (!empty($this->config['javascript_renderer']['disable_fontawesome'])) {
+ if (! empty($this->config['javascript_renderer']['disable_fontawesome'])) {
$this->getJavascriptRenderer()->disableVendor('fontawesome');
}
- if (!empty($this->config['javascript_renderer']['disable_highlightjs'])) {
+ if (! empty($this->config['javascript_renderer']['disable_highlightjs'])) {
$this->getJavascriptRenderer()->disableVendor('highlightjs');
}
}
- /**
- * @param string $ipAddress
- * @return bool
- */
- public function shouldEnable(string $ipAddress): bool
+ public function getExceptionsCollector(): ExceptionsCollector
{
- /**
- * If config file is missing: DebugBar is disabled
- */
- if (empty($this->config)) {
- return false;
- }
+ return $this->exceptionsCollector;
+ }
+
+ public function getMessagesCollector(): MessagesCollector
+ {
+ return $this->messagesCollector;
+ }
+
+ public function getTimeDataCollector(): TimeDataCollector
+ {
+ return $this->timeDataCollector;
+ }
+ public function shouldEnable(string $ipAddress): bool
+ {
/**
* If config.enabled is missing/empty/false: DebugBar is disabled
*/
- if (empty($this->config['enabled'])) {
+ if (false === $this->config['enabled']) {
return false;
}
@@ -101,10 +112,6 @@ public function shouldEnable(string $ipAddress): bool
}
}
- /**
- * @param string $ipAddress
- * @return bool
- */
private function shouldEnableIPV4(string $ipAddress): bool
{
/**
@@ -127,10 +134,6 @@ private function shouldEnableIPV4(string $ipAddress): bool
return in_array($ipAddress, $this->config['ipv4Whitelist']);
}
- /**
- * @param string $ipAddress
- * @return bool
- */
private function shouldEnableIPV6(string $ipAddress): bool
{
/**
@@ -153,85 +156,60 @@ private function shouldEnableIPV6(string $ipAddress): bool
return in_array($ipAddress, $this->config['ipv6Whitelist']);
}
- /**
- * @return bool
- */
public function isEnabled(): bool
{
return $this->status === self::STATUS_ENABLED;
}
- /**
- * @return $this
- */
public function enable(): self
{
$this->status = self::STATUS_ENABLED;
+
return $this;
}
- /**
- * @return $this
- */
public function disable(): self
{
$this->status = self::STATUS_DISABLED;
+
return $this;
}
- /**
- * @param $message
- * @param string $label
- * @param bool $isString
- * @return $this
- */
- public function addMessage($message, string $label = 'info', bool $isString = true): self
+ public function addMessage(mixed $message, string $label = 'info', bool $isString = true): self
{
$this->messagesCollector->addMessage($message, $label, $isString);
+
return $this;
}
- /**
- * @param string $name
- * @param string|null $label
- * @return $this
- */
public function startTimer(string $name, ?string $label = null): self
{
$this->timeDataCollector->startMeasure($name, $label);
+
return $this;
}
/**
- * @param string $name
- * @param array $params
- * @return $this
- * @throws DebugBarException
+ * @inheritDoc
*/
public function stopTimer(string $name, array $params = []): self
{
$this->timeDataCollector->stopMeasure($name, $params);
+
return $this;
}
- /**
- * @param string $name
- * @param Closure $closure
- * @return $this
- */
public function measure(string $name, Closure $closure): self
{
$this->timeDataCollector->measure($name, $closure);
+
return $this;
}
- /**
- * @param Throwable $throwable
- * @return $this
- */
public function addThrowable(Throwable $throwable): self
{
$this->exceptionsCollector->addThrowable($throwable);
+
return $this;
}
}
diff --git a/src/DebugBarInterface.php b/src/DebugBarInterface.php
new file mode 100644
index 0000000..5d24b99
--- /dev/null
+++ b/src/DebugBarInterface.php
@@ -0,0 +1,42 @@
+config = $config;
$this->debugBar = $debugBar;
- $this->baseUrl = rtrim($this->config['application']['url'], '/');
+ $this->baseUrl = $baseUrl;
}
/**
@@ -40,20 +35,14 @@ public function getFunctions(): array
];
}
- /**
- * @return bool
- */
public function renderDebugBarEnabled(): bool
{
return $this->debugBar->isEnabled();
}
- /**
- * @return string|null
- */
public function renderDebugBarCss(): ?string
{
- if (!$this->debugBar->isEnabled()) {
+ if (! $this->debugBar->isEnabled()) {
return null;
}
@@ -66,12 +55,9 @@ public function renderDebugBarCss(): ?string
return $return;
}
- /**
- * @return string|null
- */
public function renderDebugBarJs(): ?string
{
- if (!$this->debugBar->isEnabled()) {
+ if (! $this->debugBar->isEnabled()) {
return null;
}
diff --git a/src/Factory/DebugBarExtensionFactory.php b/src/Factory/DebugBarExtensionFactory.php
index 55c72eb..b30b117 100644
--- a/src/Factory/DebugBarExtensionFactory.php
+++ b/src/Factory/DebugBarExtensionFactory.php
@@ -1,28 +1,67 @@
has(DebugBarInterface::class)) {
+ throw new Exception(DebugBarFactory::MESSAGE_MISSING_DEBUG_BAR);
+ }
+
+ if (! $container->has('config')) {
+ throw new Exception(DebugBarFactory::MESSAGE_MISSING_CONFIG);
+ }
+ $config = $container->get('config');
+
+ if (
+ ! array_key_exists(DebugBar::class, $config)
+ || ! is_array($config[DebugBar::class])
+ || empty($config[DebugBar::class])
+ ) {
+ throw new Exception(DebugBarFactory::MESSAGE_MISSING_PACKAGE_CONFIG);
+ }
+ $config = $config[DebugBar::class];
+
+ if (
+ ! array_key_exists('application', $config)
+ || ! is_array($config['application'])
+ || empty($config['application'])
+ ) {
+ throw new Exception(DebugBarFactory::MESSAGE_MISSING_CONFIG_APPLICATION);
+ }
+
+ if (
+ ! array_key_exists('url', $config['application'])
+ || ! is_string($config['application']['url'])
+ || empty($config['application']['url'])
+ ) {
+ throw new Exception(DebugBarFactory::MESSAGE_MISSING_CONFIG_APPLICATION_URL);
+ }
+
return new DebugBarExtension(
- $container->get(DebugBar::class),
- $container->get('config')
+ $container->get(DebugBarInterface::class),
+ $config['application']['url']
);
}
}
diff --git a/src/Factory/DebugBarFactory.php b/src/Factory/DebugBarFactory.php
index 0e11699..fa84e8d 100644
--- a/src/Factory/DebugBarFactory.php
+++ b/src/Factory/DebugBarFactory.php
@@ -1,30 +1,81 @@
has(EntityManager::class)) {
+ throw new Exception(self::MESSAGE_MISSING_ENTITY_MANAGER);
+ }
+
+ if (! $container->has('config')) {
+ throw new Exception(self::MESSAGE_MISSING_CONFIG);
+ }
+ $config = $container->get('config');
+
+ if (
+ ! array_key_exists(DebugBar::class, $config)
+ || ! is_array($config[DebugBar::class])
+ || empty($config[DebugBar::class])
+ ) {
+ throw new Exception(self::MESSAGE_MISSING_PACKAGE_CONFIG);
+ }
+ $config = $config[DebugBar::class];
+
+ if (! array_key_exists('enabled', $config) || ! is_bool($config['enabled'])) {
+ throw new Exception(self::MESSAGE_MISSING_CONFIG_ENABLED);
+ }
+
+ if (! array_key_exists('ipv4Whitelist', $config) || ! is_array($config['ipv4Whitelist'])) {
+ throw new Exception(self::MESSAGE_MISSING_CONFIG_IPV4_WHITELIST);
+ }
+
+ if (! array_key_exists('ipv6Whitelist', $config) || ! is_array($config['ipv6Whitelist'])) {
+ throw new Exception(self::MESSAGE_MISSING_CONFIG_IPV6_WHITELIST);
+ }
+
+ if (! array_key_exists('javascript_renderer', $config) || ! is_array($config['javascript_renderer'])) {
+ throw new Exception(self::MESSAGE_MISSING_CONFIG_JAVASCRIPT_RENDERER);
+ }
+
+ /** @var EntityManager $em */
+ $em = $container->get(EntityManager::class);
return new DebugBar(
- $container->get(EntityManager::class),
- $container->get('config') ?? []
+ $em->getConnection()->getConfiguration(),
+ $config
);
}
}
diff --git a/src/Factory/DebugBarMiddlewareFactory.php b/src/Factory/DebugBarMiddlewareFactory.php
index e249a8e..07bbf59 100644
--- a/src/Factory/DebugBarMiddlewareFactory.php
+++ b/src/Factory/DebugBarMiddlewareFactory.php
@@ -1,12 +1,13 @@
has(DebugBarInterface::class)) {
+ throw new Exception(DebugBarFactory::MESSAGE_MISSING_DEBUG_BAR);
+ }
+
+ if (! $container->has(ResponseInterface::class)) {
+ throw new Exception(self::MESSAGE_MISSING_RESPONSE_INTERFACE);
+ }
+
return new DebugBarMiddleware(
- $container->get(DebugBar::class),
+ $container->get(DebugBarInterface::class),
$container->get(ResponseInterface::class),
$container->has(ErrorResponseGenerator::class)
? $container->get(ErrorResponseGenerator::class)
diff --git a/src/Middleware/DebugBarMiddleware.php b/src/Middleware/DebugBarMiddleware.php
index 7999c1e..16df017 100644
--- a/src/Middleware/DebugBarMiddleware.php
+++ b/src/Middleware/DebugBarMiddleware.php
@@ -1,10 +1,10 @@
debugBar = $debugBar;
- $this->responseFactory = static fn(): ResponseInterface => $responseFactory();
+ public function __construct(
+ DebugBarInterface $debugBar,
+ callable $responseFactory,
+ ?callable $responseGenerator = null
+ ) {
+ $this->debugBar = $debugBar;
+ $this->responseFactory = static fn(): ResponseInterface => $responseFactory();
$this->responseGenerator = $responseGenerator ?: new ErrorResponseGenerator();
}
- /**
- * @param ServerRequestInterface $request
- * @param RequestHandlerInterface $handler
- * @return ResponseInterface
- */
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if ($this->debugBar->shouldEnable($request->getServerParams()['REMOTE_ADDR'])) {
@@ -63,16 +57,10 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
}
}
- /**
- * Creates and returns a callable error handler that raises exceptions.
- *
- * Only raises exceptions for errors that are within the error_reporting mask.
- */
- private function createErrorHandler() : callable
+ private function createErrorHandler(): callable
{
- return function (int $errno, string $errstr, string $errfile, int $errline) : void {
+ return function (int $errno, string $errstr, string $errfile, int $errline): void {
if (! (error_reporting() & $errno)) {
- // error_reporting does not include this error
return;
}
@@ -80,13 +68,6 @@ private function createErrorHandler() : callable
};
}
- /**
- * Handles all throwables, generating and returning a response.
- *
- * Passes the error, request, and response prototype to createErrorResponse(),
- * triggers all listeners with the same arguments (but using the response
- * returned from createErrorResponse()), and then returns the response.
- */
private function handleThrowable(Throwable $e, ServerRequestInterface $request): ResponseInterface
{
$generator = $this->responseGenerator;
diff --git a/src/Middleware/DebugBarMiddlewareInterface.php b/src/Middleware/DebugBarMiddlewareInterface.php
index 3f19cca..5da2593 100644
--- a/src/Middleware/DebugBarMiddlewareInterface.php
+++ b/src/Middleware/DebugBarMiddlewareInterface.php
@@ -1,9 +1,14 @@
[
+ 'enabled' => true,
+ 'ipv4Whitelist' => [],
+ 'ipv6Whitelist' => [],
+ 'javascript_renderer' => [],
+ 'application' => [
+ 'url' => 'https://example.com',
+ ],
+ ],
+ ];
+}
diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php
new file mode 100644
index 0000000..338701c
--- /dev/null
+++ b/test/ConfigProviderTest.php
@@ -0,0 +1,55 @@
+config = (new ConfigProvider())();
+ }
+
+ public function testHasDependencies(): void
+ {
+ $this->assertArrayHasKey('dependencies', $this->config);
+ }
+
+ public function testDependenciesHasFactories(): void
+ {
+ $this->assertArrayHasKey('factories', $this->config['dependencies']);
+
+ $factories = $this->config['dependencies']['factories'];
+ $this->assertArrayHasKey(DebugBar::class, $factories);
+ $this->assertSame(DebugBarFactory::class, $factories[DebugBar::class]);
+ $this->assertArrayHasKey(DebugBarExtension::class, $factories);
+ $this->assertSame(DebugBarExtensionFactory::class, $factories[DebugBarExtension::class]);
+ $this->assertArrayHasKey(DebugBarMiddleware::class, $factories);
+ $this->assertSame(DebugBarMiddlewareFactory::class, $factories[DebugBarMiddleware::class]);
+ }
+
+ public function testDependenciesHasAliases(): void
+ {
+ $this->assertArrayHasKey('aliases', $this->config['dependencies']);
+
+ $aliases = $this->config['dependencies']['aliases'];
+ $this->assertArrayHasKey(DebugBarInterface::class, $aliases);
+ $this->assertSame(DebugBar::class, $aliases[DebugBarInterface::class]);
+ $this->assertArrayHasKey(DebugBarMiddlewareInterface::class, $aliases);
+ $this->assertSame(DebugBarMiddleware::class, $aliases[DebugBarMiddlewareInterface::class]);
+ }
+}
diff --git a/test/DebugBarTest.php b/test/DebugBarTest.php
new file mode 100644
index 0000000..82d6f4c
--- /dev/null
+++ b/test/DebugBarTest.php
@@ -0,0 +1,196 @@
+createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, $this->config);
+ $this->assertInstanceOf(DebugBar::class, $dotDebugBar);
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillNotEnableIfConfigDisabled(): void
+ {
+ $config = $this->config[DebugBar::class];
+ $config['enabled'] = false;
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, $config);
+ $this->assertFalse($dotDebugBar->shouldEnable(''));
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillNotEnableIfConfigEnabledButIpAddressIsInvalid(): void
+ {
+ $config = $this->config[DebugBar::class];
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, $config);
+ $this->assertFalse($dotDebugBar->shouldEnable('test'));
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillNotEnableIfConfigEnabledAndValidIpv4AddressNotWhitelisted(): void
+ {
+ $config = $this->config[DebugBar::class];
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, $config);
+ $this->assertFalse($dotDebugBar->shouldEnable('127.0.0.1'));
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillNotEnableIfConfigEnabledAndValidIpv6AddressNotWhitelisted(): void
+ {
+ $config = $this->config[DebugBar::class];
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, $config);
+ $this->assertFalse(
+ $dotDebugBar->shouldEnable('::1')
+ );
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillEnableIfConfigEnabledAndValidWhitelistedIpv4Address(): void
+ {
+ $config = $this->config[DebugBar::class];
+ $config['ipv4Whitelist'][] = '127.0.0.1';
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, $config);
+ $this->assertTrue($dotDebugBar->shouldEnable('127.0.0.1'));
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillEnableIfConfigEnabledAndValidWhitelistedIpv6Address(): void
+ {
+ $config = $this->config[DebugBar::class];
+ $config['ipv6Whitelist'][] = '::1';
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, $config);
+ $this->assertTrue($dotDebugBar->shouldEnable('::1'));
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillEnableIfConfigEnabledAndAllowAnyValidIpv4Address(): void
+ {
+ $config = $this->config[DebugBar::class];
+ $config['ipv4Whitelist'][] = '*';
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, $config);
+ $this->assertTrue($dotDebugBar->shouldEnable('127.0.0.1'));
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillEnableIfConfigEnabledAndAllowAnyValidIpv6Address(): void
+ {
+ $config = $this->config[DebugBar::class];
+ $config['ipv6Whitelist'][] = '*';
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, $config);
+ $this->assertTrue($dotDebugBar->shouldEnable('::1'));
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillToggle(): void
+ {
+ $config = $this->config[DebugBar::class];
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, $config);
+ $this->assertFalse($dotDebugBar->isEnabled());
+ $dotDebugBar->enable();
+ $this->assertInstanceOf(DebugBar::class, $dotDebugBar);
+ $this->assertTrue($dotDebugBar->isEnabled());
+ $dotDebugBar->disable();
+ $this->assertInstanceOf(DebugBar::class, $dotDebugBar);
+ $this->assertFalse($dotDebugBar->isEnabled());
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillAddMessage(): void
+ {
+ $config = $this->config[DebugBar::class];
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, $config);
+ $this->assertCount(0, $dotDebugBar->getMessagesCollector()->getMessages());
+ $dotDebugBar->addMessage('test');
+ $this->assertInstanceOf(DebugBar::class, $dotDebugBar);
+ $this->assertCount(1, $dotDebugBar->getMessagesCollector()->getMessages());
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillStartStopMeasureTimer(): void
+ {
+ $config = $this->config[DebugBar::class];
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, $config);
+ $this->assertFalse($dotDebugBar->getTimeDataCollector()->hasStartedMeasure('test'));
+ $dotDebugBar->startTimer('test');
+ $this->assertInstanceOf(DebugBar::class, $dotDebugBar);
+ $this->assertTrue($dotDebugBar->getTimeDataCollector()->hasStartedMeasure('test'));
+ $dotDebugBar->stopTimer('test');
+ $this->assertInstanceOf(DebugBar::class, $dotDebugBar);
+ $this->assertFalse($dotDebugBar->getTimeDataCollector()->hasStartedMeasure('test'));
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillAddThrowable(): void
+ {
+ $config = $this->config[DebugBar::class];
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, $config);
+ $this->assertCount(0, $dotDebugBar->getExceptionsCollector()->getExceptions());
+ $dotDebugBar->addThrowable(new \Exception('test'));
+ $this->assertInstanceOf(DebugBar::class, $dotDebugBar);
+ $this->assertCount(1, $dotDebugBar->getExceptionsCollector()->getExceptions());
+ }
+}
diff --git a/test/DummyResponse.php b/test/DummyResponse.php
new file mode 100644
index 0000000..6fea2c4
--- /dev/null
+++ b/test/DummyResponse.php
@@ -0,0 +1,73 @@
+assertNull(null);
+ }
+
+ /**
+ * @throws Exception
+ */
+ public function testGetFunctions(): void
+ {
+ $dotDebugBar = $this->createMock(DebugBar::class);
+ $extension = new DebugBarExtension($dotDebugBar, $this->config[DebugBar::class]['application']['url']);
+ $functions = $extension->getFunctions();
+ $this->assertIsArray($functions);
+ $this->assertCount(3, $functions);
+ $this->assertInstanceOf(TwigFunction::class, $functions[0]);
+ $this->assertInstanceOf(TwigFunction::class, $functions[1]);
+ $this->assertInstanceOf(TwigFunction::class, $functions[2]);
+ $this->assertSame('debugBarEnabled', $functions[0]->getName());
+ $this->assertSame('debugBarCss', $functions[1]->getName());
+ $this->assertSame('debugBarJs', $functions[2]->getName());
+ }
+
+ /**
+ * @throws Exception
+ * @throws DebugBarException
+ */
+ public function testRenderDebugBarEnabledReturnsTrueWhenEnabled(): void
+ {
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, []);
+ $dotDebugBar->enable();
+
+ $extension = new DebugBarExtension($dotDebugBar, $this->config[DebugBar::class]['application']['url']);
+ $this->assertTrue($extension->renderDebugBarEnabled());
+ }
+
+ /**
+ * @throws Exception
+ * @throws DebugBarException
+ */
+ public function testRenderDebugBarEnabledReturnsFalseWhenDisabled(): void
+ {
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, []);
+ $dotDebugBar->disable();
+
+ $extension = new DebugBarExtension($dotDebugBar, $this->config[DebugBar::class]['application']['url']);
+ $this->assertFalse($extension->renderDebugBarEnabled());
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillNotRenderDebugBarCssWhenDisabled(): void
+ {
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, []);
+ $dotDebugBar->disable();
+
+ $extension = new DebugBarExtension($dotDebugBar, $this->config[DebugBar::class]['application']['url']);
+ $this->assertNull($extension->renderDebugBarCss());
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillRenderDebugBarCssWhenEnabled(): void
+ {
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, []);
+ $dotDebugBar->enable();
+
+ $extension = new DebugBarExtension($dotDebugBar, $this->config[DebugBar::class]['application']['url']);
+ $html = $extension->renderDebugBarCss();
+ $this->assertStringContainsString('dotkernel.css', $html);
+ $this->assertStringContainsString('debugbar.css', $html);
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillNotRenderDebugBarJsWhenDisabled(): void
+ {
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, []);
+ $dotDebugBar->disable();
+
+ $extension = new DebugBarExtension($dotDebugBar, $this->config[DebugBar::class]['application']['url']);
+ $this->assertNull($extension->renderDebugBarJs());
+ }
+
+ /**
+ * @throws DebugBarException
+ * @throws Exception
+ */
+ public function testWillRenderDebugBarJsWhenEnabled(): void
+ {
+ $configuration = $this->createMock(Configuration::class);
+ $dotDebugBar = new DebugBar($configuration, []);
+ $dotDebugBar->enable();
+
+ $extension = new DebugBarExtension($dotDebugBar, $this->config[DebugBar::class]['application']['url']);
+ $html = $extension->renderDebugBarJs();
+ $this->assertStringContainsString('var phpdebugbar = new PhpDebugBar.DebugBar();', $html);
+ $this->assertStringContainsString('debugbar.js', $html);
+ }
+}
diff --git a/test/Factory/DebugBarExtensionFactoryTest.php b/test/Factory/DebugBarExtensionFactoryTest.php
new file mode 100644
index 0000000..ee975b2
--- /dev/null
+++ b/test/Factory/DebugBarExtensionFactoryTest.php
@@ -0,0 +1,103 @@
+createMock(ContainerInterface::class);
+
+ $container->method('has')->willReturnMap([
+ [DebugBarInterface::class, true],
+ ['config', false],
+ ]);
+
+ $this->expectExceptionMessage(DebugBarFactory::MESSAGE_MISSING_CONFIG);
+ (new DebugBarExtensionFactory())($container);
+ }
+
+ /**
+ * @throws Exception
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ */
+ public function testWillNotCreateExtensionWithoutPackageConfig(): void
+ {
+ $container = $this->createMock(ContainerInterface::class);
+
+ $container->method('has')->willReturnMap([
+ [DebugBarInterface::class, true],
+ ['config', true],
+ ]);
+
+ $container->method('get')->willReturn([
+ 'test',
+ ]);
+
+ $this->expectExceptionMessage(DebugBarFactory::MESSAGE_MISSING_PACKAGE_CONFIG);
+ (new DebugBarExtensionFactory())($container);
+ }
+
+ /**
+ * @throws Exception
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ */
+ public function testWillNotCreateExtensionWithoutDebugBar(): void
+ {
+ $container = $this->createMock(ContainerInterface::class);
+
+ $container->method('has')->willReturnMap([
+ ['config', true],
+ [DebugBarInterface::class, false],
+ ]);
+
+ $this->expectExceptionMessage(DebugBarFactory::MESSAGE_MISSING_DEBUG_BAR);
+ (new DebugBarExtensionFactory())($container);
+ }
+
+ /**
+ * @throws Exception
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ */
+ public function testWillCreateExtension(): void
+ {
+ $container = $this->createMock(ContainerInterface::class);
+ $debugBar = $this->createMock(DebugBarInterface::class);
+
+ $container->method('has')->willReturnMap([
+ ['config', true],
+ [DebugBarInterface::class, true],
+ ]);
+
+ $container->method('get')->willReturnMap([
+ ['config', $this->config],
+ [DebugBarInterface::class, $debugBar],
+ ]);
+
+ $extension = (new DebugBarExtensionFactory())($container);
+ $this->assertInstanceOf(DebugBarExtension::class, $extension);
+ }
+}
diff --git a/test/Factory/DebugBarFactoryTest.php b/test/Factory/DebugBarFactoryTest.php
new file mode 100644
index 0000000..c486461
--- /dev/null
+++ b/test/Factory/DebugBarFactoryTest.php
@@ -0,0 +1,219 @@
+createMock(ContainerInterface::class);
+
+ $container->expects($this->once())
+ ->method('has')
+ ->with(EntityManager::class)
+ ->willReturn(false);
+
+ $this->expectExceptionMessage(DebugBarFactory::MESSAGE_MISSING_ENTITY_MANAGER);
+ (new DebugBarFactory())($container);
+ }
+
+ /**
+ * @throws Exception
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws DebugBarException
+ */
+ public function testWillNotCreateServiceWithoutConfig(): void
+ {
+ $container = $this->createMock(ContainerInterface::class);
+
+ $container->method('has')->willReturnMap([
+ [EntityManager::class, true],
+ ['config', false],
+ ]);
+
+ $this->expectExceptionMessage(DebugBarFactory::MESSAGE_MISSING_CONFIG);
+ (new DebugBarFactory())($container);
+ }
+
+ /**
+ * @throws Exception
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws DebugBarException
+ */
+ public function testWillNotCreateServiceWithoutMissingConfigEnabled(): void
+ {
+ $container = $this->createMock(ContainerInterface::class);
+
+ $container->method('has')->willReturnMap([
+ [EntityManager::class, true],
+ ['config', true],
+ ]);
+
+ $container->method('get')->willReturnMap([
+ [EntityManager::class, true],
+ [
+ 'config',
+ [
+ DebugBar::class => [
+ 'test',
+ ],
+ ],
+ ],
+ ]);
+
+ $this->expectExceptionMessage(DebugBarFactory::MESSAGE_MISSING_CONFIG_ENABLED);
+ (new DebugBarFactory())($container);
+ }
+
+ /**
+ * @throws Exception
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws DebugBarException
+ */
+ public function testWillNotCreateServiceWithoutMissingConfigIPv4Whitelist(): void
+ {
+ $container = $this->createMock(ContainerInterface::class);
+
+ $container->method('has')->willReturnMap([
+ [EntityManager::class, true],
+ ['config', true],
+ ]);
+
+ $container->method('get')->willReturnMap([
+ [EntityManager::class, true],
+ [
+ 'config',
+ [
+ DebugBar::class => [
+ 'enabled' => true,
+ ],
+ ],
+ ],
+ ]);
+
+ $this->expectExceptionMessage(DebugBarFactory::MESSAGE_MISSING_CONFIG_IPV4_WHITELIST);
+ (new DebugBarFactory())($container);
+ }
+
+ /**
+ * @throws Exception
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws DebugBarException
+ */
+ public function testWillNotCreateServiceWithoutMissingConfigIPv6Whitelist(): void
+ {
+ $container = $this->createMock(ContainerInterface::class);
+
+ $container->method('has')->willReturnMap([
+ [EntityManager::class, true],
+ ['config', true],
+ ]);
+
+ $container->method('get')->willReturnMap([
+ [EntityManager::class, true],
+ [
+ 'config',
+ [
+ DebugBar::class => [
+ 'enabled' => true,
+ 'ipv4Whitelist' => [],
+ ],
+ ],
+ ],
+ ]);
+
+ $this->expectExceptionMessage(DebugBarFactory::MESSAGE_MISSING_CONFIG_IPV6_WHITELIST);
+ (new DebugBarFactory())($container);
+ }
+
+ /**
+ * @throws Exception
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws DebugBarException
+ */
+ public function testWillNotCreateServiceWithoutMissingConfigJavaScriptRenderer(): void
+ {
+ $container = $this->createMock(ContainerInterface::class);
+
+ $container->method('has')->willReturnMap([
+ [EntityManager::class, true],
+ ['config', true],
+ ]);
+
+ $container->method('get')->willReturnMap([
+ [EntityManager::class, true],
+ [
+ 'config',
+ [
+ DebugBar::class => [
+ 'enabled' => true,
+ 'ipv4Whitelist' => [],
+ 'ipv6Whitelist' => [],
+ ],
+ ],
+ ],
+ ]);
+
+ $this->expectExceptionMessage(DebugBarFactory::MESSAGE_MISSING_CONFIG_JAVASCRIPT_RENDERER);
+ (new DebugBarFactory())($container);
+ }
+
+ /**
+ * @throws Exception
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws DebugBarException
+ */
+ public function testWillCreateService(): void
+ {
+ $configuration = $this->createMock(Configuration::class);
+ $connection = $this->createMock(Connection::class);
+ $container = $this->createMock(ContainerInterface::class);
+ $em = $this->createMock(EntityManager::class);
+
+ $container->method('has')->willReturnMap([
+ [EntityManager::class, true],
+ ['config', true],
+ ]);
+
+ $container->method('get')->willReturnMap([
+ [EntityManager::class, $em],
+ ['config', $this->config],
+ ]);
+
+ $em->expects($this->once())->method('getConnection')->willReturn($connection);
+ $connection->expects($this->once())->method('getConfiguration')->willReturn($configuration);
+
+ $service = (new DebugBarFactory())($container);
+ $this->assertInstanceOf(DebugBarInterface::class, $service);
+ }
+}
diff --git a/test/Factory/DebugBarMiddlewareFactoryTest.php b/test/Factory/DebugBarMiddlewareFactoryTest.php
new file mode 100644
index 0000000..df7ee15
--- /dev/null
+++ b/test/Factory/DebugBarMiddlewareFactoryTest.php
@@ -0,0 +1,83 @@
+createMock(ContainerInterface::class);
+
+ $container->expects($this->once())
+ ->method('has')
+ ->with(DebugBarInterface::class)
+ ->willReturn(false);
+
+ $this->expectExceptionMessage(DebugBarFactory::MESSAGE_MISSING_DEBUG_BAR);
+ (new DebugBarMiddlewareFactory())($container);
+ }
+
+ /**
+ * @throws Exception
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ */
+ public function testWillNotCreateServiceWithoutResponseInterface(): void
+ {
+ $container = $this->createMock(ContainerInterface::class);
+
+ $container->method('has')->willReturnMap([
+ [DebugBarInterface::class, true],
+ [ResponseInterface::class, false],
+ ]);
+
+ $this->expectExceptionMessage(DebugBarMiddlewareFactory::MESSAGE_MISSING_RESPONSE_INTERFACE);
+ (new DebugBarMiddlewareFactory())($container);
+ }
+
+ /**
+ * @throws Exception
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ */
+ public function testWillCreateMiddleware(): void
+ {
+ $container = $this->createMock(ContainerInterface::class);
+ $debugBar = $this->createMock(DebugBarInterface::class);
+
+ $container->method('has')->willReturnMap([
+ [DebugBarInterface::class, true],
+ [ResponseInterface::class, true],
+ ]);
+
+ $container->method('get')->willReturnMap([
+ [DebugBarInterface::class, $debugBar],
+ [ResponseInterface::class, new DummyResponse()],
+ ]);
+
+ $middleware = (new DebugBarMiddlewareFactory())($container);
+ $this->assertInstanceOf(DebugBarMiddlewareInterface::class, $middleware);
+ }
+}
diff --git a/test/Middleware/DebugBarMiddlewareTest.php b/test/Middleware/DebugBarMiddlewareTest.php
new file mode 100644
index 0000000..a895b68
--- /dev/null
+++ b/test/Middleware/DebugBarMiddlewareTest.php
@@ -0,0 +1,64 @@
+createMock(DebugBarInterface::class);
+ $middleware = new DebugBarMiddleware($debugBar, new DummyResponse());
+ $this->assertInstanceOf(DebugBarMiddlewareInterface::class, $middleware);
+ }
+
+ /**
+ * @throws Exception
+ */
+ public function testCanProcess(): void
+ {
+ $debugBar = $this->createMock(DebugBarInterface::class);
+ $request = $this->createMock(ServerRequestInterface::class);
+ $handler = $this->createMock(RequestHandlerInterface::class);
+
+ $request->expects($this->once())->method('getServerParams')->willReturn([
+ 'REMOTE_ADDR' => '127.0.0.1',
+ ]);
+
+ $debugBar->expects($this->once())->method('shouldEnable')->withAnyParameters()->willReturn(true);
+
+ $middleware = new DebugBarMiddleware($debugBar, new DummyResponse());
+ $response = $middleware->process($request, $handler);
+ $this->assertInstanceOf(ResponseInterface::class, $response);
+ }
+
+ /**
+ * @throws Exception
+ * @throws ReflectionException
+ */
+ public function testCreateErrorHandler(): void
+ {
+ $debugBar = $this->createMock(DebugBarInterface::class);
+ $middleware = new DebugBarMiddleware($debugBar, new DummyResponse());
+ $reflection = new ReflectionMethod(DebugBarMiddleware::class, 'createErrorHandler');
+
+ $callable = $reflection->invoke($middleware);
+ $this->assertIsCallable($callable);
+ }
+}