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

Commit

Permalink
Merge branch 'hotfix/next-as-delegate-with-error'
Browse files Browse the repository at this point in the history
Close #85
  • Loading branch information
weierophinney committed Nov 11, 2016
2 parents 93e375e + 14079ea commit c410d36
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@ Versions prior to 1.0 were originally released as `phly/conduit`; please visit
its [CHANGELOG](https://github.com/phly/conduit/blob/master/CHANGELOG.md) for
details.

## 1.3.1 - 2016-11-10

### Added

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- [#85](https://github.com/zendframework/zend-stratigility/pull/85) fixes an
issue with how the `$done` or `$nextDelegate` is invoked by `Next` when an
error is present. Previously, the class was detecting a `Next` instance as an
http-interop `DelegateInterface` instance and dropping the error; this would
then mean if the instance contained error middleware, it would never be
dispatched.

## 1.3.0 - 2016-11-10

### Added
Expand Down
4 changes: 3 additions & 1 deletion src/Next.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,9 @@ private function dispatchNextDelegate(
ResponseInterface $response = null,
$err = null
) {
if ($nextDelegate instanceof DelegateInterface) {
if ($nextDelegate instanceof DelegateInterface
&& (! $nextDelegate instanceof Next || $err === null)
) {
return $nextDelegate->process($request);
}

Expand Down
21 changes: 21 additions & 0 deletions test/MiddlewarePipeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,27 @@ public function testWillDecorateCallableMiddlewareAsInteropMiddlewareIfResponseP
$this->assertAttributeSame($this->response, 'responsePrototype', $test);
}

/**
* @group http-interop
*/
public function testWillNotDecorateCallableMiddlewareAsInteropMiddlewareIfResponsePrototypeIsNotPresent()
{
$pipeline = new MiddlewarePipe();

$middleware = function () {
};
$pipeline->pipe($middleware);

$r = new ReflectionProperty($pipeline, 'pipeline');
$r->setAccessible(true);
$queue = $r->getValue($pipeline);

$route = $queue->dequeue();
$test = $route->handler;
$this->assertNotInstanceOf(CallableMiddlewareWrapper::class, $test);
$this->assertInternalType('callable', $test);
}

/**
* @todo Remove with 2.0.0
*/
Expand Down
35 changes: 35 additions & 0 deletions test/NextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -910,4 +910,39 @@ public function testEnablingRaiseThrowablesFlagWillCauseInvocationToRaiseMiddlew

$this->assertTrue($triggered, 'Deprecation notice not triggered');
}

/**
* @todo Remove for 2.0.0
* @group error-handling
*/
public function testNestedNextInvocationWithAnErrorShouldDispatchErrorMiddleware()
{
$internalQueue = clone $this->queue;
$internalQueue->enqueue(new Route('/', function ($request, $response, $next) {
return $next($request, $response, 'ERROR');
}));

$nextDelegateQueue = clone $this->queue;
$nextDelegateQueue->enqueue(new Route('/', function ($err, $request, $response, $next) {
$response->getBody()->write('ERROR DETECTED');
return $response->withStatus(599);
}));

$finalDelegate = $this->prophesize(DelegateInterface::class);
$finalDelegate->process(Argument::any())->shouldNotBeCalled();

$nextDelegate = new Next($nextDelegateQueue, $finalDelegate->reveal());
$internalNext = new Next($internalQueue, $nextDelegate);

set_error_handler(function ($errno, $errstr) {
return false !== strstr($errstr, 'error middleware is deprecated');
}, E_USER_DEPRECATED);

$response = $internalNext($this->request, $this->response);

restore_error_handler();

$this->assertEquals(599, $response->getStatusCode());
$this->assertEquals('ERROR DETECTED', (string) $response->getBody());
}
}

0 comments on commit c410d36

Please sign in to comment.