|
5 | 5 | namespace Overblog\GraphQLBundle\Tests\Transformer;
|
6 | 6 |
|
7 | 7 | use Exception;
|
| 8 | +use Generator; |
8 | 9 | use GraphQL\Type\Definition\EnumType;
|
9 | 10 | use GraphQL\Type\Definition\InputObjectType;
|
| 11 | +use GraphQL\Type\Definition\ListOfType; |
| 12 | +use GraphQL\Type\Definition\NonNull; |
10 | 13 | use GraphQL\Type\Definition\ResolveInfo;
|
11 | 14 | use GraphQL\Type\Definition\Type;
|
12 | 15 | use GraphQL\Type\Schema;
|
@@ -300,4 +303,75 @@ public function testRaisedErrorsForMultipleInputs(): void
|
300 | 303 | $this->assertEquals($e->toState(), $expected);
|
301 | 304 | }
|
302 | 305 | }
|
| 306 | + |
| 307 | + public function getWrappedInputObject(): Generator |
| 308 | + { |
| 309 | + $inputObject = new InputObjectType([ |
| 310 | + 'name' => 'InputType1', |
| 311 | + 'fields' => [ |
| 312 | + 'field1' => Type::string(), |
| 313 | + 'field2' => Type::int(), |
| 314 | + 'field3' => Type::boolean(), |
| 315 | + ], |
| 316 | + ]); |
| 317 | + yield [$inputObject, false]; |
| 318 | + yield [new NonNull($inputObject), false]; |
| 319 | + } |
| 320 | + |
| 321 | + /** @dataProvider getWrappedInputObject */ |
| 322 | + public function testInputObjectWithWrappingType(Type $type): void |
| 323 | + { |
| 324 | + $transformer = $this->getTransformer([ |
| 325 | + 'InputType1' => ['type' => 'input', 'class' => InputType1::class], |
| 326 | + ], new ConstraintViolationList() |
| 327 | + ); |
| 328 | + $info = $this->getResolveInfo(self::getTypes()); |
| 329 | + |
| 330 | + $data = ['field1' => 'hello', 'field2' => 12, 'field3' => true]; |
| 331 | + |
| 332 | + $inputValue = $transformer->getInstanceAndValidate($type->toString(), $data, $info, 'input1'); |
| 333 | + |
| 334 | + /** @var InputType1 $inputValue */ |
| 335 | + $this->assertInstanceOf(InputType1::class, $inputValue); |
| 336 | + $this->assertEquals($inputValue->field1, $data['field1']); |
| 337 | + $this->assertEquals($inputValue->field2, $data['field2']); |
| 338 | + $this->assertEquals($inputValue->field3, $data['field3']); |
| 339 | + } |
| 340 | + |
| 341 | + public function getWrappedInputObjectList(): Generator |
| 342 | + { |
| 343 | + $inputObject = new InputObjectType([ |
| 344 | + 'name' => 'InputType1', |
| 345 | + 'fields' => [ |
| 346 | + 'field1' => Type::string(), |
| 347 | + 'field2' => Type::int(), |
| 348 | + 'field3' => Type::boolean(), |
| 349 | + ], |
| 350 | + ]); |
| 351 | + yield [new ListOfType($inputObject)]; |
| 352 | + yield [new ListOfType(new NonNull($inputObject))]; |
| 353 | + yield [new NonNull(new ListOfType($inputObject))]; |
| 354 | + yield [new NonNull(new ListOfType(new NonNull($inputObject)))]; |
| 355 | + } |
| 356 | + |
| 357 | + /** @dataProvider getWrappedInputObject */ |
| 358 | + public function testInputObjectWithWrappingTypeList(Type $type): void |
| 359 | + { |
| 360 | + $transformer = $this->getTransformer( |
| 361 | + ['InputType1' => ['type' => 'input', 'class' => InputType1::class]], |
| 362 | + new ConstraintViolationList() |
| 363 | + ); |
| 364 | + $info = $this->getResolveInfo(self::getTypes()); |
| 365 | + |
| 366 | + $data = ['field1' => 'hello', 'field2' => 12, 'field3' => true]; |
| 367 | + |
| 368 | + $inputValue = $transformer->getInstanceAndValidate($type->toString(), [$data], $info, 'input1'); |
| 369 | + $inputValue = reset($inputValue); |
| 370 | + |
| 371 | + /** @var InputType1 $inputValue */ |
| 372 | + $this->assertInstanceOf(InputType1::class, $inputValue); |
| 373 | + $this->assertEquals($inputValue->field1, $data['field1']); |
| 374 | + $this->assertEquals($inputValue->field2, $data['field2']); |
| 375 | + $this->assertEquals($inputValue->field3, $data['field3']); |
| 376 | + } |
303 | 377 | }
|
0 commit comments