2
2
3
3
namespace PhpMiddlewareTest \PhpDebugBar ;
4
4
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 ;
7
8
use Zend \Diactoros \ServerRequestFactory ;
8
- use Zend \Expressive \Application ;
9
- use Zend \Expressive \Router \FastRouteRouter ;
9
+ use Zend \Expressive \Container \ApplicationFactory ;
10
10
use Zend \ServiceManager \ServiceManager ;
11
11
12
12
final class ZendExpressiveTest extends AbstractMiddlewareRunnerTest
13
13
{
14
- protected function dispatchApplication (array $ server , array $ pipe = [])
14
+ private $ testEmitter ;
15
+
16
+ protected function setUp ()
15
17
{
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
+ }
23
22
24
- $ app = new Application ($ router , $ container , null , $ emitter );
23
+ protected function dispatchApplication (array $ server , array $ pipe = [])
24
+ {
25
+ $ container = $ this ->createContainer ();
25
26
26
- $ app ->pipe (PhpDebugBarMiddleware::class);
27
+ $ appFactory = new ApplicationFactory ();
28
+ $ app = $ appFactory ($ container );
27
29
28
30
foreach ($ pipe as $ pattern => $ middleware ) {
29
31
$ app ->get ($ pattern , $ middleware );
@@ -36,6 +38,21 @@ protected function dispatchApplication(array $server, array $pipe = [])
36
38
37
39
$ app ->run ($ serverRequest );
38
40
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 );
40
57
}
41
58
}
0 commit comments