Passed
Pull Request — master (#9)
by Rafael
03:29
created

AssertJson::assertValueIsTrue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
crap 2
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Behat\Assert;
12
13
use PHPUnit\Framework\Assert;
14
use Symfony\Component\HttpFoundation\Response;
15
use Ynlo\GraphQLBundle\Util\Json;
16
17
/**
18
 * Set of asserts to check JSON values
19
 */
20
class AssertJson
21
{
22
    /**
23
     * @param string|array|Response $json
24
     * @param string                $type
25
     * @param string                $path
26
     */
27
    public static function assertValueInternalType($json, $type, $path)
28
    {
29
        Assert::assertInternalType($type, Json::getValue($json, $path));
30
    }
31
32
    /**
33
     * @param string|array|Response $json
34
     * @param string                $type
35
     * @param string                $path
36
     */
37
    public static function assertValueNotInternalType($json, $type, $path)
38
    {
39
        Assert::assertNotInternalType($type, Json::getValue($json, $path));
40
    }
41
42
    /**
43
     * @param string|array|Response $json
44
     * @param mixed                 $expected
45
     * @param string                $path
46
     */
47
    public static function assertValueEquals($json, $expected, $path)
48
    {
49
        Assert::assertEquals($expected, Json::getValue($json, $path));
50
    }
51
52
    /**
53
     * @param string|array|Response $json
54
     * @param string                $path
55
     */
56
    public static function assertValueIsFalse($json, $path)
57
    {
58
        Assert::assertFalse(Json::getValue($json, $path));
59
    }
60
61
    /**
62
     * @param string|array|Response $json
63
     * @param string                $path
64
     */
65
    public static function assertValueIsTrue($json, $path)
66
    {
67
        Assert::assertTrue(Json::getValue($json, $path));
68
    }
69
70
    /**
71
     * @param string|array|Response $json
72
     * @param mixed                 $expected
73
     * @param string                $path
74
     */
75
    public static function assertValueNotEquals($json, $expected, $path)
76
    {
77
        Assert::assertNotEquals($expected, Json::getValue($json, $path));
78
    }
79
80
    /**
81
     * @param string|array|Response $json
82
     * @param string                $path
83
     */
84
    public static function assertValueIsNull($json, $path)
85
    {
86
        Assert::assertNull(Json::getValue($json, $path));
87
    }
88
89
    /**
90
     * @param string|array|Response $json
91
     * @param mixed                 $expected
92
     * @param string                $path
93
     */
94
    public static function assertArraySubset($json, $expected, $path)
95
    {
96
        Assert::assertArraySubset($expected, Json::getValue($json, $path));
97
    }
98
99
    /**
100
     * @param string|array|Response $json
101
     * @param string                $format
102
     * @param string                $path
103
     */
104
    public static function assertValueMatchesFormat($json, $format, $path)
105
    {
106
        $value = Json::getValue($json, $path);
107
        Assert::assertStringMatchesFormat($format, $value);
108
    }
109
110
    /**
111
     * @param string|array|Response $json
112
     * @param string                $format
113
     * @param string                $path
114
     */
115
    public static function assertValueNotMatchesFormat($json, $format, $path)
116
    {
117
        $value = Json::getValue($json, $path);
118
        Assert::assertStringNotMatchesFormat($format, $value);
119
    }
120
121
    /**
122
     * @param string|array|Response $json
123
     * @param string                $pattern
124
     * @param string                $path
125
     */
126
    public static function assertValueRegExp($json, $pattern, $path)
127
    {
128
        $value = Json::getValue($json, $path);
129
        Assert::assertRegExp($pattern, $value);
130
    }
131
132
    /**
133
     * @param string|array|Response $json
134
     * @param string                $pattern
135
     * @param string                $path
136
     */
137
    public static function assertValueNotRegExp($json, $pattern, $path)
138
    {
139
        $value = Json::getValue($json, $path);
140
        Assert::assertNotRegExp($pattern, $value);
141
    }
142
}
143