From 6060c5636a6b38a9f323dc20c0521e7c57a93605 Mon Sep 17 00:00:00 2001 From: webimpress Date: Mon, 31 Dec 2018 08:42:37 -0600 Subject: [PATCH] Fixed tests for latest dependencies --- test/MiddlewareListenerTest.php | 25 +++++++++++++------------ test/TestAsset/Middleware.php | 10 +++++++--- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/test/MiddlewareListenerTest.php b/test/MiddlewareListenerTest.php index c11c7165c..5681e13fb 100644 --- a/test/MiddlewareListenerTest.php +++ b/test/MiddlewareListenerTest.php @@ -26,6 +26,7 @@ use Zend\Router\RouteMatch; use Zend\ServiceManager\ServiceManager; use Zend\Stdlib\DispatchableInterface; +use Zend\Stratigility\Middleware\CallableMiddlewareWrapper; use Zend\View\Model\ModelInterface; class MiddlewareListenerTest extends TestCase @@ -77,12 +78,12 @@ public function createMvcEvent($middlewareMatched, $middleware = null) public function testSuccessfullyDispatchesMiddleware() { - $event = $this->createMvcEvent('path', function ($request, $response) { + $event = $this->createMvcEvent('path', new CallableMiddlewareWrapper(function ($request, $response) { $this->assertInstanceOf(ServerRequestInterface::class, $request); $this->assertInstanceOf(ResponseInterface::class, $response); $response->getBody()->write('Test!'); return $response; - }); + }, new DiactorosResponse())); $application = $event->getApplication(); $application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) { @@ -128,11 +129,11 @@ public function testMatchedRouteParamsAreInjectedToRequestAsAttributes() $event = $this->createMvcEvent( 'foo', - function (ServerRequestInterface $request, ResponseInterface $response) use (&$routeAttribute) { + new CallableMiddlewareWrapper(function (ServerRequestInterface $request, ResponseInterface $response) use (&$routeAttribute) { $routeAttribute = $request->getAttribute(RouteMatch::class); $response->getBody()->write($request->getAttribute('myParam', 'param did not exist')); return $response; - } + }, new DiactorosResponse()) ); $this->routeMatch->getParams()->willReturn([ @@ -161,12 +162,12 @@ public function testSuccessfullyDispatchesPipeOfCallableAndHttpInteropStyleMiddl $serviceManager = $this->prophesize(ContainerInterface::class); $serviceManager->get('EventManager')->willReturn($eventManager); $serviceManager->has('firstMiddleware')->willReturn(true); - $serviceManager->get('firstMiddleware')->willReturn(function ($request, $response, $next) { + $serviceManager->get('firstMiddleware')->willReturn(new CallableMiddlewareWrapper(function ($request, $response, $next) { $this->assertInstanceOf(ServerRequestInterface::class, $request); $this->assertInstanceOf(ResponseInterface::class, $response); $this->assertTrue(is_callable($next)); return $next($request->withAttribute('firstMiddlewareAttribute', 'firstMiddlewareValue'), $response); - }); + }, $this->prophesize(ResponseInterface::class)->reveal())); $secondMiddleware = $this->createMock(MiddlewareInterface::class); $secondMiddleware->expects($this->once()) @@ -223,9 +224,9 @@ public function testTriggersErrorForUncallableMiddleware() public function testTriggersErrorForExceptionRaisedInMiddleware() { $exception = new \Exception(); - $event = $this->createMvcEvent('path', function ($request, $response) use ($exception) { + $event = $this->createMvcEvent('path', new CallableMiddlewareWrapper(function ($request, $response) use ($exception) { throw $exception; - }); + }, $this->prophesize(ResponseInterface::class)->reveal())); $application = $event->getApplication(); $application->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, function ($e) use ($exception) { @@ -362,7 +363,7 @@ public function testValidMiddlewareDispatchCancelsPreviousDispatchFailures() /* @var $application Application|\PHPUnit_Framework_MockObject_MockObject */ $application = $this->createMock(Application::class); $eventManager = new EventManager(); - $middleware = $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock(); + $middleware = $this->getMockBuilder(MiddlewareInterface::class)->setMethods(['process'])->getMock(); $serviceManager = new ServiceManager([ 'factories' => [ 'EventManager' => function () { @@ -378,7 +379,7 @@ public function testValidMiddlewareDispatchCancelsPreviousDispatchFailures() $application->expects(self::any())->method('getEventManager')->willReturn($eventManager); $application->expects(self::any())->method('getServiceManager')->willReturn($serviceManager); $application->expects(self::any())->method('getResponse')->willReturn(new Response()); - $middleware->expects(self::once())->method('__invoke')->willReturn($response); + $middleware->expects(self::once())->method('process')->willReturn($response); $event = new MvcEvent(); @@ -406,7 +407,7 @@ public function testValidMiddlewareFiresDispatchableInterfaceEventListeners() /* @var $sharedListener callable|\PHPUnit_Framework_MockObject_MockObject */ $sharedListener = $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock(); $eventManager = new EventManager(); - $middleware = $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock(); + $middleware = $this->getMockBuilder(MiddlewareInterface::class)->setMethods(['process'])->getMock(); $serviceManager = new ServiceManager([ 'factories' => [ 'EventManager' => function () use ($sharedManager) { @@ -422,7 +423,7 @@ public function testValidMiddlewareFiresDispatchableInterfaceEventListeners() $application->expects(self::any())->method('getEventManager')->willReturn($eventManager); $application->expects(self::any())->method('getServiceManager')->willReturn($serviceManager); $application->expects(self::any())->method('getResponse')->willReturn(new Response()); - $middleware->expects(self::once())->method('__invoke')->willReturn($response); + $middleware->expects(self::once())->method('process')->willReturn($response); $event = new MvcEvent(); diff --git a/test/TestAsset/Middleware.php b/test/TestAsset/Middleware.php index 289bc3b12..cf477019a 100644 --- a/test/TestAsset/Middleware.php +++ b/test/TestAsset/Middleware.php @@ -7,14 +7,18 @@ namespace ZendTest\Mvc\TestAsset; +use Interop\Http\ServerMiddleware\DelegateInterface; +use Interop\Http\ServerMiddleware\MiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; -use Psr\Http\Message\ResponseInterface; +use Zend\Diactoros\Response; -class Middleware +class Middleware implements MiddlewareInterface { - public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next = null) + public function process(ServerRequestInterface $request, DelegateInterface $delegate) { + $response = new Response(); $response->getBody()->write(__CLASS__); + return $response; } }