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

Commit ae33892

Browse files
committed
Add test coverage for nested pipelines
1 parent 5abe027 commit ae33892

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

test/Application/MarshalMiddlewareTraitTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Prophecy\Prophecy\ObjectProphecy;
1414
use Psr\Container\ContainerInterface;
1515
use Psr\Http\Message\ResponseInterface;
16+
use Psr\Http\Message\ServerRequestInterface;
1617
use ReflectionMethod;
1718
use ReflectionProperty;
1819
use stdClass;
@@ -159,14 +160,15 @@ public function testPreparingCallableMiddlewareWithoutContainerReturnsDecoratedM
159160

160161
public function testPreparingArrayOfMiddlewareReturnsMiddlewarePipe()
161162
{
162-
$first = $this->prophesize(ServerMiddlewareInterface::class)->reveal();
163-
$second = function ($request, DelegateInterface $delegate) {
163+
$first = $this->prophesize(ServerMiddlewareInterface::class)->reveal();
164+
$second = function ($request, DelegateInterface $delegate) {
164165
};
165-
$third = function ($request, $response, callable $next) {
166+
$third = function ($request, $response, callable $next) {
166167
};
167-
$fourth = 'fourth';
168-
$fifth = TestAsset\CallableMiddleware::class;
169-
$sixth = TestAsset\CallableInteropMiddleware::class;
168+
$fourth = 'fourth';
169+
$fifth = TestAsset\CallableMiddleware::class;
170+
$sixth = TestAsset\CallableInteropMiddleware::class;
171+
$seventh = [$first, $second];
170172

171173
$this->container->has('fourth')->willReturn(true);
172174
$this->container->has(TestAsset\CallableMiddleware::class)->willReturn(false);
@@ -179,6 +181,7 @@ public function testPreparingArrayOfMiddlewareReturnsMiddlewarePipe()
179181
$fourth,
180182
$fifth,
181183
$sixth,
184+
$seventh,
182185
];
183186

184187
$middleware = $this->prepareMiddleware($base);
@@ -188,7 +191,7 @@ public function testPreparingArrayOfMiddlewareReturnsMiddlewarePipe()
188191
$r->setAccessible(true);
189192
$pipeline = $r->getValue($middleware);
190193

191-
$this->assertCount(6, $pipeline);
194+
$this->assertCount(7, $pipeline);
192195
}
193196

194197
public function testPreparingArrayOfMiddlewareWithoutContainerReturnsMiddlewarePipe()

test/ApplicationTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use ReflectionProperty;
2323
use RuntimeException;
2424
use UnexpectedValueException;
25+
use Zend\Diactoros\Response;
2526
use Zend\Diactoros\Response\EmitterInterface;
2627
use Zend\Diactoros\Response\SapiEmitter;
2728
use Zend\Diactoros\ServerRequest;
@@ -681,4 +682,42 @@ public function testWillUseConfiguredTemplateRendererWhenCreatingDelegateFromNot
681682
$this->assertAttributeNotSame($appResponsePrototype, 'responsePrototype', $delegate);
682683
$this->assertAttributeSame($renderer, 'renderer', $delegate);
683684
}
685+
686+
public function testAllowsNestedMiddlewarePipelines()
687+
{
688+
$app = $this->getApp();
689+
$counter = function (ServerRequestInterface $request, DelegateInterface $delegate) {
690+
$count = $request->getAttribute('count', 0);
691+
$request = $request->withAttribute('count', $count + 1);
692+
693+
return $delegate->process($request);
694+
};
695+
696+
$app->pipe([
697+
// First level
698+
$counter,
699+
[
700+
// Second level
701+
$counter,
702+
$counter
703+
],
704+
[
705+
[
706+
// Third level
707+
$counter,
708+
$counter
709+
]
710+
]
711+
]);
712+
713+
$request = new ServerRequest();
714+
$response = new Response();
715+
$delegate = $this->prophesize(DelegateInterface::class);
716+
717+
$delegate->process($request->withAttribute('count', 5))
718+
->shouldBeCalled()
719+
->willReturn($response);
720+
721+
$this->assertSame($response, $app->process($request, $delegate->reveal()));
722+
}
684723
}

0 commit comments

Comments
 (0)