Skip to content

Commit a202395

Browse files
committed
Config provider for zend expressive
1 parent d3db972 commit a202395

4 files changed

+71
-15
lines changed

Diff for: config/dependency.config.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
return [
4+
'factories' => [
5+
PhpMiddleware\PhpDebugBar\PhpDebugBarMiddleware::class => PhpMiddleware\PhpDebugBar\PhpDebugBarMiddlewareFactory::class,
6+
],
7+
];
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use PhpMiddleware\PhpDebugBar\PhpDebugBarMiddleware;
4+
5+
return [
6+
PhpDebugBarMiddleware::class => [
7+
'middleware' => [
8+
PhpDebugBarMiddleware::class,
9+
],
10+
'priority' => 1000,
11+
],
12+
];

Diff for: src/ConfigProvider.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace PhpMiddleware\PhpDebugBar;
4+
5+
final class ConfigProvider
6+
{
7+
public static function getConfig()
8+
{
9+
$self = new self();
10+
return $self();
11+
}
12+
13+
public function __invoke()
14+
{
15+
return [
16+
'dependencies' => include __DIR__ . '/../config/dependency.config.php',
17+
'middleware_pipeline' => include __DIR__ . '/../config/zend-expressive.middleware_pipeline.config.php',
18+
];
19+
}
20+
}

Diff for: test/ZendExpressiveTest.php

+32-15
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,30 @@
22

33
namespace PhpMiddlewareTest\PhpDebugBar;
44

5-
use PhpMiddleware\PhpDebugBar\PhpDebugBarMiddleware;
6-
use PhpMiddleware\PhpDebugBar\PhpDebugBarMiddlewareFactory;
5+
use Interop\Container\ContainerInterface;
6+
use PhpMiddleware\PhpDebugBar\ConfigProvider;
7+
use Zend\Diactoros\Response\EmitterInterface;
78
use Zend\Diactoros\ServerRequestFactory;
8-
use Zend\Expressive\Application;
9-
use Zend\Expressive\Router\FastRouteRouter;
9+
use Zend\Expressive\Container\ApplicationFactory;
1010
use Zend\ServiceManager\ServiceManager;
1111

1212
final class ZendExpressiveTest extends AbstractMiddlewareRunnerTest
1313
{
14-
protected function dispatchApplication(array $server, array $pipe = [])
14+
private $testEmitter;
15+
16+
protected function setUp()
1517
{
16-
$container = new ServiceManager([
17-
'factories' => [
18-
PhpDebugBarMiddleware::class => PhpDebugBarMiddlewareFactory::class,
19-
],
20-
]);
21-
$router = new FastRouteRouter();
22-
$emitter = new TestEmitter();
18+
parent::setUp();
19+
20+
$this->testEmitter = new TestEmitter();
21+
}
2322

24-
$app = new Application($router, $container, null, $emitter);
23+
protected function dispatchApplication(array $server, array $pipe = [])
24+
{
25+
$container = $this->createContainer();
2526

26-
$app->pipe(PhpDebugBarMiddleware::class);
27+
$appFactory = new ApplicationFactory();
28+
$app = $appFactory($container);
2729

2830
foreach ($pipe as $pattern => $middleware) {
2931
$app->get($pattern, $middleware);
@@ -36,6 +38,21 @@ protected function dispatchApplication(array $server, array $pipe = [])
3638

3739
$app->run($serverRequest);
3840

39-
return $emitter->getResponse();
41+
return $this->testEmitter->getResponse();
42+
}
43+
44+
/**
45+
*
46+
* @return ContainerInterface
47+
*/
48+
private function createContainer()
49+
{
50+
$config = ConfigProvider::getConfig();
51+
52+
$serviceManagerConfig = $config['dependencies'];
53+
$serviceManagerConfig['services']['config'] = $config;
54+
$serviceManagerConfig['services'][EmitterInterface::class] = $this->testEmitter;
55+
56+
return new ServiceManager($serviceManagerConfig);
4057
}
4158
}

0 commit comments

Comments
 (0)