Skip to content

Commit 1a5f339

Browse files
committed
add tests to validate existing exception hierarchy, in preparation for adjustment. add \RuntimeException wrapper. update all extensions of \RuntimeException to extend the wrapper. spl-exception wrappers now implement a common exception interface for this package. this allows consumers to handle all custom exception types thrown by catching the common interface rather than by catching each specific extension or their spl parents.
1 parent 8490e82 commit 1a5f339

17 files changed

+230
-6
lines changed

src/JsonSchema/Constraints/ConstraintInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function isValid();
5555
* @param mixed $schema
5656
* @param mixed $path
5757
* @param mixed $i
58+
* @throws \JsonSchema\Exception\ExceptionInterface
5859
*/
5960
public function check($value, $schema = null, $path = null, $i = null);
6061
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace JsonSchema\Exception;
4+
5+
interface ExceptionInterface
6+
{
7+
8+
}

src/JsonSchema/Exception/InvalidArgumentException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
/**
1313
* Wrapper for the InvalidArgumentException
1414
*/
15-
class InvalidArgumentException extends \InvalidArgumentException
15+
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
1616
{
1717
}

src/JsonSchema/Exception/InvalidSchemaMediaTypeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
/**
1313
* Wrapper for the InvalidSchemaMediaType
1414
*/
15-
class InvalidSchemaMediaTypeException extends \RuntimeException
15+
class InvalidSchemaMediaTypeException extends RuntimeException
1616
{
1717
}

src/JsonSchema/Exception/JsonDecodingException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/**
1313
* Wrapper for the JsonDecodingException
1414
*/
15-
class JsonDecodingException extends \RuntimeException
15+
class JsonDecodingException extends RuntimeException
1616
{
1717
public function __construct($code = JSON_ERROR_NONE, \Exception $previous = null)
1818
{

src/JsonSchema/Exception/ResourceNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
/**
1313
* Wrapper for the ResourceNotFoundException
1414
*/
15-
class ResourceNotFoundException extends \RuntimeException
15+
class ResourceNotFoundException extends RuntimeException
1616
{
1717
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the JsonSchema package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace JsonSchema\Exception;
11+
12+
/**
13+
* Wrapper for the RuntimeException
14+
*/
15+
class RuntimeException extends \RuntimeException implements ExceptionInterface
16+
{
17+
}

src/JsonSchema/Exception/UnresolvableJsonPointerException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
* @package JsonSchema\Exception
1414
* @author Joost Nijhuis <jnijhuis81@gmail.com>
1515
*/
16-
class UnresolvableJsonPointerException extends \InvalidArgumentException
16+
class UnresolvableJsonPointerException extends InvalidArgumentException
1717
{
1818
}

src/JsonSchema/Exception/UriResolverException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
/**
1313
* Wrapper for the UriResolverException
1414
*/
15-
class UriResolverException extends \RuntimeException
15+
class UriResolverException extends RuntimeException
1616
{
1717
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace JsonSchema\Tests\Exception;
4+
5+
use JsonSchema\Exception\InvalidArgumentException;
6+
7+
class InvalidArgumentExceptionTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testHierarchy()
10+
{
11+
$exception = new InvalidArgumentException();
12+
self::assertInstanceOf('\InvalidArgumentException', $exception);
13+
self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception);
14+
}
15+
}

0 commit comments

Comments
 (0)