graphql-php/tests/Validator/UniqueDirectivesPerLocationTest.php

171 lines
4.2 KiB
PHP
Raw Normal View History

<?php
2018-09-02 14:08:49 +03:00
declare(strict_types=1);
namespace GraphQL\Tests\Validator;
use GraphQL\Validator\Rules\UniqueDirectivesPerLocation;
2018-07-29 18:43:10 +03:00
class UniqueDirectivesPerLocationTest extends ValidatorTestCase
{
/**
* @see it('no directives')
*/
public function testNoDirectives() : void
{
2018-09-02 14:08:49 +03:00
$this->expectPassesRule(
new UniqueDirectivesPerLocation(),
'
fragment Test on Type {
field
}
2018-09-02 14:08:49 +03:00
'
);
}
/**
* @see it('unique directives in different locations')
*/
public function testUniqueDirectivesInDifferentLocations() : void
{
2018-09-02 14:08:49 +03:00
$this->expectPassesRule(
new UniqueDirectivesPerLocation(),
'
fragment Test on Type @directiveA {
field @directiveB
}
2018-09-02 14:08:49 +03:00
'
);
}
/**
* @see it('unique directives in same locations')
*/
public function testUniqueDirectivesInSameLocations() : void
{
2018-09-02 14:08:49 +03:00
$this->expectPassesRule(
new UniqueDirectivesPerLocation(),
'
fragment Test on Type @directiveA @directiveB {
field @directiveA @directiveB
}
2018-09-02 14:08:49 +03:00
'
);
}
/**
* @see it('same directives in different locations')
*/
public function testSameDirectivesInDifferentLocations() : void
{
2018-09-02 14:08:49 +03:00
$this->expectPassesRule(
new UniqueDirectivesPerLocation(),
'
fragment Test on Type @directiveA {
field @directiveA
}
2018-09-02 14:08:49 +03:00
'
);
}
/**
* @see it('same directives in similar locations')
*/
public function testSameDirectivesInSimilarLocations() : void
{
2018-09-02 14:08:49 +03:00
$this->expectPassesRule(
new UniqueDirectivesPerLocation(),
'
fragment Test on Type {
field @directive
field @directive
}
2018-09-02 14:08:49 +03:00
'
);
}
/**
* @see it('duplicate directives in one location')
*/
public function testDuplicateDirectivesInOneLocation() : void
{
2018-09-02 14:08:49 +03:00
$this->expectFailsRule(
new UniqueDirectivesPerLocation(),
'
fragment Test on Type {
field @directive @directive
}
2018-09-02 14:08:49 +03:00
',
[$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],
],
];
}
/**
* @see it('many duplicate directives in one location')
*/
public function testManyDuplicateDirectivesInOneLocation() : void
{
2018-09-02 14:08:49 +03:00
$this->expectFailsRule(
new UniqueDirectivesPerLocation(),
'
fragment Test on Type {
field @directive @directive @directive
}
2018-09-02 14:08:49 +03:00
',
[
$this->duplicateDirective('directive', 3, 15, 3, 26),
$this->duplicateDirective('directive', 3, 15, 3, 37),
]
);
}
/**
* @see it('different duplicate directives in one location')
*/
public function testDifferentDuplicateDirectivesInOneLocation() : void
{
2018-09-02 14:08:49 +03:00
$this->expectFailsRule(
new UniqueDirectivesPerLocation(),
'
fragment Test on Type {
field @directiveA @directiveB @directiveA @directiveB
}
2018-09-02 14:08:49 +03:00
',
[
$this->duplicateDirective('directiveA', 3, 15, 3, 39),
$this->duplicateDirective('directiveB', 3, 27, 3, 51),
]
);
}
/**
* @see it('duplicate directives in many locations')
*/
public function testDuplicateDirectivesInManyLocations() : void
{
2018-09-02 14:08:49 +03:00
$this->expectFailsRule(
new UniqueDirectivesPerLocation(),
'
fragment Test on Type @directive @directive {
field @directive @directive
}
2018-09-02 14:08:49 +03:00
',
[
$this->duplicateDirective('directive', 2, 29, 2, 40),
$this->duplicateDirective('directive', 3, 15, 3, 26),
]
2018-09-02 14:08:49 +03:00
);
}
}