Skip to content

Commit e182fc9

Browse files
authored
Merge pull request #1073 from sparklink-pro/transformer_fix
Fix tests & arguments transformer when data is not set
2 parents e2fc804 + 8db715d commit e182fc9

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

src/Transformer/ArgumentsTransformer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ private function populateObject(Type $type, $data, bool $multiple, ResolveInfo $
102102
$fields = $type->getFields();
103103

104104
foreach ($fields as $name => $field) {
105+
if (!array_key_exists($name, $data)) {
106+
continue;
107+
}
105108
$fieldData = $this->accessor->getValue($data, sprintf('[%s]', $name));
106109
$fieldType = $field->getType();
107110

tests/Definition/Type/PhpEnumTypeTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ public function testValidParseValue(): void
7474
public function testInvalidSerialize(): void
7575
{
7676
$this->expectException(SerializationError::class);
77-
$this->expectExceptionMessage(sprintf(
78-
'Cannot serialize value Overblog\GraphQLBundle\Tests\Definition\Type\PhpEnumTypeTest as it must be an instance of enum',
79-
));
77+
$this->expectExceptionMessageMatches('/Cannot serialize value (.*) as it must be an instance of enum/');
8078

8179
$this->getEnum()->serialize(self::class);
8280
}

tests/Relay/Connection/ConnectionBuilderTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,13 @@ public function testReturnsAllElementsIfCursorsAreOnTheOutside(): void
271271

272272
public function testReturnsNoElementsIfCursorsCross(): void
273273
{
274-
$actual = call_user_func(
274+
$this->expectException(InvalidArgumentException::class);
275+
$this->expectExceptionMessage('Arguments "before" and "after" cannot be intersected');
276+
call_user_func(
275277
[static::getBuilder(), 'connectionFromArray'],
276278
$this->letters,
277279
['before' => 'YXJyYXljb25uZWN0aW9uOjI=', 'after' => 'YXJyYXljb25uZWN0aW9uOjQ=']
278280
);
279-
280-
$expected = $this->getExpectedConnection([], false, false);
281-
282-
$this->assertSameConnection($expected, $actual);
283281
}
284282

285283
/**

tests/Transformer/ArgumentsTransformerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ public function testPopulating(): void
125125
$this->assertEquals($res->field1, $data['field1']);
126126
$this->assertEquals($res->field2, $data['field2']);
127127
$this->assertEquals($res->field3, $data['field3']);
128+
$this->assertEquals($res->field4, 'default_value_when_not_set_in_data');
129+
$this->assertEquals($res->field5, []);
130+
$this->assertEquals($res->field6, null);
128131

129132
$data = [
130133
'field1' => [

tests/Transformer/InputType1.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,19 @@ final class InputType1
2020
* @var mixed
2121
*/
2222
public $field3;
23+
24+
/**
25+
* @var mixed
26+
*/
27+
public $field4 = 'default_value_when_not_set_in_data';
28+
29+
/**
30+
* @var array
31+
*/
32+
public $field5 = [];
33+
34+
/**
35+
* @var mixed
36+
*/
37+
public $field6;
2338
}

0 commit comments

Comments
 (0)