Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Tests for #260 - Stratigility 2.0 and 2.1 #262

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ All notable changes to this project will be documented in this file, in reverse

### Added

- Nothing.
- [#260](https://github.com/zendframework/zend-mvc/pull/260) adds support for
http-interop/http-middleware 0.5.0 via a polyfill provided by the package
webimpress/http-middleware-compatibility. This in turn adds full support for
zend-stratigility ^2.1

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
}
},
"require": {
"container-interop/container-interop": "^1.1",
"php": "^5.6 || ^7.0",
"container-interop/container-interop": "^1.1",
"zendframework/zend-eventmanager": "^3.0",
"zendframework/zend-http": "^2.5.4",
"zendframework/zend-modulemanager": "^2.7.1",
Expand Down
113 changes: 103 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/MiddlewareListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
use Psr\Http\Message\ResponseInterface as PsrResponseInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as PsrServerRequestInterface;
use Webimpress\HttpMiddlewareCompatibility\MiddlewareInterface as CompatMiddleware;
use Zend\EventManager\AbstractListenerAggregate;
use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\Controller\MiddlewareController;
use Zend\Mvc\Exception\InvalidMiddlewareException;
use Zend\Mvc\Exception\ReachedFinalHandlerException;
use Zend\Mvc\Controller\MiddlewareController;
use Zend\Psr7Bridge\Psr7Response;
use Zend\Router\RouteMatch;
use Zend\Stratigility\Delegate\CallableDelegateDecorator;
Expand Down Expand Up @@ -142,7 +143,10 @@ private function createPipeFromSpec(
if (is_string($middlewareToBePiped) && $serviceLocator->has($middlewareToBePiped)) {
$middlewareToBePiped = $serviceLocator->get($middlewareToBePiped);
}
if (! $middlewareToBePiped instanceof MiddlewareInterface && ! is_callable($middlewareToBePiped)) {
if (! $middlewareToBePiped instanceof MiddlewareInterface
&& ! $middlewareToBePiped instanceof CompatMiddleware
&& ! is_callable($middlewareToBePiped)
) {
throw InvalidMiddlewareException::fromMiddlewareName($middlewareName);
}

Expand Down
12 changes: 10 additions & 2 deletions test/MiddlewareListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Webimpress\HttpMiddlewareCompatibility\MiddlewareInterface as CompatMiddleware;
use Zend\Diactoros\Response\HtmlResponse;
use Zend\Diactoros\Response as DiactorosResponse;
use Zend\EventManager\EventManager;
Expand Down Expand Up @@ -102,7 +103,7 @@ public function testSuccessfullyDispatchesHttpInteropMiddleware()
{
$expectedOutput = uniqid('expectedOutput', true);

$middleware = $this->createMock(MiddlewareInterface::class);
$middleware = $this->createMock($this->getMiddlewareInteface());
$middleware->expects($this->once())->method('process')->willReturn(new HtmlResponse($expectedOutput));

$event = $this->createMvcEvent('path', $middleware);
Expand Down Expand Up @@ -168,7 +169,7 @@ public function testSuccessfullyDispatchesPipeOfCallableAndHttpInteropStyleMiddl
return $next($request->withAttribute('firstMiddlewareAttribute', 'firstMiddlewareValue'), $response);
});

$secondMiddleware = $this->createMock(MiddlewareInterface::class);
$secondMiddleware = $this->createMock($this->getMiddlewareInteface());
$secondMiddleware->expects($this->once())
->method('process')
->willReturnCallback(function (ServerRequestInterface $request) {
Expand Down Expand Up @@ -507,4 +508,11 @@ public function alreadySetMvcEventResultProvider()
['a response string'],
];
}

private function getMiddlewareInteface()
{
return interface_exists(CompatMiddleware::class)
? CompatMiddleware::class
: MiddlewareInterface::class;
}
}