2015-07-15 20:05:46 +03:00
|
|
|
<?php
|
2016-04-09 10:36:53 +03:00
|
|
|
namespace GraphQL\Tests\Validator;
|
2015-07-15 20:05:46 +03:00
|
|
|
|
|
|
|
use GraphQL\Validator\Rules\KnownFragmentNames;
|
2016-10-21 12:39:57 +03:00
|
|
|
use GraphQL\Error\FormattedError;
|
2015-07-15 20:05:46 +03:00
|
|
|
use GraphQL\Language\SourceLocation;
|
|
|
|
|
|
|
|
class KnownFragmentNamesTest extends TestCase
|
|
|
|
{
|
|
|
|
// Validate: Known fragment names
|
|
|
|
|
2016-04-25 00:57:09 +03:00
|
|
|
/**
|
|
|
|
* @it known fragment names are valid
|
|
|
|
*/
|
2015-07-15 20:05:46 +03:00
|
|
|
public function testKnownFragmentNamesAreValid()
|
|
|
|
{
|
|
|
|
$this->expectPassesRule(new KnownFragmentNames, '
|
|
|
|
{
|
|
|
|
human(id: 4) {
|
|
|
|
...HumanFields1
|
|
|
|
... on Human {
|
|
|
|
...HumanFields2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fragment HumanFields1 on Human {
|
|
|
|
name
|
|
|
|
...HumanFields3
|
|
|
|
}
|
|
|
|
fragment HumanFields2 on Human {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
fragment HumanFields3 on Human {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
2016-04-25 00:57:09 +03:00
|
|
|
/**
|
|
|
|
* @it unknown fragment names are invalid
|
|
|
|
*/
|
2015-07-15 20:05:46 +03:00
|
|
|
public function testUnknownFragmentNamesAreInvalid()
|
|
|
|
{
|
|
|
|
$this->expectFailsRule(new KnownFragmentNames, '
|
|
|
|
{
|
|
|
|
human(id: 4) {
|
|
|
|
...UnknownFragment1
|
|
|
|
... on Human {
|
|
|
|
...UnknownFragment2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fragment HumanFields on Human {
|
|
|
|
name
|
|
|
|
...UnknownFragment3
|
|
|
|
}
|
|
|
|
', [
|
|
|
|
$this->undefFrag('UnknownFragment1', 4, 14),
|
|
|
|
$this->undefFrag('UnknownFragment2', 6, 16),
|
|
|
|
$this->undefFrag('UnknownFragment3', 12, 12)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function undefFrag($fragName, $line, $column)
|
|
|
|
{
|
2015-08-17 17:01:55 +03:00
|
|
|
return FormattedError::create(
|
|
|
|
KnownFragmentNames::unknownFragmentMessage($fragName),
|
2015-07-15 20:05:46 +03:00
|
|
|
[new SourceLocation($line, $column)]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|