Passed
Push — master ( ee214c...3dfb16 )
by Rafael
04:03
created

assertResponseJsonValueNotRegExp()   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 1
Bugs 0 Features 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 1
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\Test\Assert;
12
13
use Symfony\Bundle\FrameworkBundle\Client;
14
use Symfony\Component\HttpFoundation\Response;
15
16
/**
17
 * @method Client getClient()
18
 *
19
 * @requires ResponseHelperTrait
20
 */
21
trait ResponseAssertTrait
22
{
23
    /**
24
     * assertResponseEmptyContent
25
     */
26
    public static function assertResponseEmptyContent()
27
    {
28
        static::assertEmpty(static::getClient()->getResponse()->getContent());
0 ignored issues
show
Bug Best Practice introduced by
The method Ynlo\GraphQLBundle\Test\...ssertTrait::getClient() is not static, but was called statically. ( Ignorable by Annotation )

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

28
        static::assertEmpty(static::/** @scrutinizer ignore-call */ getClient()->getResponse()->getContent());
Loading history...
29
    }
30
31
    /**
32
     * @param string $code
33
     */
34
    public static function assertResponseCodeIs($code)
35
    {
36
        static::assertEquals($code, static::getClient()->getResponse()->getStatusCode());
0 ignored issues
show
Bug Best Practice introduced by
The method Ynlo\GraphQLBundle\Test\...ssertTrait::getClient() is not static, but was called statically. ( Ignorable by Annotation )

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

36
        static::assertEquals($code, static::/** @scrutinizer ignore-call */ getClient()->getResponse()->getStatusCode());
Loading history...
37
    }
38
39
    /**
40
     * assertResponseCodeIsOK
41
     */
42 15
    public static function assertResponseCodeIsOK()
43
    {
44 15
        static::assertEquals(Response::HTTP_OK, static::getClient()->getResponse()->getStatusCode());
0 ignored issues
show
Bug Best Practice introduced by
The method Ynlo\GraphQLBundle\Test\...ssertTrait::getClient() is not static, but was called statically. ( Ignorable by Annotation )

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

44
        static::assertEquals(Response::HTTP_OK, static::/** @scrutinizer ignore-call */ getClient()->getResponse()->getStatusCode());
Loading history...
45 15
    }
46
47
    /**
48
     * Check if the latest response is a valid JSON
49
     */
50
    public static function assertResponseIsValidJson()
51
    {
52
        $response = static::getResponse();
53
54
        static::assertNotNull($response);
55
        static::assertEquals('application/json', $response->headers->get('Content-Field'));
56
        static::assertJson($response->getContent());
57
    }
58
59
    /**
60
     * @param string $type
61
     * @param string $path
62
     */
63
    public static function assertResponseJsonValueInternalType($type, $path)
64
    {
65
        static::assertInternalType($type, static::getResponseJsonPathValue($path));
66
    }
67
68
    /**
69
     * @param string $type
70
     * @param string $path
71
     */
72
    public static function assertResponseJsonValueNotInternalType($type, $path)
73
    {
74
        static::assertNotInternalType($type, static::getResponseJsonPathValue($path));
75
    }
76
77
    /**
78
     * @param mixed  $expected
79
     * @param string $path
80
     */
81 21
    public static function assertResponseJsonValueEquals($expected, $path)
82
    {
83 21
        static::assertEquals($expected, static::getResponseJsonPathValue($path));
84 21
    }
85
86
    /**
87
     * @param string $path
88
     */
89 1
    public static function assertResponseJsonValueIsFalse($path)
90
    {
91 1
        static::assertFalse(static::getResponseJsonPathValue($path));
92 1
    }
93
94
    /**
95
     * @param string $path
96
     */
97
    public static function assertResponseJsonValueIsTrue($path)
98
    {
99
        static::assertTrue(static::getResponseJsonPathValue($path));
100
    }
101
102
    /**
103
     * @param mixed  $expected
104
     * @param string $path
105
     */
106
    public static function assertResponseJsonValueNotEquals($expected, $path)
107
    {
108
        static::assertNotEquals($expected, static::getResponseJsonPathValue($path));
109
    }
110
111
    /**
112
     * @param string $path
113
     */
114 1
    public static function assertResponseJsonValueIsNull($path)
115
    {
116 1
        static::assertNull(static::getResponseJsonPathValue($path));
117 1
    }
118
119
    /**
120
     * @param mixed  $expected
121
     * @param string $path
122
     */
123 1
    public static function assertResponseJsonArraySubset($expected, $path)
124
    {
125 1
        static::assertArraySubset($expected, static::getResponseJsonPathValue($path));
126 1
    }
127
128
    /**
129
     * @param string $format
130
     * @param string $path
131
     */
132
    public static function assertResponseJsonValueMatchesFormat($format, $path)
133
    {
134
        static::assertJsonValueMatchesFormat(static::getResponse()->getContent(), $format, $path);
135
    }
136
137
    /**
138
     * @param string $format
139
     * @param string $path
140
     */
141
    public static function assertResponseJsonValueNotMatchesFormat($format, $path)
142
    {
143
        static::assertJsonValueNotMatchesFormat(static::getResponse()->getContent(), $format, $path);
144
    }
145
146
    /**
147
     * @param string $pattern
148
     * @param string $path
149
     */
150
    public static function assertResponseJsonValueRegExp($pattern, $path)
151
    {
152
        static::assertJsonValueRegExp(static::getResponse()->getContent(), $pattern, $path);
153
    }
154
155
    /**
156
     * @param string $pattern
157
     * @param string $path
158
     */
159
    public static function assertResponseJsonValueNotRegExp($pattern, $path)
160
    {
161
        static::assertJsonValueNotRegExp(static::getResponse()->getContent(), $pattern, $path);
162
    }
163
}
164