forked from zendframework/zend-stratigility
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/psr-15-compat' into feature/http-interop-v2
Forward port updates from zendframework#75 Conflicts: src/Dispatch.php src/Route.php
- Loading branch information
Showing
7 changed files
with
126 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* @link http://github.com/zendframework/zend-stratigility for the canonical source repository | ||
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Stratigility\Middleware; | ||
|
||
use Interop\Http\Middleware\DelegateInterface; | ||
use PHPUnit_Framework_TestCase as TestCase; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Zend\Stratigility\Middleware\CallableInteropMiddlewareWrapper; | ||
|
||
class CallableInteropMiddlewareWrapperTest extends TestCase | ||
{ | ||
public function testWrapperDecoratesAndProxiesToCallableInteropMiddleware() | ||
{ | ||
$request = $this->prophesize(ServerRequestInterface::class)->reveal(); | ||
$delegate = $this->prophesize(DelegateInterface::class)->reveal(); | ||
$response = $this->prophesize(ResponseInterface::class)->reveal(); | ||
|
||
$decorator = new CallableInteropMiddlewareWrapper( | ||
function ($request, DelegateInterface $delegate) use ($response) { | ||
return $response; | ||
} | ||
); | ||
|
||
$this->assertSame($response, $decorator->process($request, $delegate)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
/** | ||
* @link http://github.com/zendframework/zend-stratigility for the canonical source repository | ||
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Stratigility\Middleware; | ||
|
||
use Closure; | ||
use Interop\Http\Middleware\DelegateInterface; | ||
use PHPUnit_Framework_TestCase as TestCase; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Zend\Stratigility\Middleware\CallableMiddlewareWrapper; | ||
use Zend\Stratigility\Next; | ||
|
||
class CallableMiddlewareWrapperTest extends TestCase | ||
{ | ||
public function testWrapperDecoratesAndProxiesToCallableMiddleware() | ||
{ | ||
$request = $this->prophesize(ServerRequestInterface::class)->reveal(); | ||
$delegate = $this->prophesize(DelegateInterface::class)->reveal(); | ||
$response = $this->prophesize(ResponseInterface::class)->reveal(); | ||
|
||
$decorator = new CallableMiddlewareWrapper( | ||
function ($request, $response, $delegate) { | ||
return $response; | ||
}, | ||
$response | ||
); | ||
|
||
$this->assertSame($response, $decorator->process($request, $delegate)); | ||
} | ||
|
||
public function testWrapperDoesNotDecorateNextInstancesWhenProxying() | ||
{ | ||
$request = $this->prophesize(ServerRequestInterface::class)->reveal(); | ||
$response = $this->prophesize(ResponseInterface::class)->reveal(); | ||
|
||
$delegate = $this->prophesize(Next::class)->reveal(); | ||
$decorator = new CallableMiddlewareWrapper( | ||
function ($request, $response, $next) use ($delegate) { | ||
$this->assertSame($delegate, $next); | ||
return $response; | ||
}, | ||
$response | ||
); | ||
|
||
$this->assertSame($response, $decorator->process($request, $delegate)); | ||
} | ||
|
||
public function testWrapperDecoratesDelegatesNotExtendingNext() | ||
{ | ||
$request = $this->prophesize(ServerRequestInterface::class)->reveal(); | ||
$response = $this->prophesize(ResponseInterface::class)->reveal(); | ||
|
||
$delegate = $this->prophesize(DelegateInterface::class)->reveal(); | ||
$decorator = new CallableMiddlewareWrapper( | ||
function ($request, $response, $next) use ($delegate) { | ||
$this->assertNotSame($delegate, $next); | ||
$this->assertInstanceOf(Closure::class, $next); | ||
return $response; | ||
}, | ||
$response | ||
); | ||
|
||
$this->assertSame($response, $decorator->process($request, $delegate)); | ||
} | ||
|
||
public function testDecoratedDelegateWillBeInvokedWithOnlyRequest() | ||
{ | ||
$request = $this->prophesize(ServerRequestInterface::class)->reveal(); | ||
$response = $this->prophesize(ResponseInterface::class)->reveal(); | ||
$expected = $this->prophesize(ResponseInterface::class)->reveal(); | ||
|
||
$delegate = $this->prophesize(DelegateInterface::class); | ||
$delegate->process($request)->willReturn($expected); | ||
|
||
$decorator = new CallableMiddlewareWrapper( | ||
function ($request, $response, $next) { | ||
return $next($request, $response); | ||
}, | ||
$response | ||
); | ||
|
||
$this->assertSame($expected, $decorator->process($request, $delegate->reveal())); | ||
} | ||
} |