ynloultratech /
graphql-bundle
| 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 | * @deprecated in favor of Behat tests |
||||
| 22 | */ |
||||
| 23 | trait ResponseAssertTrait |
||||
| 24 | { |
||||
| 25 | /** |
||||
| 26 | * assertResponseEmptyContent |
||||
| 27 | */ |
||||
| 28 | public static function assertResponseEmptyContent() |
||||
| 29 | { |
||||
| 30 | static::assertEmpty(static::getClient()->getResponse()->getContent()); |
||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
| 31 | } |
||||
| 32 | |||||
| 33 | /** |
||||
| 34 | * @param string $code |
||||
| 35 | */ |
||||
| 36 | public static function assertResponseCodeIs($code) |
||||
| 37 | { |
||||
| 38 | static::assertEquals($code, static::getClient()->getResponse()->getStatusCode()); |
||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||
| 39 | } |
||||
| 40 | |||||
| 41 | /** |
||||
| 42 | * assertResponseCodeIsOK |
||||
| 43 | */ |
||||
| 44 | public static function assertResponseCodeIsOK() |
||||
| 45 | { |
||||
| 46 | static::assertEquals(Response::HTTP_OK, static::getClient()->getResponse()->getStatusCode()); |
||||
|
0 ignored issues
–
show
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
Loading history...
|
|||||
| 47 | } |
||||
| 48 | |||||
| 49 | /** |
||||
| 50 | * Check if the latest response is a valid JSON |
||||
| 51 | */ |
||||
| 52 | public static function assertResponseIsValidJson() |
||||
| 53 | { |
||||
| 54 | $response = static::getResponse(); |
||||
| 55 | |||||
| 56 | static::assertNotNull($response); |
||||
| 57 | static::assertEquals('application/json', $response->headers->get('Content-Field')); |
||||
| 58 | static::assertJson($response->getContent()); |
||||
| 59 | } |
||||
| 60 | |||||
| 61 | /** |
||||
| 62 | * @param string $type |
||||
| 63 | * @param string $path |
||||
| 64 | */ |
||||
| 65 | public static function assertResponseJsonValueInternalType($type, $path) |
||||
| 66 | { |
||||
| 67 | static::assertInternalType($type, static::getResponseJsonPathValue($path)); |
||||
| 68 | } |
||||
| 69 | |||||
| 70 | /** |
||||
| 71 | * @param string $type |
||||
| 72 | * @param string $path |
||||
| 73 | */ |
||||
| 74 | public static function assertResponseJsonValueNotInternalType($type, $path) |
||||
| 75 | { |
||||
| 76 | static::assertNotInternalType($type, static::getResponseJsonPathValue($path)); |
||||
| 77 | } |
||||
| 78 | |||||
| 79 | /** |
||||
| 80 | * @param mixed $expected |
||||
| 81 | * @param string $path |
||||
| 82 | */ |
||||
| 83 | public static function assertResponseJsonValueEquals($expected, $path) |
||||
| 84 | { |
||||
| 85 | static::assertEquals($expected, static::getResponseJsonPathValue($path)); |
||||
| 86 | } |
||||
| 87 | |||||
| 88 | /** |
||||
| 89 | * @param string $path |
||||
| 90 | */ |
||||
| 91 | public static function assertResponseJsonValueIsFalse($path) |
||||
| 92 | { |
||||
| 93 | static::assertFalse(static::getResponseJsonPathValue($path)); |
||||
| 94 | } |
||||
| 95 | |||||
| 96 | /** |
||||
| 97 | * @param string $path |
||||
| 98 | */ |
||||
| 99 | public static function assertResponseJsonValueIsTrue($path) |
||||
| 100 | { |
||||
| 101 | static::assertTrue(static::getResponseJsonPathValue($path)); |
||||
| 102 | } |
||||
| 103 | |||||
| 104 | /** |
||||
| 105 | * @param mixed $expected |
||||
| 106 | * @param string $path |
||||
| 107 | */ |
||||
| 108 | public static function assertResponseJsonValueNotEquals($expected, $path) |
||||
| 109 | { |
||||
| 110 | static::assertNotEquals($expected, static::getResponseJsonPathValue($path)); |
||||
| 111 | } |
||||
| 112 | |||||
| 113 | /** |
||||
| 114 | * @param string $path |
||||
| 115 | */ |
||||
| 116 | public static function assertResponseJsonValueIsNull($path) |
||||
| 117 | { |
||||
| 118 | static::assertNull(static::getResponseJsonPathValue($path)); |
||||
| 119 | } |
||||
| 120 | |||||
| 121 | /** |
||||
| 122 | * @param mixed $expected |
||||
| 123 | * @param string $path |
||||
| 124 | */ |
||||
| 125 | public static function assertResponseJsonArraySubset($expected, $path) |
||||
| 126 | { |
||||
| 127 | static::assertArraySubset($expected, static::getResponseJsonPathValue($path)); |
||||
| 128 | } |
||||
| 129 | |||||
| 130 | /** |
||||
| 131 | * @param string $format |
||||
| 132 | * @param string $path |
||||
| 133 | */ |
||||
| 134 | public static function assertResponseJsonValueMatchesFormat($format, $path) |
||||
| 135 | { |
||||
| 136 | static::assertJsonValueMatchesFormat(static::getResponse()->getContent(), $format, $path); |
||||
| 137 | } |
||||
| 138 | |||||
| 139 | /** |
||||
| 140 | * @param string $format |
||||
| 141 | * @param string $path |
||||
| 142 | */ |
||||
| 143 | public static function assertResponseJsonValueNotMatchesFormat($format, $path) |
||||
| 144 | { |
||||
| 145 | static::assertJsonValueNotMatchesFormat(static::getResponse()->getContent(), $format, $path); |
||||
| 146 | } |
||||
| 147 | |||||
| 148 | /** |
||||
| 149 | * @param string $pattern |
||||
| 150 | * @param string $path |
||||
| 151 | */ |
||||
| 152 | public static function assertResponseJsonValueRegExp($pattern, $path) |
||||
| 153 | { |
||||
| 154 | static::assertJsonValueRegExp(static::getResponse()->getContent(), $pattern, $path); |
||||
| 155 | } |
||||
| 156 | |||||
| 157 | /** |
||||
| 158 | * @param string $pattern |
||||
| 159 | * @param string $path |
||||
| 160 | */ |
||||
| 161 | public static function assertResponseJsonValueNotRegExp($pattern, $path) |
||||
| 162 | { |
||||
| 163 | static::assertJsonValueNotRegExp(static::getResponse()->getContent(), $pattern, $path); |
||||
| 164 | } |
||||
| 165 | } |
||||
| 166 |