|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Zend Framework (http://framework.zend.com/) |
4 | | - * |
5 | 3 | * @see https://github.com/zendframework/zend-expressive for the canonical source repository |
6 | | - * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com) |
| 4 | + * @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com) |
7 | 5 | * @license https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License |
8 | 6 | */ |
9 | 7 |
|
|
13 | 11 | use Prophecy\Argument; |
14 | 12 | use Prophecy\Prophecy\ObjectProphecy; |
15 | 13 | use Psr\Http\Message\ResponseInterface; |
| 14 | +use SplQueue; |
16 | 15 | use Zend\Diactoros\Response; |
17 | 16 | use Zend\Diactoros\ServerRequest; |
18 | 17 | use Zend\Expressive\Application; |
|
23 | 22 | use Zend\Expressive\Router\RouteResultObserverInterface; |
24 | 23 | use Zend\Expressive\Router\RouterInterface; |
25 | 24 | use Zend\Expressive\Router\ZendRouter; |
| 25 | +use Zend\Stratigility\Http\Request as StratigilityRequest; |
| 26 | +use Zend\Stratigility\Http\Response as StratigilityResponse; |
| 27 | +use Zend\Stratigility\Next; |
| 28 | +use Zend\Stratigility\Route; |
26 | 29 |
|
27 | 30 | class RouteMiddlewareTest extends TestCase |
28 | 31 | { |
@@ -68,6 +71,45 @@ public function testRoutingFailureDueToHttpMethodCallsNextWithNotAllowedResponse |
68 | 71 | $this->assertContains('POST', $allow); |
69 | 72 | } |
70 | 73 |
|
| 74 | + /** |
| 75 | + * @todo Remove for 1.1.0. In that version, you either raise throwables, or |
| 76 | + * you opt in to the legacy error handling, and understand you will receive |
| 77 | + * deprecation notices. |
| 78 | + * @group 419 |
| 79 | + */ |
| 80 | + public function testRoutingFailureDueToHttpMethodCallsNextWithoutEmittingDeprecationNotice() |
| 81 | + { |
| 82 | + // Stratigility request/response required for this test, due to usage of Next instance. |
| 83 | + $request = new StratigilityRequest(new ServerRequest()); |
| 84 | + $response = new StratigilityResponse(new Response()); |
| 85 | + $result = RouteResult::fromRouteFailure(['GET', 'POST']); |
| 86 | + |
| 87 | + $this->router->match($request)->willReturn($result); |
| 88 | + |
| 89 | + $route = new Route('/', function ($error, $request, $response, $next) { |
| 90 | + $this->assertEquals(405, $error); |
| 91 | + $this->assertEquals(405, $response->getStatusCode()); |
| 92 | + return $response; |
| 93 | + }); |
| 94 | + |
| 95 | + $queue = new SplQueue(); |
| 96 | + $queue->enqueue($route); |
| 97 | + |
| 98 | + $done = function ($request, $response, $error = false) { |
| 99 | + $this->fail('Should not reach final handler, but did'); |
| 100 | + }; |
| 101 | + |
| 102 | + $next = new Next($queue, $done); |
| 103 | + |
| 104 | + $app = $this->getApplication(); |
| 105 | + $test = $app->routeMiddleware($request, $response, $next); |
| 106 | + $this->assertInstanceOf(ResponseInterface::class, $test); |
| 107 | + $this->assertEquals(405, $test->getStatusCode()); |
| 108 | + $allow = $test->getHeaderLine('Allow'); |
| 109 | + $this->assertContains('GET', $allow); |
| 110 | + $this->assertContains('POST', $allow); |
| 111 | + } |
| 112 | + |
71 | 113 | public function testGeneralRoutingFailureCallsNextWithSameRequestAndResponse() |
72 | 114 | { |
73 | 115 | $request = new ServerRequest(); |
|
0 commit comments