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

Commit ab064f2

Browse files
committed
Merge branch 'feature/stratigility-alpha4' into release-3.0.0
Close #568
2 parents 61ea007 + 5d7747b commit ab064f2

File tree

5 files changed

+79
-12
lines changed

5 files changed

+79
-12
lines changed

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,36 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5+
## 3.0.0alpha9 - TBD
6+
7+
### Added
8+
9+
- Nothing.
10+
11+
### Changed
12+
13+
- [#568](https://github.com/zendframework/zend-expressive/pull/568) updates the
14+
zendframework/zend-stratigility dependency to require at least 3.0.0alpha4.
15+
16+
- [#568](https://github.com/zendframework/zend-expressive/pull/568) updates the
17+
`ErrorHandlerFactory` to pull the `Psr\Http\Message\ResponseInterface`
18+
service, which returns a factory capable of returning a response instance,
19+
and passes it to the `Zend\Stratigility\Middleware\ErrorHandler` instance it
20+
creates, as that class changes in 3.0.0alpha4 such that it now expects a
21+
factory instead of an instance.
22+
23+
### Deprecated
24+
25+
- Nothing.
26+
27+
### Removed
28+
29+
- Nothing.
30+
31+
### Fixed
32+
33+
- Nothing.
34+
535
## 3.0.0alpha8 - 2018-02-21
636

737
### Added

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"zendframework/zend-expressive-router": "^3.0.0alpha3",
3232
"zendframework/zend-expressive-template": "^2.0.0alpha1",
3333
"zendframework/zend-httphandlerrunner": "^1.0.1",
34-
"zendframework/zend-stratigility": "3.0.0alpha3"
34+
"zendframework/zend-stratigility": "3.0.0alpha4"
3535
},
3636
"require-dev": {
3737
"filp/whoops": "^1.1.10 || ^2.1.13",

composer.lock

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

src/Container/ErrorHandlerFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Zend\Expressive\Container;
1111

1212
use Psr\Container\ContainerInterface;
13-
use Zend\Diactoros\Response;
13+
use Psr\Http\Message\ResponseInterface;
1414
use Zend\Expressive\Middleware\ErrorResponseGenerator;
1515
use Zend\Stratigility\Middleware\ErrorHandler;
1616

@@ -22,6 +22,6 @@ public function __invoke(ContainerInterface $container) : ErrorHandler
2222
? $container->get(ErrorResponseGenerator::class)
2323
: null;
2424

25-
return new ErrorHandler(new Response(), $generator);
25+
return new ErrorHandler($container->get(ResponseInterface::class), $generator);
2626
}
2727
}

test/Container/ErrorHandlerFactoryTest.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99

1010
namespace ZendTest\Expressive\Container;
1111

12+
use Closure;
1213
use PHPUnit\Framework\TestCase;
1314
use Prophecy\Prophecy\ObjectProphecy;
1415
use Psr\Container\ContainerInterface;
1516
use Psr\Http\Message\ResponseInterface;
17+
use RuntimeException;
18+
use TypeError;
1619
use Zend\Expressive\Container\ErrorHandlerFactory;
1720
use Zend\Expressive\Middleware\ErrorResponseGenerator;
1821
use Zend\Stratigility\Middleware\ErrorHandler;
@@ -28,15 +31,45 @@ public function setUp()
2831
$this->container = $this->prophesize(ContainerInterface::class);
2932
}
3033

34+
public function testFactoryFailsIfResponseServiceIsMissing()
35+
{
36+
$exception = new RuntimeException();
37+
$this->container->has(ErrorResponseGenerator::class)->willReturn(false);
38+
$this->container->get(ErrorResponseGenerator::class)->shouldNotBeCalled();
39+
$this->container->get(ResponseInterface::class)->willThrow($exception);
40+
41+
$factory = new ErrorHandlerFactory();
42+
43+
$this->expectException(RuntimeException::class);
44+
$factory($this->container->reveal());
45+
}
46+
47+
public function testFactoryFailsIfResponseServiceReturnsResponse()
48+
{
49+
$response = $this->prophesize(ResponseInterface::class)->reveal();
50+
$this->container->has(ErrorResponseGenerator::class)->willReturn(false);
51+
$this->container->get(ErrorResponseGenerator::class)->shouldNotBeCalled();
52+
$this->container->get(ResponseInterface::class)->willReturn($response);
53+
54+
$factory = new ErrorHandlerFactory();
55+
56+
$this->expectException(TypeError::class);
57+
$factory($this->container->reveal());
58+
}
59+
3160
public function testFactoryCreatesHandlerWithStratigilityGeneratorIfNoGeneratorServiceAvailable()
3261
{
3362
$this->container->has(ErrorResponseGenerator::class)->willReturn(false);
63+
$this->container->get(ErrorResponseGenerator::class)->shouldNotBeCalled();
64+
65+
$this->container->get(ResponseInterface::class)->willReturn(function () {
66+
});
3467

3568
$factory = new ErrorHandlerFactory();
3669
$handler = $factory($this->container->reveal());
3770

3871
$this->assertInstanceOf(ErrorHandler::class, $handler);
39-
$this->assertAttributeInstanceOf(ResponseInterface::class, 'responsePrototype', $handler);
72+
$this->assertAttributeInstanceOf(Closure::class, 'responseFactory', $handler);
4073
$this->assertAttributeInstanceOf(StratigilityGenerator::class, 'responseGenerator', $handler);
4174
}
4275

@@ -46,11 +79,14 @@ public function testFactoryCreatesHandlerWithGeneratorIfGeneratorServiceAvailabl
4679
$this->container->has(ErrorResponseGenerator::class)->willReturn(true);
4780
$this->container->get(ErrorResponseGenerator::class)->willReturn($generator);
4881

82+
$this->container->get(ResponseInterface::class)->willReturn(function () {
83+
});
84+
4985
$factory = new ErrorHandlerFactory();
5086
$handler = $factory($this->container->reveal());
5187

5288
$this->assertInstanceOf(ErrorHandler::class, $handler);
53-
$this->assertAttributeInstanceOf(ResponseInterface::class, 'responsePrototype', $handler);
89+
$this->assertAttributeInstanceOf(Closure::class, 'responseFactory', $handler);
5490
$this->assertAttributeSame($generator, 'responseGenerator', $handler);
5591
}
5692
}

0 commit comments

Comments
 (0)