@@ -50,17 +50,21 @@ public function createMvcEvent($middlewareMatched, $middleware = null)
50
50
$ this ->routeMatch ->getParam ('middleware ' , false )->willReturn ($ middlewareMatched );
51
51
$ this ->routeMatch ->getParams ()->willReturn ([]);
52
52
53
- $ eventManager = new EventManager ();
54
-
55
- $ serviceManager = $ this ->prophesize (ContainerInterface::class);
56
- $ serviceManager ->has ($ middlewareMatched )->willReturn (true );
57
- $ serviceManager ->get ($ middlewareMatched )->willReturn ($ middleware );
53
+ $ eventManager = new EventManager ();
54
+ $ serviceManager = new ServiceManager ([
55
+ 'factories ' => [
56
+ 'EventManager ' => function () {
57
+ return new EventManager ();
58
+ },
59
+ ],
60
+ 'services ' => [
61
+ $ middlewareMatched => $ middleware ,
62
+ ],
63
+ ]);
58
64
59
65
$ application = $ this ->prophesize (Application::class);
60
66
$ application ->getEventManager ()->willReturn ($ eventManager );
61
- $ application ->getServiceManager ()->will (function () use ($ serviceManager ) {
62
- return $ serviceManager ->reveal ();
63
- });
67
+ $ application ->getServiceManager ()->willReturn ($ serviceManager );
64
68
$ application ->getResponse ()->willReturn ($ response );
65
69
66
70
$ event = new MvcEvent ();
@@ -83,6 +87,7 @@ public function testSuccessfullyDispatchesMiddleware()
83
87
$ application = $ event ->getApplication ();
84
88
85
89
$ application ->getEventManager ()->attach (MvcEvent::EVENT_DISPATCH_ERROR , function ($ e ) {
90
+ die (var_dump ($ e ->getParam ('exception ' )->getMessage ()));
86
91
$ this ->fail (sprintf ('dispatch.error triggered when it should not be: %s ' , var_export ($ e ->getError (), 1 )));
87
92
});
88
93
@@ -249,6 +254,12 @@ public function testCanLoadFromAbstractFactory()
249
254
250
255
$ serviceManager = new ServiceManager ();
251
256
$ serviceManager ->addAbstractFactory (TestAsset \MiddlewareAbstractFactory::class);
257
+ $ serviceManager ->setFactory (
258
+ 'EventManager ' ,
259
+ function () {
260
+ return new EventManager ();
261
+ }
262
+ );
252
263
253
264
$ application = $ this ->prophesize (Application::class);
254
265
$ application ->getEventManager ()->willReturn ($ eventManager );
@@ -349,19 +360,25 @@ public function testValidMiddlewareDispatchCancelsPreviousDispatchFailures()
349
360
$ response = new DiactorosResponse ();
350
361
/* @var $application Application|\PHPUnit_Framework_MockObject_MockObject */
351
362
$ application = $ this ->createMock (Application::class);
352
- $ serviceManager = $ this ->createMock (ServiceManager::class);
353
363
$ eventManager = new EventManager ();
354
364
$ middleware = $ this ->getMockBuilder (\stdClass::class)->setMethods (['__invoke ' ])->getMock ();
365
+ $ serviceManager = new ServiceManager ([
366
+ 'factories ' => [
367
+ 'EventManager ' => function () {
368
+ return new EventManager ();
369
+ },
370
+ ],
371
+ 'services ' => [
372
+ $ middlewareName => $ middleware ,
373
+ ],
374
+ ]);
355
375
356
376
$ application ->expects (self ::any ())->method ('getRequest ' )->willReturn (new Request ());
357
377
$ application ->expects (self ::any ())->method ('getEventManager ' )->willReturn ($ eventManager );
358
378
$ application ->expects (self ::any ())->method ('getServiceManager ' )->willReturn ($ serviceManager );
359
379
$ application ->expects (self ::any ())->method ('getResponse ' )->willReturn (new Response ());
360
380
$ middleware ->expects (self ::once ())->method ('__invoke ' )->willReturn ($ response );
361
381
362
- $ serviceManager ->expects (self ::any ())->method ('has ' )->with ($ middlewareName )->willReturn (true );
363
- $ serviceManager ->expects (self ::any ())->method ('get ' )->with ($ middlewareName )->willReturn ($ middleware );
364
-
365
382
$ event = new MvcEvent ();
366
383
367
384
$ event ->setRequest (new Request ());
@@ -388,20 +405,27 @@ public function testMiddlewareDispatchWillRetrieveAnyCallableReturnValue($middle
388
405
$ routeMatch = new RouteMatch (['middleware ' => $ middlewareName ]);
389
406
/* @var $application Application|\PHPUnit_Framework_MockObject_MockObject */
390
407
$ application = $ this ->createMock (Application::class);
391
- $ serviceManager = $ this ->createMock (ServiceManager::class);
392
408
$ eventManager = new EventManager ();
393
409
$ middleware = $ this ->getMockBuilder (\stdClass::class)->setMethods (['__invoke ' ])->getMock ();
410
+ $ serviceManager = new ServiceManager ([
411
+ 'factories ' => [
412
+ 'EventManager ' => function () {
413
+ return new EventManager ();
414
+ },
415
+ ],
416
+ 'services ' => [
417
+ $ middlewareName => $ middleware ,
418
+ ],
419
+ ]);
394
420
395
421
$ application ->expects (self ::any ())->method ('getRequest ' )->willReturn (new Request ());
396
422
$ application ->expects (self ::any ())->method ('getEventManager ' )->willReturn ($ eventManager );
397
423
$ application ->expects (self ::any ())->method ('getServiceManager ' )->willReturn ($ serviceManager );
398
424
$ application ->expects (self ::any ())->method ('getResponse ' )->willReturn (new Response ());
399
425
$ middleware ->expects (self ::once ())->method ('__invoke ' )->willReturn ($ middlewareResult );
400
426
401
- $ serviceManager ->expects (self ::any ())->method ('has ' )->with ($ middlewareName )->willReturn (true );
402
- $ serviceManager ->expects (self ::any ())->method ('get ' )->with ($ middlewareName )->willReturn ($ middleware );
403
-
404
- $ eventManager ->attach (MvcEvent::EVENT_DISPATCH_ERROR , function () {
427
+ $ eventManager ->attach (MvcEvent::EVENT_DISPATCH_ERROR , function ($ e ) {
428
+ var_dump ($ e ->getParam ('exception ' )->getMessage ());
405
429
self ::fail ('No dispatch error should have been raised ' );
406
430
});
407
431
0 commit comments