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

assertResponseJsonArraySubset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
crap 1
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 assertResponseJsonPathInternalType($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 assertResponseJsonPathNotInternalType($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 assertResponseJsonPathEquals($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 assertResponseJsonPathFalse($path)
90
    {
91 1
        static::assertFalse(static::getResponseJsonPathValue($path));
92 1
    }
93
94
    /**
95
     * @param string $path
96
     */
97
    public static function assertResponseJsonPathTrue($path)
98
    {
99
        static::assertTrue(static::getResponseJsonPathValue($path));
100
    }
101
102
    /**
103
     * @param mixed  $expected
104
     * @param string $path
105
     */
106
    public static function assertResponseJsonPathNotEquals($expected, $path)
107
    {
108
        static::assertNotEquals($expected, static::getResponseJsonPathValue($path));
109
    }
110
111
    /**
112
     * @param string $path
113
     */
114 1
    public static function assertResponseJsonPathNull($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 $path
130
     */
131
    public static function assertResponseJsonPathMatch($path)
132
    {
133
        static::assertJsonPathMatch(static::getResponse()->getContent(), $path);
134
    }
135
136
    /**
137
     * @param string $path
138
     */
139
    public static function assertResponseJsonPathNotMatch($path)
140
    {
141
        static::assertJsonPathNotMatch(static::getResponse()->getContent(), $path);
142
    }
143
}
144