Skip to content

Commit 4fcbb74

Browse files
ozahoruliaMarcin Hubertozahorulia
authored
Tests for #410 (#482)
* feat: add test for #410 * Tests for #411 (fixes #410, #481) Co-authored-by: Marcin Hubert <marcin.hubert@zety.com> Co-authored-by: ozahorulia <ozahorulia@unisender.com>
1 parent dc6e07d commit 4fcbb74

File tree

5 files changed

+147
-1
lines changed

5 files changed

+147
-1
lines changed

tests/Fixtures/Inputs/TestOnlyConstruct.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@ class TestOnlyConstruct
2424
*/
2525
private $bar;
2626

27-
public function __construct(string $foo, int $bar = 100)
27+
/**
28+
* @Field()
29+
* @var bool
30+
*/
31+
private $baz;
32+
33+
public function __construct(string $foo, bool $baz, int $bar = 100)
2834
{
2935
$this->foo = $foo;
3036
$this->bar = $bar;
37+
$this->baz = $baz;
3138
}
3239

3340
public function setFoo(string $foo): void
@@ -39,6 +46,11 @@ public function setBar(int $bar): void
3946
{
4047
throw new Exception('This should not be called!');
4148
}
49+
50+
public function setBaz(bool $baz): void
51+
{
52+
throw new Exception('This should not be called!');
53+
}
4254

4355
public function getFoo(): string
4456
{
@@ -49,4 +61,9 @@ public function getBar(): int
4961
{
5062
return $this->bar;
5163
}
64+
65+
public function getBaz(): bool
66+
{
67+
return $this->baz;
68+
}
5269
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace TheCodingMachine\GraphQLite\Fixtures\Integration\Controllers;
4+
5+
use TheCodingMachine\GraphQLite\Annotations\Mutation;
6+
use TheCodingMachine\GraphQLite\Fixtures\Integration\Models\Preferences;
7+
8+
class PreferencesController
9+
{
10+
/**
11+
* @Mutation()
12+
* @param Preferences $preferences
13+
*
14+
* @return Preferences
15+
*/
16+
public function updatePreferences(Preferences $preferences): Preferences
17+
{
18+
return $preferences;
19+
}
20+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace TheCodingMachine\GraphQLite\Fixtures\Integration\Models;
4+
5+
use DateTimeInterface;
6+
use TheCodingMachine\GraphQLite\Annotations\Field;
7+
use TheCodingMachine\GraphQLite\Annotations\Input;
8+
use TheCodingMachine\GraphQLite\Annotations\Type;
9+
10+
/**
11+
* @Type()
12+
* @Input()
13+
*/
14+
class Preferences
15+
{
16+
/**
17+
* @Field(inputType="Int!")
18+
* @var int
19+
*/
20+
private $id;
21+
22+
/**
23+
* @Field(inputType="[String!]!")
24+
* @var string[]
25+
*/
26+
private $options;
27+
28+
/**
29+
* @Field(inputType="Boolean!")
30+
* @var bool
31+
*/
32+
private $enabled;
33+
34+
/**
35+
* @Field(inputType="String!")
36+
* @var string
37+
*/
38+
private $name;
39+
40+
public function __construct(int $id, array $options, bool $enabled, string $name)
41+
{
42+
$this->id = $id;
43+
$this->options = $options;
44+
$this->enabled = $enabled;
45+
$this->name = $name;
46+
}
47+
48+
public function getId(): int
49+
{
50+
return $this->id;
51+
}
52+
53+
public function getOptions(): array
54+
{
55+
return $this->options;
56+
}
57+
58+
public function isEnabled(): bool
59+
{
60+
return $this->enabled;
61+
}
62+
63+
public function getName(): string
64+
{
65+
return $this->name;
66+
}
67+
}

tests/Integration/EndToEndTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,46 @@ public function testEndToEndInputAnnotationIssues(): void
20022002
$result->toArray(DebugFlag::RETHROW_INTERNAL_EXCEPTIONS);
20032003
}
20042004

2005+
public function testEndToEndInputEmptyValues(): void
2006+
{
2007+
/**
2008+
* @var Schema $schema
2009+
*/
2010+
$schema = $this->mainContainer->get(Schema::class);
2011+
2012+
$queryString = '
2013+
mutation {
2014+
updatePreferences(
2015+
preferences: {
2016+
id: 0,
2017+
options: [],
2018+
enabled: false,
2019+
name: ""
2020+
}
2021+
) {
2022+
id
2023+
options
2024+
enabled
2025+
name
2026+
}
2027+
}
2028+
';
2029+
2030+
$result = GraphQL::executeQuery(
2031+
$schema,
2032+
$queryString
2033+
);
2034+
2035+
$this->assertSame([
2036+
'updatePreferences' => [
2037+
'id' => 0,
2038+
'options' => [],
2039+
'enabled' => false,
2040+
'name' => '',
2041+
],
2042+
], $this->getSuccessResult($result));
2043+
}
2044+
20052045
public function testEndToEndInputTypeValidation(): void
20062046
{
20072047
$validator = new Validator();

tests/Types/InputTypeTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public function testResolvesCorrectlyWithOnlyConstruct(): void
121121
$input = new InputType(TestOnlyConstruct::class, 'TestOnlyConstructInput', null, false, $this->getFieldsBuilder());
122122

123123
$args = [
124+
'baz' => false,
124125
'foo' => 'Foo',
125126
'bar' => 200,
126127
];
@@ -130,6 +131,7 @@ public function testResolvesCorrectlyWithOnlyConstruct(): void
130131
/** @var TestOnlyConstruct $result */
131132
$result = $input->resolve(null, $args, [], $resolveInfo);
132133

134+
$this->assertEquals(false, $result->getBaz());
133135
$this->assertEquals('Foo', $result->getFoo());
134136
$this->assertEquals(200, $result->getBar());
135137
}

0 commit comments

Comments
 (0)