|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimPod\GraphQLUtils\Tests\Builder; |
| 6 | + |
| 7 | +use GraphQL\Type\Definition\InputObjectField; |
| 8 | +use GraphQL\Type\Definition\InterfaceType; |
| 9 | +use GraphQL\Type\Definition\Type; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | +use SimPod\GraphQLUtils\Builder\InputFieldBuilder; |
| 12 | +use SimPod\GraphQLUtils\Builder\InputObjectBuilder; |
| 13 | +use SimPod\GraphQLUtils\Builder\InterfaceBuilder; |
| 14 | + |
| 15 | +final class InputObjectBuilderTest extends TestCase |
| 16 | +{ |
| 17 | + public function testCreate(): void |
| 18 | + { |
| 19 | + $description = 'To the sichuan-style nachos add ghee, noodles, buttermilk and heated herring.'; |
| 20 | + $name = 'SomeType'; |
| 21 | + $interface = new class () extends InterfaceType { |
| 22 | + public function __construct() |
| 23 | + { |
| 24 | + $builder = InterfaceBuilder::create('InterfaceA'); |
| 25 | + parent::__construct($builder->build()); |
| 26 | + } |
| 27 | + }; |
| 28 | + |
| 29 | + $fieldResolver = static function (): void { |
| 30 | + }; |
| 31 | + |
| 32 | + $builder = InputObjectBuilder::create($name); |
| 33 | + $object = $builder |
| 34 | + ->setDescription($description) |
| 35 | + ->setFields( |
| 36 | + [ |
| 37 | + InputFieldBuilder::create('SomeField', Type::string())->build(), |
| 38 | + new InputObjectField(InputFieldBuilder::create('Another', Type::string())->build()), |
| 39 | + ] |
| 40 | + ) |
| 41 | + ->build(); |
| 42 | + |
| 43 | + self::assertArrayHasKey('name', $object); |
| 44 | + self::assertSame($name, $object['name']); |
| 45 | + self::assertArrayHasKey('description', $object); |
| 46 | + self::assertSame($description, $object['description']); |
| 47 | + self::assertIsArray($object['fields']); |
| 48 | + self::assertCount(2, $object['fields']); |
| 49 | + } |
| 50 | +} |
0 commit comments