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

Commit

Permalink
Added ExceptionInterface as marker for package-specific exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
michalbundyra committed Dec 5, 2017
1 parent ea9ea58 commit 5a05b4c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/book/migration.md
Expand Up @@ -81,6 +81,9 @@ If you wish to use those types, you will need to decorate them in a
only operate on the response returned by `$next`, or produce a concrete
response yourself.

- `Zend\Stratigility\Exception\ExceptionInterface` - marker for
package-specific exceptions.

### Removed classes and exceptions

The following classes have been removed:
Expand Down
15 changes: 15 additions & 0 deletions src/Exception/ExceptionInterface.php
@@ -0,0 +1,15 @@
<?php
/**
* @see https://github.com/zendframework/zend-stratigility for the canonical source repository
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-stratigility/blob/master/LICENSE.md New BSD License
*/

namespace Zend\Stratigility\Exception;

/**
* Marker interface for package-specific exceptions.
*/
interface ExceptionInterface
{
}
2 changes: 1 addition & 1 deletion src/Exception/InvalidMiddlewareException.php
Expand Up @@ -10,7 +10,7 @@
use Interop\Http\Server\MiddlewareInterface;
use InvalidArgumentException;

class InvalidMiddlewareException extends InvalidArgumentException
class InvalidMiddlewareException extends InvalidArgumentException implements ExceptionInterface
{
/**
* Create and return an InvalidArgumentException detailing the invalid middleware type.
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/MissingResponseException.php
Expand Up @@ -13,7 +13,7 @@
* Exception thrown when the internal stack of Zend\Stratigility\Next is
* exhausted, but no response returned.
*/
class MissingResponseException extends OutOfBoundsException
class MissingResponseException extends OutOfBoundsException implements ExceptionInterface
{
public static function forCallableMiddleware(callable $middleware) : self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/MissingResponsePrototypeException.php
Expand Up @@ -14,7 +14,7 @@
* Exception thrown by the DoublePassMiddlewareWrapper when no response
* prototype is provided, and Diactoros is not available to create a default.
*/
class MissingResponsePrototypeException extends UnexpectedValueException
class MissingResponsePrototypeException extends UnexpectedValueException implements ExceptionInterface
{
public static function create() : self
{
Expand Down
36 changes: 36 additions & 0 deletions test/Exception/ExceptionTest.php
@@ -0,0 +1,36 @@
<?php
/**
* @see https://github.com/zendframework/zend-stratigility for the canonical source repository
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-stratigility/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\Stratigility\Exception;

use Generator;
use PHPUnit\Framework\TestCase;
use Zend\Stratigility\Exception\ExceptionInterface;

class ExceptionTest extends TestCase
{
public function exception() : Generator
{
$namespace = substr(ExceptionInterface::class, 0, strrpos(ExceptionInterface::class, '\\') + 1);

$exceptions = glob(__DIR__ . '/../../src/Exception/*.php');
foreach ($exceptions as $exception) {
$class = substr(basename($exception), 0, -4);

yield $class => [$namespace . $class];
}
}

/**
* @dataProvider exception
*/
public function testExceptionIsInstanceOfExceptionInterface(string $exception) : void
{
self::assertContains('Exception', $exception);
self::assertTrue(is_a($exception, ExceptionInterface::class, true));
}
}

0 comments on commit 5a05b4c

Please sign in to comment.