Completed
Push — master ( 533532...ee214c )
by Rafael
04:23
created

JsonAssertTrait::assertJsonPathNotEquals()   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 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 3
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\Test\Assert;
12
13
use Symfony\Component\HttpFoundation\Response;
14
15
/**
16
 * @method Response getResponse()
17
 *
18
 * @requires JsonHelperTrait
19
 */
20
trait JsonAssertTrait
21
{
22
    /**
23
     * @param string|array $json
24
     * @param string       $type
25
     * @param string       $path
26
     */
27
    public static function assertJsonPathInternalType($json, $type, $path)
28
    {
29
        static::assertInternalType($type, static::getJsonPathValue($json, $path));
30
    }
31
32
    /**
33
     * @param string|array $json
34
     * @param string       $type
35
     * @param string       $path
36
     */
37
    public static function assertJsonPathNotInternalType($json, $type, $path)
38
    {
39
        static::assertNotInternalType($type, static::getJsonPathValue($json, $path));
40
    }
41
42
    /**
43
     * @param string|array $json
44
     * @param mixed        $expected
45
     * @param string       $path
46
     */
47
    public static function assertJsonPathEquals($json, $expected, $path)
48
    {
49
        static::assertEquals($expected, static::getJsonPathValue($json, $path));
50
    }
51
52
    /**
53
     * @param string|array $json
54
     * @param string       $path
55
     */
56
    public static function assertJsonPathFalse($json, $path)
57
    {
58
        static::assertFalse(static::getJsonPathValue($json, $path));
59
    }
60
61
    /**
62
     * @param string|array $json
63
     * @param string       $path
64
     */
65
    public static function assertJsonPathTrue($json, $path)
66
    {
67
        static::assertTrue(static::getJsonPathValue($json, $path));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not exist on Ynlo\GraphQLBundle\Test\Assert\JsonAssertTrait. Did you maybe mean assertJsonPathTrue()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
        static::/** @scrutinizer ignore-call */ 
68
                assertTrue(static::getJsonPathValue($json, $path));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
    }
69
70
    /**
71
     * @param string|array $json
72
     * @param mixed        $expected
73
     * @param string       $path
74
     */
75
    public static function assertJsonPathNotEquals($json, $expected, $path)
76
    {
77
        static::assertNotEquals($expected, static::getJsonPathValue($json, $path));
78
    }
79
80
    /**
81
     * @param string|array $json
82
     * @param string       $path
83
     */
84
    public static function assertJsonPathNull($json, $path)
85
    {
86
        static::assertNull(static::getJsonPathValue($json, $path));
0 ignored issues
show
Bug introduced by
The method assertNull() does not exist on Ynlo\GraphQLBundle\Test\Assert\JsonAssertTrait. Did you maybe mean assertJsonPathNull()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
        static::/** @scrutinizer ignore-call */ 
87
                assertNull(static::getJsonPathValue($json, $path));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87
    }
88
89
    /**
90
     * @param string|array $json
91
     * @param mixed        $expected
92
     * @param string       $path
93
     */
94
    public static function assertJsonArraySubset($json, $expected, $path)
95
    {
96
        static::assertArraySubset($expected, static::getJsonPathValue($json, $path));
97
    }
98
99
    /**
100
     * @param string|array $json
101
     * @param string       $path
102
     */
103
    public static function assertJsonPathMatch($json, $path)
104
    {
105
        $value = static::getJsonPathValue($json, $path);
106
        if (\is_array($value)) {
107
            static::assertNotEmpty($value);
108
        } else {
109
            static::assertNotNull($value);
110
        }
111
    }
112
113
    /**
114
     * @param string|array $json
115
     * @param string       $path
116
     */
117
    public static function assertJsonPathNotMatch($json, $path)
118
    {
119
        $value = static::getJsonPathValue($json, $path);
120
        if (\is_array($value)) {
121
            static::assertEmpty($value);
122
        } else {
123
            static::assertNull($value);
124
        }
125
    }
126
}
127