Skip to content

Commit

Permalink
Add interface implementing interface parser test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingdutch committed Nov 27, 2020
1 parent 8ead4df commit 4eeb883
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions tests/Language/SchemaParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,83 @@ interface Hello {
self::assertEquals($expected, TestUtils::nodeToArray($doc));
}

/**
* @see it('Simple interface inheriting interface')
*/
public function testSimpleInterfaceInheritingInterface() : void
{
$body = 'interface Hello implements World { field: String }';
$doc = Parser::parse($body);
$loc = static function ($start, $end) : array {
return TestUtils::locArray($start, $end);
};

$expected = [
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeKind::INTERFACE_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(10, 15)),
'interfaces' => [
$this->typeNode('World', $loc(27, 32)),
],
'directives' => [],
'fields' => [
$this->fieldNode(
$this->nameNode('field', $loc(35, 40)),
$this->typeNode('String', $loc(42, 48)),
$loc(35, 48)
),
],
'loc' => $loc(0, 50),
'description' => null,
],
],
'loc' => $loc(0, 50),
];

self::assertEquals($expected, TestUtils::nodeToArray($doc));
}

/**
* @see it('Simple interface inheriting multiple interfaces')
*/
public function testSimpleInterfaceInheritingMultipleInterfaces() : void
{
$body = 'interface Hello implements Wo & rld { field: String }';
$doc = Parser::parse($body);
$loc = static function ($start, $end) : array {
return TestUtils::locArray($start, $end);
};

$expected = [
'kind' => NodeKind::DOCUMENT,
'definitions' => [
[
'kind' => NodeKind::INTERFACE_TYPE_DEFINITION,
'name' => $this->nameNode('Hello', $loc(10, 15)),
'interfaces' => [
$this->typeNode('Wo', $loc(27, 29)),
$this->typeNode('rld', $loc(32, 35)),
],
'directives' => [],
'fields' => [
$this->fieldNode(
$this->nameNode('field', $loc(38, 43)),
$this->typeNode('String', $loc(45, 51)),
$loc(38, 51)
),
],
'loc' => $loc(0, 53),
'description' => null,
],
],
'loc' => $loc(0, 53),
];

self::assertEquals($expected, TestUtils::nodeToArray($doc));
}

/**
* @see it('Simple field with arg')
*/
Expand Down

0 comments on commit 4eeb883

Please sign in to comment.