Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 72 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| GraphqlTestHelper | |
0.00% |
0 / 72 |
|
0.00% |
0 / 7 |
90 | |
0.00% |
0 / 1 |
| createEmptyCall | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| createSchemaCall | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| createTypeInspectionCall | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| createIntrospectionCall | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| createEntityList | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| createExpectedListResponse | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| createQueryCall | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\IntegrationTests\Graphql; |
| 3 | |
| 4 | use Apie\Core\BoundedContext\BoundedContextId; |
| 5 | use Apie\IntegrationTests\Apie\TypeDemo\Identifiers\PrimitiveOnlyIdentifier; |
| 6 | use Apie\IntegrationTests\Apie\TypeDemo\Resources\PrimitiveOnly; |
| 7 | use Apie\IntegrationTests\IntegrationTestHelper; |
| 8 | |
| 9 | class GraphqlTestHelper extends IntegrationTestHelper |
| 10 | { |
| 11 | public function createEmptyCall(): GraphqlProvider |
| 12 | { |
| 13 | return new GraphqlProvider( |
| 14 | new BoundedContextId('types'), |
| 15 | [ |
| 16 | 'query' => '{ apie_version }' |
| 17 | ], |
| 18 | [ |
| 19 | "data" => [ |
| 20 | "apie_version" => \Apie\Core\ApieLib::VERSION, |
| 21 | ], |
| 22 | ] |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | public function createSchemaCall(): GraphqlProvider |
| 27 | { |
| 28 | return new SchemaGraphqlProvider( |
| 29 | new BoundedContextId('types'), |
| 30 | [ |
| 31 | 'query' => '{ |
| 32 | __schema { |
| 33 | queryType { |
| 34 | fields { |
| 35 | name |
| 36 | description |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | }' |
| 41 | ], |
| 42 | [ |
| 43 | ] |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | public function createTypeInspectionCall(): GraphqlProvider |
| 48 | { |
| 49 | return new SchemaGraphqlProvider( |
| 50 | new BoundedContextId('types'), |
| 51 | [ |
| 52 | 'query' => 'query IntrospectionQuery { |
| 53 | __schema { |
| 54 | queryType { |
| 55 | name |
| 56 | } |
| 57 | mutationType { |
| 58 | name |
| 59 | } |
| 60 | subscriptionType { |
| 61 | name |
| 62 | } |
| 63 | types { |
| 64 | ...FullType |
| 65 | } |
| 66 | directives { |
| 67 | name |
| 68 | description |
| 69 | locations |
| 70 | args { |
| 71 | ...InputValue |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | fragment FullType on __Type { |
| 78 | kind |
| 79 | name |
| 80 | description |
| 81 | fields(includeDeprecated: true) { |
| 82 | name |
| 83 | description |
| 84 | args { |
| 85 | ...InputValue |
| 86 | } |
| 87 | type { |
| 88 | ...TypeRef |
| 89 | } |
| 90 | isDeprecated |
| 91 | deprecationReason |
| 92 | } |
| 93 | inputFields { |
| 94 | ...InputValue |
| 95 | } |
| 96 | interfaces { |
| 97 | ...TypeRef |
| 98 | } |
| 99 | enumValues(includeDeprecated: true) { |
| 100 | name |
| 101 | description |
| 102 | isDeprecated |
| 103 | deprecationReason |
| 104 | } |
| 105 | possibleTypes { |
| 106 | ...TypeRef |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | fragment InputValue on __InputValue { |
| 111 | name |
| 112 | description |
| 113 | type { |
| 114 | ...TypeRef |
| 115 | } |
| 116 | defaultValue |
| 117 | } |
| 118 | |
| 119 | fragment TypeRef on __Type { |
| 120 | kind |
| 121 | name |
| 122 | ofType { |
| 123 | kind |
| 124 | name |
| 125 | ofType { |
| 126 | kind |
| 127 | name |
| 128 | ofType { |
| 129 | kind |
| 130 | name |
| 131 | ofType { |
| 132 | kind |
| 133 | name |
| 134 | ofType { |
| 135 | kind |
| 136 | name |
| 137 | ofType { |
| 138 | kind |
| 139 | name |
| 140 | ofType { |
| 141 | kind |
| 142 | name |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | ' |
| 152 | ], |
| 153 | [] |
| 154 | ); |
| 155 | } |
| 156 | |
| 157 | public function createIntrospectionCall(): GraphqlProvider |
| 158 | { |
| 159 | return new SchemaGraphqlProvider( |
| 160 | new BoundedContextId('types'), |
| 161 | [ |
| 162 | 'query' => '{ |
| 163 | __type(name: "findPrimitiveOnly") { |
| 164 | name |
| 165 | description |
| 166 | fields { |
| 167 | name |
| 168 | description |
| 169 | } |
| 170 | } |
| 171 | }' |
| 172 | ], |
| 173 | [ |
| 174 | ] |
| 175 | ); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * @return array<int, PrimitiveOnly> |
| 180 | */ |
| 181 | private function createEntityList(int $count): array |
| 182 | { |
| 183 | $entities = []; |
| 184 | for ($i = 0; $i < $count; $i++) { |
| 185 | $entity = new PrimitiveOnly(PrimitiveOnlyIdentifier::generateFromInteger($i)); |
| 186 | $entity->stringField = 'String ' . $i; |
| 187 | $entity->integerField = $i * 10; |
| 188 | $entity->floatingPoint = $i * 1.5; |
| 189 | $entity->booleanField = $i % 2 === 0; |
| 190 | $entities[] = $entity; |
| 191 | } |
| 192 | return $entities; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * @return array<int, array<string, mixed>> |
| 197 | */ |
| 198 | private function createExpectedListResponse(int $start, int $end): array |
| 199 | { |
| 200 | $list = []; |
| 201 | for ($i = $start; $i <= $end; $i++) { |
| 202 | $list[] = [ |
| 203 | 'id' => (string) PrimitiveOnlyIdentifier::generateFromInteger($i), |
| 204 | 'stringField' => 'String ' . $i, |
| 205 | 'integerField' => $i * 10, |
| 206 | 'floatingPoint' => $i * 1.5, |
| 207 | 'booleanField' => $i % 2 === 0, |
| 208 | ]; |
| 209 | } |
| 210 | return $list; |
| 211 | } |
| 212 | |
| 213 | public function createQueryCall(): GraphqlProvider |
| 214 | { |
| 215 | $entities = $this->createEntityList(30); |
| 216 | return new GraphqlProvider( |
| 217 | new BoundedContextId('types'), |
| 218 | [ |
| 219 | 'query' => '{ findPrimitiveOnly(filter: { orderBy: "+id" }) { totalCount, list { id, stringField, integerField, floatingPoint, booleanField } } }' |
| 220 | ], |
| 221 | [ |
| 222 | 'data' => [ |
| 223 | 'findPrimitiveOnly' => [ |
| 224 | 'list' => $this->createExpectedListResponse(0, 19), |
| 225 | 'totalCount' => 30, |
| 226 | ] |
| 227 | ] |
| 228 | ], |
| 229 | $entities |
| 230 | ); |
| 231 | } |
| 232 | |
| 233 | } |