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

Commit 1ed59a6

Browse files
committed
Updates zend-httphandlerrunner dependency to 1.0.1
That particular release decorates the various factories in closures in order to provide type-safety - which means we cannot assume that the properties are the same instances as we provide to the constructor. This patch updates the tests to take that into account.
1 parent c6caeeb commit 1ed59a6

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"zendframework/zend-diactoros": "^1.3.10",
3131
"zendframework/zend-expressive-router": "^3.0.0alpha3",
3232
"zendframework/zend-expressive-template": "^2.0.0alpha1",
33-
"zendframework/zend-httphandlerrunner": "^1.0",
33+
"zendframework/zend-httphandlerrunner": "^1.0.1",
3434
"zendframework/zend-stratigility": "3.0.0alpha3"
3535
},
3636
"require-dev": {

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/Container/RequestHandlerRunnerFactoryTest.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111

1212
use PHPUnit\Framework\TestCase;
1313
use Psr\Container\ContainerInterface;
14+
use Psr\Http\Message\ResponseInterface;
1415
use Psr\Http\Message\ServerRequestInterface;
1516
use Psr\Http\Server\RequestHandlerInterface;
17+
use ReflectionProperty;
18+
use RuntimeException;
19+
use Throwable;
1620
use Zend\Expressive\ApplicationPipeline;
1721
use Zend\Expressive\Container\RequestHandlerRunnerFactory;
1822
use Zend\Expressive\ServerRequestErrorResponseGenerator;
@@ -27,7 +31,7 @@ public function testFactoryProducesRunnerUsingServicesFromContainer()
2731
$handler = $this->registerHandlerInContainer($container);
2832
$emitter = $this->registerEmitterInContainer($container);
2933
$serverRequestFactory = $this->registerServerRequestFactoryInContainer($container);
30-
$errorGenerator = $this->registerServerRequestErroResponseGeneratorInContainer($container);
34+
$errorGenerator = $this->registerServerRequestErrorResponseGeneratorInContainer($container);
3135

3236
$factory = new RequestHandlerRunnerFactory();
3337

@@ -36,8 +40,20 @@ public function testFactoryProducesRunnerUsingServicesFromContainer()
3640
$this->assertInstanceOf(RequestHandlerRunner::class, $runner);
3741
$this->assertAttributeSame($handler, 'handler', $runner);
3842
$this->assertAttributeSame($emitter, 'emitter', $runner);
39-
$this->assertAttributeSame($serverRequestFactory, 'serverRequestFactory', $runner);
40-
$this->assertAttributeSame($errorGenerator, 'serverRequestErrorResponseGenerator', $runner);
43+
44+
$this->assertAttributeNotSame($serverRequestFactory, 'serverRequestFactory', $runner);
45+
$this->assertAttributeNotSame($errorGenerator, 'serverRequestErrorResponseGenerator', $runner);
46+
47+
$r = new ReflectionProperty($runner, 'serverRequestFactory');
48+
$r->setAccessible(true);
49+
$toTest = $r->getValue($runner);
50+
$this->assertSame($serverRequestFactory(), $toTest());
51+
52+
$r = new ReflectionProperty($runner, 'serverRequestErrorResponseGenerator');
53+
$r->setAccessible(true);
54+
$toTest = $r->getValue($runner);
55+
$e = new RuntimeException();
56+
$this->assertSame($errorGenerator($e), $toTest($e));
4157
}
4258

4359
public function registerHandlerInContainer($container) : RequestHandlerInterface
@@ -56,15 +72,19 @@ public function registerEmitterInContainer($container) : EmitterInterface
5672

5773
public function registerServerRequestFactoryInContainer($container) : callable
5874
{
59-
$factory = function () {
75+
$request = $this->prophesize(ServerRequestInterface::class)->reveal();
76+
$factory = function () use ($request) {
77+
return $request;
6078
};
6179
$container->get(ServerRequestInterface::class)->willReturn($factory);
6280
return $factory;
6381
}
6482

65-
public function registerServerRequestErroResponseGeneratorInContainer($container) : callable
83+
public function registerServerRequestErrorResponseGeneratorInContainer($container) : callable
6684
{
67-
$generator = function ($e) {
85+
$response = $this->prophesize(ResponseInterface::class)->reveal();
86+
$generator = function (Throwable $e) use ($response) {
87+
return $response;
6888
};
6989
$container->get(ServerRequestErrorResponseGenerator::class)->willReturn($generator);
7090
return $generator;

0 commit comments

Comments
 (0)