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

Commit b315ea9

Browse files
committed
Merge branch 'hotfix/419'
Close #420 Fixes #419
2 parents 815671d + 9fd85e1 commit b315ea9

File tree

6 files changed

+85
-10
lines changed

6 files changed

+85
-10
lines changed

.docheader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* @see https://github.com/zendframework/zend-expressive for the canonical source repository
3-
* @copyright Copyright (c) %regexp:(20\d{2}-)?%%year% Zend Technologies USA Inc. (http://www.zend.com)
3+
* @copyright Copyright (c) %regexp:(20\d{2}-)20\d{2}% Zend Technologies USA Inc. (http://www.zend.com)
44
* @license https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License
55
*/

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 1.0.6 - 2017-01-09
6+
7+
### Added
8+
9+
- Nothing.
10+
11+
### Deprecated
12+
13+
- Nothing.
14+
15+
### Removed
16+
17+
- Nothing.
18+
19+
### Fixed
20+
21+
- [#420](https://github.com/zendframework/zend-expressive/pull/420) fixes the
22+
`routeMiddleware()`'s handling of 405 errors such that it now no longer emits
23+
deprecation notices when running under the Stratigility 1.3 series.
24+
525
## 1.0.5 - 2016-12-08
626

727
### Added

src/Application.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* @see https://github.com/zendframework/zend-expressive for the canonical source repository
4-
* @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)
55
* @license https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License
66
*/
77

@@ -423,6 +423,10 @@ public function routeMiddleware(ServerRequestInterface $request, ResponseInterfa
423423
if ($result->isMethodFailure()) {
424424
$response = $response->withStatus(405)
425425
->withHeader('Allow', implode(',', $result->getAllowedMethods()));
426+
427+
// Need to swallow deprecation notices, as this is how 405 errors
428+
// are reported in the 1.0 series.
429+
$this->swallowDeprecationNotices();
426430
return $next($request, $response, 405);
427431
}
428432
return $next($request, $response);

src/Exception/MissingDependencyException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* @see https://github.com/zendframework/zend-expressive for the canonical source repository
4-
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com)
4+
* @copyright Copyright (c) 2016-2017 Zend Technologies USA Inc. (http://www.zend.com)
55
* @license https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License
66
*/
77

test/RouteMiddlewareTest.php

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22
/**
3-
* Zend Framework (http://framework.zend.com/)
4-
*
53
* @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)
75
* @license https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License
86
*/
97

@@ -13,6 +11,7 @@
1311
use Prophecy\Argument;
1412
use Prophecy\Prophecy\ObjectProphecy;
1513
use Psr\Http\Message\ResponseInterface;
14+
use SplQueue;
1615
use Zend\Diactoros\Response;
1716
use Zend\Diactoros\ServerRequest;
1817
use Zend\Expressive\Application;
@@ -23,6 +22,10 @@
2322
use Zend\Expressive\Router\RouteResultObserverInterface;
2423
use Zend\Expressive\Router\RouterInterface;
2524
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;
2629

2730
class RouteMiddlewareTest extends TestCase
2831
{
@@ -68,6 +71,45 @@ public function testRoutingFailureDueToHttpMethodCallsNextWithNotAllowedResponse
6871
$this->assertContains('POST', $allow);
6972
}
7073

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+
71113
public function testGeneralRoutingFailureCallsNextWithSameRequestAndResponse()
72114
{
73115
$request = new ServerRequest();

test/WhoopsErrorHandlerTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22
/**
3-
* Zend Framework (http://framework.zend.com/)
4-
*
53
* @see http://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)
75
* @license https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License
86
*/
97

@@ -15,6 +13,7 @@
1513
use Psr\Http\Message\ResponseInterface;
1614
use Psr\Http\Message\ServerRequestInterface;
1715
use Psr\Http\Message\StreamInterface;
16+
use ReflectionClass;
1817
use Whoops\Handler\Handler;
1918
use Whoops\Handler\PrettyPageHandler;
2019
use Whoops\Run as Whoops;
@@ -29,7 +28,17 @@ class WhoopsErrorHandlerTest extends TestCase
2928
{
3029
public function getPrettyPageHandler()
3130
{
32-
return $this->prophesize(PrettyPageHandler::class);
31+
$handler = $this->prophesize(PrettyPageHandler::class);
32+
33+
// whoops 2.1.5 introduced a new method, which the runner calls when
34+
// invoked; as such, we need to test if this method is present and mock
35+
// a request to it if present.
36+
$r = new ReflectionClass(PrettyPageHandler::class);
37+
if ($r->hasMethod('contentType')) {
38+
$handler->contentType()->willReturn('text/html');
39+
}
40+
41+
return $handler;
3342
}
3443

3544
public function testInstantiationRequiresWhoopsAndPageHandler()

0 commit comments

Comments
 (0)