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

Commit fc16e29

Browse files
committed
Merge branch 'hotfix/574-psr-11-exceptions' into release-3.0.0
Close #574 Fixes #573
2 parents b381f53 + a257ab1 commit fc16e29

File tree

5 files changed

+94
-4
lines changed

5 files changed

+94
-4
lines changed

CHANGELOG.md

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

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

5+
## 3.0.0rc1 - TBD
6+
7+
### Added
8+
9+
- Nothing.
10+
11+
### Changed
12+
13+
- Nothing.
14+
15+
### Deprecated
16+
17+
- Nothing.
18+
19+
### Removed
20+
21+
- Nothing.
22+
23+
### Fixed
24+
25+
- [#574](https://github.com/zendframework/zend-expressive/pull/574) updates the
26+
classes `Zend\Expressive\Exception\InvalidMiddlewareException` and
27+
`MissingDependencyException` to implement the
28+
[PSR-11](https://www.php-fig.org/psr/psr-11/) `ContainerExceptionInterface`.
29+
530
## 3.0.0alpha9 - 2018-02-22
631

732
### Added

src/Exception/InvalidMiddlewareException.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99

1010
namespace Zend\Expressive\Exception;
1111

12+
use Psr\Container\ContainerExceptionInterface;
1213
use Psr\Http\Server\MiddlewareInterface;
1314
use Psr\Http\Server\RequestHandlerInterface;
1415
use RuntimeException;
1516

16-
class InvalidMiddlewareException extends RuntimeException implements ExceptionInterface
17+
class InvalidMiddlewareException extends RuntimeException implements
18+
ContainerExceptionInterface,
19+
ExceptionInterface
1720
{
1821
/**
1922
* @param mixed $middleware The middleware that does not fulfill the

src/Exception/MissingDependencyException.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99

1010
namespace Zend\Expressive\Exception;
1111

12+
use Psr\Container\ContainerExceptionInterface;
1213
use RuntimeException;
1314

14-
class MissingDependencyException extends RuntimeException implements ExceptionInterface
15+
class MissingDependencyException extends RuntimeException implements
16+
ContainerExceptionInterface,
17+
ExceptionInterface
1518
{
1619
public static function forMiddlewareService(string $service) : self
1720
{

src/MiddlewareContainer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public function __construct(ContainerInterface $container)
2929
/**
3030
* Returns true if the service is in the container, or resolves to an
3131
* autoloadable class name.
32-
* {@inheritDocs}
32+
*
33+
* @param string $service
3334
*/
3435
public function has($service) : bool
3536
{
@@ -43,9 +44,12 @@ public function has($service) : bool
4344
/**
4445
* Returns middleware pulled from container, or directly instantiated if
4546
* not managed by the container.
46-
* {@inheritDocs}
47+
*
48+
* @param string $service
4749
* @throws Exception\MissingDependencyException if the service does not
4850
* exist, or is not a valid class name.
51+
* @throws Exception\InvalidMiddlewareException if the service is not
52+
* an instance of MiddlewareInterface.
4953
*/
5054
public function get($service) : MiddlewareInterface
5155
{

test/ExceptionTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-expressive for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace ZendTest\Expressive;
11+
12+
use Generator;
13+
use PHPUnit\Framework\TestCase;
14+
use Psr\Container\ContainerExceptionInterface;
15+
use Zend\Expressive\Exception\ExceptionInterface;
16+
use Zend\Expressive\Exception\InvalidMiddlewareException;
17+
use Zend\Expressive\Exception\MissingDependencyException;
18+
19+
class ExceptionTest extends TestCase
20+
{
21+
public function exception() : Generator
22+
{
23+
$namespace = substr(ExceptionInterface::class, 0, strrpos(ExceptionInterface::class, '\\') + 1);
24+
25+
$exceptions = glob(__DIR__ . '/../src/Exception/*.php');
26+
foreach ($exceptions as $exception) {
27+
$class = substr(basename($exception), 0, -4);
28+
29+
yield $class => [$namespace . $class];
30+
}
31+
}
32+
33+
/**
34+
* @dataProvider exception
35+
*/
36+
public function testExceptionIsInstanceOfExceptionInterface(string $exception) : void
37+
{
38+
$this->assertContains('Exception', $exception);
39+
$this->assertTrue(is_a($exception, ExceptionInterface::class, true));
40+
}
41+
42+
public function containerException() : Generator
43+
{
44+
yield InvalidMiddlewareException::class => [InvalidMiddlewareException::class];
45+
yield MissingDependencyException::class => [MissingDependencyException::class];
46+
}
47+
48+
/**
49+
* @dataProvider containerException
50+
*/
51+
public function testExceptionIsInstanceOfContainerExceptionInterface(string $exception) : void
52+
{
53+
$this->assertTrue(is_a($exception, ContainerExceptionInterface::class, true));
54+
}
55+
}

0 commit comments

Comments
 (0)