|
12 | 12 | use Graphpinator\Typesystem\EnumItem\EnumItem; |
13 | 13 | use Graphpinator\Typesystem\EnumItem\EnumItemSet; |
14 | 14 | use Graphpinator\Typesystem\EnumType; |
| 15 | +use Graphpinator\Typesystem\Exception\ArgumentDefaultValueCycleDetected; |
15 | 16 | use Graphpinator\Typesystem\Exception\ArgumentInvalidTypeUsage; |
16 | 17 | use Graphpinator\Typesystem\Exception\DirectiveIncorrectType; |
17 | 18 | use Graphpinator\Typesystem\Exception\DuplicateNonRepeatableDirective; |
@@ -1405,4 +1406,47 @@ protected function getFieldDefinition() : ArgumentSet |
1405 | 1406 | $this->expectException(NameMustNotStartWithDoubleUnderscore::class); |
1406 | 1407 | $directive->accept(new ValidateIntegrityVisitor()); |
1407 | 1408 | } |
| 1409 | + |
| 1410 | + public function testArgumentDefaultValueCycleDetected() : void |
| 1411 | + { |
| 1412 | + $inputA = new class extends InputType { |
| 1413 | + protected const NAME = 'InputA'; |
| 1414 | + |
| 1415 | + public InputType|null $inputB = null; |
| 1416 | + |
| 1417 | + #[\Override] |
| 1418 | + protected function getFieldDefinition() : ArgumentSet |
| 1419 | + { |
| 1420 | + return new ArgumentSet([ |
| 1421 | + Argument::create('field', $this->inputB) |
| 1422 | + ->setDefaultValue(new \stdClass()), |
| 1423 | + ]); |
| 1424 | + } |
| 1425 | + }; |
| 1426 | + |
| 1427 | + $inputB = new class ($inputA) extends InputType { |
| 1428 | + protected const NAME = 'InputB'; |
| 1429 | + |
| 1430 | + public function __construct( |
| 1431 | + private InputType $inputA, |
| 1432 | + ) |
| 1433 | + { |
| 1434 | + parent::__construct(); |
| 1435 | + } |
| 1436 | + |
| 1437 | + #[\Override] |
| 1438 | + protected function getFieldDefinition() : ArgumentSet |
| 1439 | + { |
| 1440 | + return new ArgumentSet([ |
| 1441 | + Argument::create('field', $this->inputA) |
| 1442 | + ->setDefaultValue(new \stdClass()), |
| 1443 | + ]); |
| 1444 | + } |
| 1445 | + }; |
| 1446 | + |
| 1447 | + $inputA->inputB = $inputB; |
| 1448 | + |
| 1449 | + $this->expectException(ArgumentDefaultValueCycleDetected::class); |
| 1450 | + $inputA->accept(new ValidateIntegrityVisitor()); |
| 1451 | + } |
1408 | 1452 | } |
0 commit comments