File: JsonDecodingExceptionTest.php

package info (click to toggle)
php-json-schema 6.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,216 kB
  • sloc: php: 9,403; makefile: 153; python: 28; sh: 13
file content (89 lines) | stat: -rw-r--r-- 2,827 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php

namespace JsonSchema\Tests\Exception;

use JsonSchema\Exception\JsonDecodingException;
use PHPUnit\Framework\TestCase;

class JsonDecodingExceptionTest extends TestCase
{
    public function testHierarchy(): void
    {
        $exception = new JsonDecodingException();
        self::assertInstanceOf('\RuntimeException', $exception);
        self::assertInstanceOf('\JsonSchema\Exception\RuntimeException', $exception);
        self::assertInstanceOf('\JsonSchema\Exception\ExceptionInterface', $exception);
    }

    public function testDefaultMessage()
    {
        $exception = new JsonDecodingException();
        self::assertNotEmpty($exception->getMessage());
    }

    public function testErrorNoneMessage()
    {
        $exception = new JsonDecodingException(JSON_ERROR_NONE);
        self::assertNotEmpty($exception->getMessage());
    }

    public function testErrorDepthMessage()
    {
        $exception = new JsonDecodingException(JSON_ERROR_DEPTH);
        self::assertNotEmpty($exception->getMessage());
    }

    public function testErrorStateMismatchMessage()
    {
        $exception = new JsonDecodingException(JSON_ERROR_STATE_MISMATCH);
        self::assertNotEmpty($exception->getMessage());
    }

    public function testErrorControlCharacterMessage()
    {
        $exception = new JsonDecodingException(JSON_ERROR_CTRL_CHAR);
        self::assertNotEmpty($exception->getMessage());
    }

    public function testErrorUtf8Message()
    {
        $exception = new JsonDecodingException(JSON_ERROR_UTF8);
        self::assertNotEmpty($exception->getMessage());
    }

    public function testErrorSyntaxMessage()
    {
        $exception = new JsonDecodingException(JSON_ERROR_SYNTAX);
        self::assertNotEmpty($exception->getMessage());
    }

    public function testErrorInfiniteOrNotANumberMessage()
    {
        if (!defined('JSON_ERROR_INF_OR_NAN')) {
            self::markTestSkipped('JSON_ERROR_INF_OR_NAN is not defined until php55.');
        }

        $exception = new JsonDecodingException(JSON_ERROR_INF_OR_NAN);
        self::assertNotEmpty($exception->getMessage());
    }

    public function testErrorRecursionMessage()
    {
        if (!defined('JSON_ERROR_RECURSION')) {
            self::markTestSkipped('JSON_ERROR_RECURSION is not defined until php55.');
        }

        $exception = new JsonDecodingException(JSON_ERROR_RECURSION);
        self::assertNotEmpty($exception->getMessage());
    }

    public function testErrorUnsupportedTypeMessage()
    {
        if (!defined('JSON_ERROR_UNSUPPORTED_TYPE')) {
            self::markTestSkipped('JSON_ERROR_UNSUPPORTED_TYPE is not defined until php55.');
        }

        $exception = new JsonDecodingException(JSON_ERROR_UNSUPPORTED_TYPE);
        self::assertNotEmpty($exception->getMessage());
    }
}