Skip to content

Commit c269bda

Browse files
authored
Merge pull request #278 from abacaphiliac/exception-interface
Exception interface
2 parents 6b56652 + 1a5f339 commit c269bda

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 <[email protected]>
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+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace JsonSchema\Tests\Exception;
4+
5+
use JsonSchema\Exception\InvalidSchemaMediaTypeException;
6+
7+
class InvalidSchemaMediaTypeExceptionTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testHierarchy()
10+
{
11+
$exception = new InvalidSchemaMediaTypeException();
12+
self::assertInstanceOf('\RuntimeException', $exception);
13+
self::assertInstanceOf('\JsonSchema\Exception\RuntimeException', $exception);
14+
self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception);
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace JsonSchema\Tests\Exception;
4+
5+
use JsonSchema\Exception\InvalidSourceUriException;
6+
7+
class InvalidSourceUriExceptionTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testHierarchy()
10+
{
11+
$exception = new InvalidSourceUriException();
12+
self::assertInstanceOf('\InvalidArgumentException', $exception);
13+
self::assertInstanceOf('\JsonSchema\Exception\InvalidArgumentException', $exception);
14+
self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception);
15+
}
16+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace JsonSchema\Tests\Exception;
4+
5+
use JsonSchema\Exception\JsonDecodingException;
6+
7+
class JsonDecodingExceptionTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testHierarchy()
10+
{
11+
$exception = new JsonDecodingException();
12+
self::assertInstanceOf('\RuntimeException', $exception);
13+
self::assertInstanceOf('\JsonSchema\Exception\RuntimeException', $exception);
14+
self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception);
15+
}
16+
17+
public function testDefaultMessage()
18+
{
19+
$exception = new JsonDecodingException();
20+
self::assertNotEmpty($exception->getMessage());
21+
}
22+
23+
public function testErrorNoneMessage()
24+
{
25+
$exception = new JsonDecodingException(JSON_ERROR_NONE);
26+
self::assertNotEmpty($exception->getMessage());
27+
}
28+
29+
public function testErrorDepthMessage()
30+
{
31+
$exception = new JsonDecodingException(JSON_ERROR_DEPTH);
32+
self::assertNotEmpty($exception->getMessage());
33+
}
34+
35+
public function testErrorStateMismatchMessage()
36+
{
37+
$exception = new JsonDecodingException(JSON_ERROR_STATE_MISMATCH);
38+
self::assertNotEmpty($exception->getMessage());
39+
}
40+
41+
public function testErrorControlCharacterMessage()
42+
{
43+
$exception = new JsonDecodingException(JSON_ERROR_CTRL_CHAR);
44+
self::assertNotEmpty($exception->getMessage());
45+
}
46+
47+
public function testErrorUtf8Message()
48+
{
49+
$exception = new JsonDecodingException(JSON_ERROR_UTF8);
50+
self::assertNotEmpty($exception->getMessage());
51+
}
52+
53+
public function testErrorSyntaxMessage()
54+
{
55+
$exception = new JsonDecodingException(JSON_ERROR_SYNTAX);
56+
self::assertNotEmpty($exception->getMessage());
57+
}
58+
59+
public function testErrorInfiniteOrNotANumberMessage()
60+
{
61+
if (!defined('JSON_ERROR_INF_OR_NAN')) {
62+
self::markTestSkipped('JSON_ERROR_INF_OR_NAN is not defined until php55.');
63+
}
64+
65+
$exception = new JsonDecodingException(JSON_ERROR_INF_OR_NAN);
66+
self::assertNotEmpty($exception->getMessage());
67+
}
68+
69+
public function testErrorRecursionMessage()
70+
{
71+
if (!defined('JSON_ERROR_RECURSION')) {
72+
self::markTestSkipped('JSON_ERROR_RECURSION is not defined until php55.');
73+
}
74+
75+
$exception = new JsonDecodingException(JSON_ERROR_RECURSION);
76+
self::assertNotEmpty($exception->getMessage());
77+
}
78+
79+
public function testErrorUnsupportedTypeMessage()
80+
{
81+
if (!defined('JSON_ERROR_UNSUPPORTED_TYPE')) {
82+
self::markTestSkipped('JSON_ERROR_UNSUPPORTED_TYPE is not defined until php55.');
83+
}
84+
85+
$exception = new JsonDecodingException(JSON_ERROR_UNSUPPORTED_TYPE);
86+
self::assertNotEmpty($exception->getMessage());
87+
}
88+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace JsonSchema\Tests\Exception;
4+
5+
use JsonSchema\Exception\ResourceNotFoundException;
6+
7+
class ResourceNotFoundExceptionTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testHierarchy()
10+
{
11+
$exception = new ResourceNotFoundException();
12+
self::assertInstanceOf('\RuntimeException', $exception);
13+
self::assertInstanceOf('\JsonSchema\Exception\RuntimeException', $exception);
14+
self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception);
15+
}
16+
}
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\RuntimeException;
6+
7+
class RuntimeExceptionTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testHierarchy()
10+
{
11+
$exception = new RuntimeException();
12+
self::assertInstanceOf('\RuntimeException', $exception);
13+
self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception);
14+
}
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace JsonSchema\Tests\Exception;
4+
5+
use JsonSchema\Exception\UnresolvableJsonPointerException;
6+
7+
class UnresolvableJsonPointerExceptionTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testHierarchy()
10+
{
11+
$exception = new UnresolvableJsonPointerException();
12+
self::assertInstanceOf('\InvalidArgumentException', $exception);
13+
self::assertInstanceOf('\JsonSchema\Exception\InvalidArgumentException', $exception);
14+
self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception);
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace JsonSchema\Tests\Exception;
4+
5+
use JsonSchema\Exception\UriResolverException;
6+
7+
class UriResolverExceptionTest extends \PHPUnit_Framework_TestCase
8+
{
9+
public function testHierarchy()
10+
{
11+
$exception = new UriResolverException();
12+
self::assertInstanceOf('\RuntimeException', $exception);
13+
self::assertInstanceOf('\JsonSchema\Exception\RuntimeException', $exception);
14+
self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception);
15+
}
16+
}

0 commit comments

Comments
 (0)