2016-11-18 20:21:56 +03:00
|
|
|
<?php
|
|
|
|
namespace GraphQL\Tests\Validator;
|
|
|
|
|
|
|
|
use GraphQL\Validator\Rules\UniqueDirectivesPerLocation;
|
|
|
|
|
2018-07-29 18:43:10 +03:00
|
|
|
class UniqueDirectivesPerLocationTest extends ValidatorTestCase
|
2016-11-18 20:21:56 +03:00
|
|
|
{
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('no directives')
|
2016-11-18 20:21:56 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testNoDirectives() : void
|
2016-11-18 20:21:56 +03:00
|
|
|
{
|
|
|
|
$this->expectPassesRule(new UniqueDirectivesPerLocation(), '
|
|
|
|
fragment Test on Type {
|
|
|
|
field
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('unique directives in different locations')
|
2016-11-18 20:21:56 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testUniqueDirectivesInDifferentLocations() : void
|
2016-11-18 20:21:56 +03:00
|
|
|
{
|
|
|
|
$this->expectPassesRule(new UniqueDirectivesPerLocation(), '
|
|
|
|
fragment Test on Type @directiveA {
|
|
|
|
field @directiveB
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('unique directives in same locations')
|
2016-11-18 20:21:56 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testUniqueDirectivesInSameLocations() : void
|
2016-11-18 20:21:56 +03:00
|
|
|
{
|
|
|
|
$this->expectPassesRule(new UniqueDirectivesPerLocation(), '
|
|
|
|
fragment Test on Type @directiveA @directiveB {
|
|
|
|
field @directiveA @directiveB
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('same directives in different locations')
|
2016-11-18 20:21:56 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testSameDirectivesInDifferentLocations() : void
|
2016-11-18 20:21:56 +03:00
|
|
|
{
|
|
|
|
$this->expectPassesRule(new UniqueDirectivesPerLocation(), '
|
|
|
|
fragment Test on Type @directiveA {
|
|
|
|
field @directiveA
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('same directives in similar locations')
|
2016-11-18 20:21:56 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testSameDirectivesInSimilarLocations() : void
|
2016-11-18 20:21:56 +03:00
|
|
|
{
|
|
|
|
$this->expectPassesRule(new UniqueDirectivesPerLocation(), '
|
|
|
|
fragment Test on Type {
|
|
|
|
field @directive
|
|
|
|
field @directive
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('duplicate directives in one location')
|
2016-11-18 20:21:56 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testDuplicateDirectivesInOneLocation() : void
|
2016-11-18 20:21:56 +03:00
|
|
|
{
|
|
|
|
$this->expectFailsRule(new UniqueDirectivesPerLocation(), '
|
|
|
|
fragment Test on Type {
|
|
|
|
field @directive @directive
|
|
|
|
}
|
|
|
|
', [
|
|
|
|
$this->duplicateDirective('directive', 3, 15, 3, 26)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('many duplicate directives in one location')
|
2016-11-18 20:21:56 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testManyDuplicateDirectivesInOneLocation() : void
|
2016-11-18 20:21:56 +03:00
|
|
|
{
|
|
|
|
$this->expectFailsRule(new UniqueDirectivesPerLocation(), '
|
|
|
|
fragment Test on Type {
|
|
|
|
field @directive @directive @directive
|
|
|
|
}
|
|
|
|
', [
|
|
|
|
$this->duplicateDirective('directive', 3, 15, 3, 26),
|
|
|
|
$this->duplicateDirective('directive', 3, 15, 3, 37)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('different duplicate directives in one location')
|
2016-11-18 20:21:56 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testDifferentDuplicateDirectivesInOneLocation() : void
|
2016-11-18 20:21:56 +03:00
|
|
|
{
|
|
|
|
$this->expectFailsRule(new UniqueDirectivesPerLocation, '
|
|
|
|
fragment Test on Type {
|
|
|
|
field @directiveA @directiveB @directiveA @directiveB
|
|
|
|
}
|
|
|
|
', [
|
|
|
|
$this->duplicateDirective('directiveA', 3, 15, 3, 39),
|
|
|
|
$this->duplicateDirective('directiveB', 3, 27, 3, 51)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('duplicate directives in many locations')
|
2016-11-18 20:21:56 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testDuplicateDirectivesInManyLocations() : void
|
2016-11-18 20:21:56 +03:00
|
|
|
{
|
|
|
|
$this->expectFailsRule(new UniqueDirectivesPerLocation(), '
|
|
|
|
fragment Test on Type @directive @directive {
|
|
|
|
field @directive @directive
|
|
|
|
}
|
|
|
|
', [
|
|
|
|
$this->duplicateDirective('directive', 2, 29, 2, 40),
|
|
|
|
$this->duplicateDirective('directive', 3, 15, 3, 26)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function duplicateDirective($directiveName, $l1, $c1, $l2, $c2)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'message' =>UniqueDirectivesPerLocation::duplicateDirectiveMessage($directiveName),
|
|
|
|
'locations' => [
|
|
|
|
['line' => $l1, 'column' => $c1],
|
|
|
|
['line' => $l2, 'column' => $c2]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|