diff --git a/tests/Fixtures/Inputs/TestOnlyConstruct.php b/tests/Fixtures/Inputs/TestOnlyConstruct.php index f78ed8efdf..d4a0ecbf83 100644 --- a/tests/Fixtures/Inputs/TestOnlyConstruct.php +++ b/tests/Fixtures/Inputs/TestOnlyConstruct.php @@ -24,10 +24,17 @@ class TestOnlyConstruct */ private $bar; - public function __construct(string $foo, int $bar = 100) + /** + * @Field() + * @var bool + */ + private $baz; + + public function __construct(string $foo, bool $baz, int $bar = 100) { $this->foo = $foo; $this->bar = $bar; + $this->baz = $baz; } public function setFoo(string $foo): void @@ -39,6 +46,11 @@ public function setBar(int $bar): void { throw new Exception('This should not be called!'); } + + public function setBaz(bool $baz): void + { + throw new Exception('This should not be called!'); + } public function getFoo(): string { @@ -49,4 +61,9 @@ public function getBar(): int { return $this->bar; } + + public function getBaz(): bool + { + return $this->baz; + } } diff --git a/tests/Fixtures/Integration/Controllers/PreferencesController.php b/tests/Fixtures/Integration/Controllers/PreferencesController.php new file mode 100644 index 0000000000..a31f21900b --- /dev/null +++ b/tests/Fixtures/Integration/Controllers/PreferencesController.php @@ -0,0 +1,20 @@ +id = $id; + $this->options = $options; + $this->enabled = $enabled; + $this->name = $name; + } + + public function getId(): int + { + return $this->id; + } + + public function getOptions(): array + { + return $this->options; + } + + public function isEnabled(): bool + { + return $this->enabled; + } + + public function getName(): string + { + return $this->name; + } +} diff --git a/tests/Integration/EndToEndTest.php b/tests/Integration/EndToEndTest.php index 2bddb1219f..b196ce68b0 100644 --- a/tests/Integration/EndToEndTest.php +++ b/tests/Integration/EndToEndTest.php @@ -2002,6 +2002,46 @@ public function testEndToEndInputAnnotationIssues(): void $result->toArray(DebugFlag::RETHROW_INTERNAL_EXCEPTIONS); } + public function testEndToEndInputEmptyValues(): void + { + /** + * @var Schema $schema + */ + $schema = $this->mainContainer->get(Schema::class); + + $queryString = ' + mutation { + updatePreferences( + preferences: { + id: 0, + options: [], + enabled: false, + name: "" + } + ) { + id + options + enabled + name + } + } + '; + + $result = GraphQL::executeQuery( + $schema, + $queryString + ); + + $this->assertSame([ + 'updatePreferences' => [ + 'id' => 0, + 'options' => [], + 'enabled' => false, + 'name' => '', + ], + ], $this->getSuccessResult($result)); + } + public function testEndToEndInputTypeValidation(): void { $validator = new Validator(); diff --git a/tests/Types/InputTypeTest.php b/tests/Types/InputTypeTest.php index 57174337fe..e14b5efd41 100644 --- a/tests/Types/InputTypeTest.php +++ b/tests/Types/InputTypeTest.php @@ -121,6 +121,7 @@ public function testResolvesCorrectlyWithOnlyConstruct(): void $input = new InputType(TestOnlyConstruct::class, 'TestOnlyConstructInput', null, false, $this->getFieldsBuilder()); $args = [ + 'baz' => false, 'foo' => 'Foo', 'bar' => 200, ]; @@ -130,6 +131,7 @@ public function testResolvesCorrectlyWithOnlyConstruct(): void /** @var TestOnlyConstruct $result */ $result = $input->resolve(null, $args, [], $resolveInfo); + $this->assertEquals(false, $result->getBaz()); $this->assertEquals('Foo', $result->getFoo()); $this->assertEquals(200, $result->getBar()); }