@@ -11,7 +11,7 @@ |
||
| 11 | 11 | use Youshido\GraphQL\Processor; |
| 12 | 12 | use Youshido\GraphQL\Schema; |
| 13 | 13 | |
| 14 | -require_once __DIR__ . '/schema-bootstrap.php'; |
|
| 14 | +require_once __DIR__.'/schema-bootstrap.php'; |
|
| 15 | 15 | /** @var Schema $schema */ |
| 16 | 16 | $schema = new BlogSchema(); |
| 17 | 17 | |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -require_once __DIR__ . '/../../vendor/autoload.php'; |
|
| 4 | -require_once __DIR__ . '/Schema/FactionType.php'; |
|
| 5 | -require_once __DIR__ . '/Schema/ShipType.php'; |
|
| 6 | -require_once __DIR__ . '/Schema/TestDataProvider.php'; |
|
| 7 | -require_once __DIR__ . '/Schema/StarWarsRelaySchema.php'; |
|
| 3 | +require_once __DIR__.'/../../vendor/autoload.php'; |
|
| 4 | +require_once __DIR__.'/Schema/FactionType.php'; |
|
| 5 | +require_once __DIR__.'/Schema/ShipType.php'; |
|
| 6 | +require_once __DIR__.'/Schema/TestDataProvider.php'; |
|
| 7 | +require_once __DIR__.'/Schema/StarWarsRelaySchema.php'; |
|
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $validator = ConfigValidator::getInstance(); |
| 54 | 54 | |
| 55 | 55 | if (!$validator->validate($this->data, $this->getContextRules(), $this->extraFieldsAllowed)) { |
| 56 | - throw new ConfigurationException('Config is not valid for ' . ($contextObject ? get_class($contextObject) : null) . "\n" . implode("\n", $validator->getErrorsArray(false))); |
|
| 56 | + throw new ConfigurationException('Config is not valid for '.($contextObject ? get_class($contextObject) : null)."\n".implode("\n", $validator->getErrorsArray(false))); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | $this->build(); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | } elseif (substr($method, 0, 2) == 'is') { |
| 127 | 127 | $propertyName = lcfirst(substr($method, 2)); |
| 128 | 128 | } else { |
| 129 | - throw new \Exception('Call to undefined method ' . $method); |
|
| 129 | + throw new \Exception('Call to undefined method '.$method); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | return $this->get($propertyName); |
@@ -93,9 +93,9 @@ |
||
| 93 | 93 | return $this->get('resolve', null); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * @return string|null |
|
| 98 | - */ |
|
| 96 | + /** |
|
| 97 | + * @return string|null |
|
| 98 | + */ |
|
| 99 | 99 | public function getResolveString() |
| 100 | 100 | { |
| 101 | 101 | return $this->get('resolveString', null); |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | public function getValue() |
| 42 | 42 | { |
| 43 | 43 | if (!$this->value) { |
| 44 | - throw new \LogicException('Value is not set for variable "' . $this->name . '"'); |
|
| 44 | + throw new \LogicException('Value is not set for variable "'.$this->name.'"'); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | return $this->value; |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - public function testNestedVariables() { |
|
| 58 | + public function testNestedVariables() { |
|
| 59 | 59 | $processor = new Processor(new TestSchema()); |
| 60 | 60 | $noArgsQuery = '{ me { echo(value:"foo") } }'; |
| 61 | 61 | $expectedData = ['data' => ['me' => ['echo' => 'foo']]]; |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | }'; |
| 82 | 82 | $processor->processPayload($parameterizedQueryQuery, ['value' => 1]); |
| 83 | 83 | $this->assertArrayNotHasKey('errors', $processor->getResponseData()); |
| 84 | - } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | 86 | public function testListNullResponse() |
| 87 | 87 | { |
@@ -192,19 +192,19 @@ discard block |
||
| 192 | 192 | $this->assertEquals(['data' => ['me' => ['firstName' => 'JOHN']]], $processor->getResponseData()); |
| 193 | 193 | |
| 194 | 194 | $schema->getMutationType() |
| 195 | - ->addField(new Field([ |
|
| 196 | - 'name' => 'increaseCounter', |
|
| 197 | - 'type' => new IntType(), |
|
| 198 | - 'resolve' => function ($value, $args, ResolveInfo $info) { |
|
| 199 | - return $this->_counter += $args['amount']; |
|
| 200 | - }, |
|
| 201 | - 'args' => [ |
|
| 202 | - 'amount' => [ |
|
| 203 | - 'type' => new IntType(), |
|
| 204 | - 'default' => 1 |
|
| 205 | - ] |
|
| 206 | - ] |
|
| 207 | - ]))->addField(new Field([ |
|
| 195 | + ->addField(new Field([ |
|
| 196 | + 'name' => 'increaseCounter', |
|
| 197 | + 'type' => new IntType(), |
|
| 198 | + 'resolve' => function ($value, $args, ResolveInfo $info) { |
|
| 199 | + return $this->_counter += $args['amount']; |
|
| 200 | + }, |
|
| 201 | + 'args' => [ |
|
| 202 | + 'amount' => [ |
|
| 203 | + 'type' => new IntType(), |
|
| 204 | + 'default' => 1 |
|
| 205 | + ] |
|
| 206 | + ] |
|
| 207 | + ]))->addField(new Field([ |
|
| 208 | 208 | 'name' => 'invalidResolveTypeMutation', |
| 209 | 209 | 'type' => new NonNullType(new IntType()), |
| 210 | 210 | 'resolve' => function () { |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | public function testSchemaOperations() |
| 127 | 127 | { |
| 128 | - $schema = new Schema([ |
|
| 128 | + $schema = new Schema([ |
|
| 129 | 129 | 'query' => new ObjectType([ |
| 130 | 130 | 'name' => 'RootQuery', |
| 131 | 131 | 'fields' => [ |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | 'args' => [ |
| 139 | 139 | 'shorten' => new BooleanType() |
| 140 | 140 | ], |
| 141 | - 'resolve' => function ($value, $args) { |
|
| 141 | + 'resolve' => function($value, $args) { |
|
| 142 | 142 | return empty($args['shorten']) ? $value : $value; |
| 143 | 143 | } |
| 144 | 144 | ], |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | 'code' => new StringType(), |
| 147 | 147 | ] |
| 148 | 148 | ]), |
| 149 | - 'resolve' => function ($value, $args) { |
|
| 149 | + 'resolve' => function($value, $args) { |
|
| 150 | 150 | $data = ['firstName' => 'John', 'code' => '007']; |
| 151 | 151 | if (!empty($args['upper'])) { |
| 152 | 152 | foreach ($data as $key => $value) { |
@@ -165,13 +165,13 @@ discard block |
||
| 165 | 165 | ], |
| 166 | 166 | 'randomUser' => [ |
| 167 | 167 | 'type' => new TestObjectType(), |
| 168 | - 'resolve' => function () { |
|
| 168 | + 'resolve' => function() { |
|
| 169 | 169 | return ['invalidField' => 'John']; |
| 170 | 170 | } |
| 171 | 171 | ], |
| 172 | 172 | 'invalidValueQuery' => [ |
| 173 | 173 | 'type' => new TestObjectType(), |
| 174 | - 'resolve' => function () { |
|
| 174 | + 'resolve' => function() { |
|
| 175 | 175 | return 'stringValue'; |
| 176 | 176 | } |
| 177 | 177 | ], |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | ->addField(new Field([ |
| 197 | 197 | 'name' => 'increaseCounter', |
| 198 | 198 | 'type' => new IntType(), |
| 199 | - 'resolve' => function ($value, $args, ResolveInfo $info) { |
|
| 199 | + 'resolve' => function($value, $args, ResolveInfo $info) { |
|
| 200 | 200 | return $this->_counter += $args['amount']; |
| 201 | 201 | }, |
| 202 | 202 | 'args' => [ |
@@ -208,13 +208,13 @@ discard block |
||
| 208 | 208 | ]))->addField(new Field([ |
| 209 | 209 | 'name' => 'invalidResolveTypeMutation', |
| 210 | 210 | 'type' => new NonNullType(new IntType()), |
| 211 | - 'resolve' => function () { |
|
| 211 | + 'resolve' => function() { |
|
| 212 | 212 | return null; |
| 213 | 213 | } |
| 214 | 214 | ]))->addField(new Field([ |
| 215 | 215 | 'name' => 'interfacedMutation', |
| 216 | 216 | 'type' => new TestInterfaceType(), |
| 217 | - 'resolve' => function () { |
|
| 217 | + 'resolve' => function() { |
|
| 218 | 218 | return ['name' => 'John']; |
| 219 | 219 | } |
| 220 | 220 | ])); |
@@ -260,43 +260,43 @@ discard block |
||
| 260 | 260 | 'fields' => [ |
| 261 | 261 | 'listQuery' => [ |
| 262 | 262 | 'type' => new ListType(new TestEnumType()), |
| 263 | - 'resolve' => function () { |
|
| 263 | + 'resolve' => function() { |
|
| 264 | 264 | return 'invalid list'; |
| 265 | 265 | } |
| 266 | 266 | ], |
| 267 | 267 | 'listEnumQuery' => [ |
| 268 | 268 | 'type' => new ListType(new TestEnumType()), |
| 269 | - 'resolve' => function () { |
|
| 269 | + 'resolve' => function() { |
|
| 270 | 270 | return ['invalid enum']; |
| 271 | 271 | } |
| 272 | 272 | ], |
| 273 | 273 | 'invalidEnumQuery' => [ |
| 274 | 274 | 'type' => new TestEnumType(), |
| 275 | - 'resolve' => function () { |
|
| 275 | + 'resolve' => function() { |
|
| 276 | 276 | return 'invalid enum'; |
| 277 | 277 | } |
| 278 | 278 | ], |
| 279 | 279 | 'enumQuery' => [ |
| 280 | 280 | 'type' => new TestEnumType(), |
| 281 | - 'resolve' => function () { |
|
| 281 | + 'resolve' => function() { |
|
| 282 | 282 | return 1; |
| 283 | 283 | } |
| 284 | 284 | ], |
| 285 | 285 | 'invalidNonNullQuery' => [ |
| 286 | 286 | 'type' => new NonNullType(new IntType()), |
| 287 | - 'resolve' => function () { |
|
| 287 | + 'resolve' => function() { |
|
| 288 | 288 | return null; |
| 289 | 289 | } |
| 290 | 290 | ], |
| 291 | 291 | 'invalidNonNullInsideQuery' => [ |
| 292 | 292 | 'type' => new NonNullType(new IntType()), |
| 293 | - 'resolve' => function () { |
|
| 293 | + 'resolve' => function() { |
|
| 294 | 294 | return 'hello'; |
| 295 | 295 | } |
| 296 | 296 | ], |
| 297 | 297 | 'objectQuery' => [ |
| 298 | 298 | 'type' => new TestObjectType(), |
| 299 | - 'resolve' => function () { |
|
| 299 | + 'resolve' => function() { |
|
| 300 | 300 | return ['name' => 'John']; |
| 301 | 301 | } |
| 302 | 302 | ], |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | 'enum' => new TestEnumType(), |
| 309 | 309 | ], |
| 310 | 310 | ]), |
| 311 | - 'resolve' => function () { |
|
| 311 | + 'resolve' => function() { |
|
| 312 | 312 | return [ |
| 313 | 313 | 'object' => [ |
| 314 | 314 | 'name' => 'John' |
@@ -377,10 +377,10 @@ discard block |
||
| 377 | 377 | ] |
| 378 | 378 | ]); |
| 379 | 379 | |
| 380 | - $union = new UnionType([ |
|
| 380 | + $union = new UnionType([ |
|
| 381 | 381 | 'name' => 'TestUnion', |
| 382 | 382 | 'types' => [$object1, $object2], |
| 383 | - 'resolveType' => function ($object) use ($object1, $object2) { |
|
| 383 | + 'resolveType' => function($object) use ($object1, $object2) { |
|
| 384 | 384 | if (isset($object['id'])) { |
| 385 | 385 | return $object1; |
| 386 | 386 | } |
@@ -391,11 +391,11 @@ discard block |
||
| 391 | 391 | $invalidUnion = new UnionType([ |
| 392 | 392 | 'name' => 'TestUnion', |
| 393 | 393 | 'types' => [$object1, $object2], |
| 394 | - 'resolveType' => function ($object) use ($object3) { |
|
| 394 | + 'resolveType' => function($object) use ($object3) { |
|
| 395 | 395 | return $object3; |
| 396 | 396 | } |
| 397 | 397 | ]); |
| 398 | - $processor = new Processor(new Schema([ |
|
| 398 | + $processor = new Processor(new Schema([ |
|
| 399 | 399 | 'query' => new ObjectType([ |
| 400 | 400 | 'name' => 'RootQuery', |
| 401 | 401 | 'fields' => [ |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | 'args' => [ |
| 405 | 405 | 'type' => ['type' => 'string'] |
| 406 | 406 | ], |
| 407 | - 'resolve' => function ($value, $args) { |
|
| 407 | + 'resolve' => function($value, $args) { |
|
| 408 | 408 | if ($args['type'] == 'object1') { |
| 409 | 409 | return [ |
| 410 | 410 | 'id' => 43 |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | ], |
| 419 | 419 | 'invalidUnion' => [ |
| 420 | 420 | 'type' => $invalidUnion, |
| 421 | - 'resolve' => function () { |
|
| 421 | + 'resolve' => function() { |
|
| 422 | 422 | return ['name' => 'name resolved']; |
| 423 | 423 | } |
| 424 | 424 | ], |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | $resolveFactory = $this->prophesize(ResolveStringResolverInterface::class); |
| 455 | 455 | $resolveFactory->resolve('service_name:get') |
| 456 | 456 | ->shouldBeCalled() |
| 457 | - ->willReturn(function () { |
|
| 457 | + ->willReturn(function() { |
|
| 458 | 458 | return 'hello'; |
| 459 | 459 | }); |
| 460 | 460 | |
@@ -30,21 +30,21 @@ |
||
| 30 | 30 | ], |
| 31 | 31 | ])) |
| 32 | 32 | ->addField('location', [ |
| 33 | - 'type' => new ObjectType( |
|
| 34 | - [ |
|
| 35 | - 'name' => 'Location', |
|
| 36 | - 'fields' => [ |
|
| 37 | - 'address' => new StringType() |
|
| 38 | - ] |
|
| 39 | - ] |
|
| 40 | - ), |
|
| 41 | - 'args' => [ |
|
| 42 | - 'noop' => new IntType() |
|
| 43 | - ], |
|
| 44 | - 'resolve' => function ($value, $args, $info) { |
|
| 45 | - return ['address' => '1234 Street']; |
|
| 46 | - } |
|
| 47 | - ] |
|
| 33 | + 'type' => new ObjectType( |
|
| 34 | + [ |
|
| 35 | + 'name' => 'Location', |
|
| 36 | + 'fields' => [ |
|
| 37 | + 'address' => new StringType() |
|
| 38 | + ] |
|
| 39 | + ] |
|
| 40 | + ), |
|
| 41 | + 'args' => [ |
|
| 42 | + 'noop' => new IntType() |
|
| 43 | + ], |
|
| 44 | + 'resolve' => function ($value, $args, $info) { |
|
| 45 | + return ['address' => '1234 Street']; |
|
| 46 | + } |
|
| 47 | + ] |
|
| 48 | 48 | ) |
| 49 | 49 | ->addField( |
| 50 | 50 | 'echo', [ |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | 'args' => [ |
| 42 | 42 | 'noop' => new IntType() |
| 43 | 43 | ], |
| 44 | - 'resolve' => function ($value, $args, $info) { |
|
| 44 | + 'resolve' => function($value, $args, $info) { |
|
| 45 | 45 | return ['address' => '1234 Street']; |
| 46 | 46 | } |
| 47 | 47 | ] |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | 'args' => [ |
| 53 | 53 | 'value' => new NonNullType(new StringType()) |
| 54 | 54 | ], |
| 55 | - 'resolve' => function ($value, $args, $info) { |
|
| 55 | + 'resolve' => function($value, $args, $info) { |
|
| 56 | 56 | return $args['value']; |
| 57 | 57 | } |
| 58 | 58 | ] |
@@ -61,6 +61,6 @@ |
||
| 61 | 61 | $arrayData = (new TestObjectType())->getData(); |
| 62 | 62 | |
| 63 | 63 | $this->assertEquals('John', TypeService::getPropertyValue($arrayData, 'name')); |
| 64 | - $this->assertEquals('John', TypeService::getPropertyValue((object) $arrayData, 'name')); |
|
| 64 | + $this->assertEquals('John', TypeService::getPropertyValue((object)$arrayData, 'name')); |
|
| 65 | 65 | } |
| 66 | 66 | } |