This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
Added MiddlewarePipeInterface as abstraction layer for MiddlewarePipe #146
Merged
weierophinney
merged 6 commits into
zendframework:release-3.0.0
from
michalbundyra:middleware-pipe-interface
Jan 24, 2018
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9dde7ec
Added MiddlewarePipeInterface as abstraction layer for MiddlewarePipe
michalbundyra 9481159
Added test for MiddlewarePipe
michalbundyra 97cf47a
Updated test - check if MiddlewarePipe is final
michalbundyra d5de60a
Import ReflectionMethod
michalbundyra 7e9266a
Updated test name
michalbundyra c16cb6e
Added notes in migration to v3 docs about MiddlewarePipeInterface
michalbundyra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/** | ||
* @see https://github.com/zendframework/zend-stratigility for the canonical source repository | ||
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com) | ||
* @license https://github.com/zendframework/zend-stratigility/blob/master/LICENSE.md New BSD License | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Zend\Stratigility; | ||
|
||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
|
||
interface MiddlewarePipeInterface extends MiddlewareInterface, RequestHandlerInterface | ||
{ | ||
public function pipe(MiddlewareInterface $middleware) : void; | ||
} |
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 |
---|---|---|
|
@@ -14,10 +14,13 @@ | |
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use ReflectionClass; | ||
use ReflectionObject; | ||
use Zend\Diactoros\Response; | ||
use Zend\Diactoros\ServerRequest as Request; | ||
use Zend\Stratigility\Exception; | ||
use Zend\Stratigility\MiddlewarePipe; | ||
use Zend\Stratigility\MiddlewarePipeInterface; | ||
|
||
class MiddlewarePipeTest extends TestCase | ||
{ | ||
|
@@ -179,4 +182,31 @@ public function testHandleProcessesEnqueuedMiddleware() | |
|
||
$this->assertSame($response, $pipeline->handle($this->request)); | ||
} | ||
|
||
public function testMiddlewarePipeIsInstanceOfMiddlewarePipeInterface() | ||
{ | ||
$pipeline = new MiddlewarePipe(); | ||
|
||
$r = new ReflectionObject($pipeline); | ||
$methods = $r->getMethods(\ReflectionMethod::IS_PUBLIC); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Import |
||
$actual = []; | ||
foreach ($methods as $method) { | ||
if (strpos($method->getName(), '__') !== 0) { | ||
$actual[] = $method->getName(); | ||
} | ||
} | ||
sort($actual); | ||
|
||
$interfaceReflection = new ReflectionClass(MiddlewarePipeInterface::class); | ||
$interfaceMethods = $interfaceReflection->getMethods(\ReflectionMethod::IS_PUBLIC); | ||
$expected = []; | ||
foreach ($interfaceMethods as $method) { | ||
$expected[] = $method->getName(); | ||
} | ||
sort($expected); | ||
|
||
self::assertTrue($r->isFinal()); | ||
self::assertEquals($expected, $actual); | ||
self::assertInstanceOf(MiddlewarePipeInterface::class, $pipeline); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rename this to
testMiddlewarePipeOnlyImplementsMiddlewarePipeInterfaceApi()
, as that's what it's really doing.Honestly, I'm not 100% certain we need this to be as thorough as it is; checking that
MiddlewarePipe instanceof MiddlewarePipeInterface
is likely enough for our purposes. There may be reasons to add additional public methods down the line, primarily to provide optional collaborators, that would invalidate this test otherwise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weierophinney
And this was the reason why I've created that test as thorough as it is. I think any public method added into that class, should be also defined in the abstraction later. This is the whole point of that PR.
If test fails, it will show us that something is changed, and we will have chance to think again if it's really needed there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm convinced. Thanks for the feedback!