2016-04-25 16:29:17 +03:00
|
|
|
<?php
|
2018-09-02 14:08:49 +03:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-04-25 16:29:17 +03:00
|
|
|
namespace GraphQL\Tests\Validator;
|
|
|
|
|
2016-10-21 12:39:57 +03:00
|
|
|
use GraphQL\Error\FormattedError;
|
2016-04-25 16:29:17 +03:00
|
|
|
use GraphQL\Language\SourceLocation;
|
|
|
|
use GraphQL\Validator\Rules\UniqueOperationNames;
|
|
|
|
|
2018-07-29 18:43:10 +03:00
|
|
|
class UniqueOperationNamesTest extends ValidatorTestCase
|
2016-04-25 16:29:17 +03:00
|
|
|
{
|
|
|
|
// Validate: Unique operation names
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('no operations')
|
2016-04-25 16:29:17 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testNoOperations() : void
|
2016-04-25 16:29:17 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectPassesRule(
|
|
|
|
new UniqueOperationNames(),
|
|
|
|
'
|
2016-04-25 16:29:17 +03:00
|
|
|
fragment fragA on Type {
|
|
|
|
field
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
'
|
|
|
|
);
|
2016-04-25 16:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('one anon operation')
|
2016-04-25 16:29:17 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testOneAnonOperation() : void
|
2016-04-25 16:29:17 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectPassesRule(
|
|
|
|
new UniqueOperationNames(),
|
|
|
|
'
|
2016-04-25 16:29:17 +03:00
|
|
|
{
|
|
|
|
field
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
'
|
|
|
|
);
|
2016-04-25 16:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('one named operation')
|
2016-04-25 16:29:17 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testOneNamedOperation() : void
|
2016-04-25 16:29:17 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectPassesRule(
|
|
|
|
new UniqueOperationNames(),
|
|
|
|
'
|
2016-04-25 16:29:17 +03:00
|
|
|
query Foo {
|
|
|
|
field
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
'
|
|
|
|
);
|
2016-04-25 16:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('multiple operations')
|
2016-04-25 16:29:17 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testMultipleOperations() : void
|
2016-04-25 16:29:17 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectPassesRule(
|
|
|
|
new UniqueOperationNames(),
|
|
|
|
'
|
2016-04-25 16:29:17 +03:00
|
|
|
query Foo {
|
|
|
|
field
|
|
|
|
}
|
|
|
|
|
|
|
|
query Bar {
|
|
|
|
field
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
'
|
|
|
|
);
|
2016-04-25 16:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('multiple operations of different types')
|
2016-04-25 16:29:17 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testMultipleOperationsOfDifferentTypes() : void
|
2016-04-25 16:29:17 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectPassesRule(
|
|
|
|
new UniqueOperationNames(),
|
|
|
|
'
|
2016-04-25 16:29:17 +03:00
|
|
|
query Foo {
|
|
|
|
field
|
|
|
|
}
|
|
|
|
|
|
|
|
mutation Bar {
|
|
|
|
field
|
|
|
|
}
|
|
|
|
|
|
|
|
subscription Baz {
|
|
|
|
field
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
'
|
|
|
|
);
|
2016-04-25 16:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('fragment and operation named the same')
|
2016-04-25 16:29:17 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testFragmentAndOperationNamedTheSame() : void
|
2016-04-25 16:29:17 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectPassesRule(
|
|
|
|
new UniqueOperationNames(),
|
|
|
|
'
|
2016-04-25 16:29:17 +03:00
|
|
|
query Foo {
|
|
|
|
...Foo
|
|
|
|
}
|
|
|
|
fragment Foo on Type {
|
|
|
|
field
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
'
|
|
|
|
);
|
2016-04-25 16:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('multiple operations of same name')
|
2016-04-25 16:29:17 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testMultipleOperationsOfSameName() : void
|
2016-04-25 16:29:17 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectFailsRule(
|
|
|
|
new UniqueOperationNames(),
|
|
|
|
'
|
2016-04-25 16:29:17 +03:00
|
|
|
query Foo {
|
|
|
|
fieldA
|
|
|
|
}
|
|
|
|
query Foo {
|
|
|
|
fieldB
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
',
|
|
|
|
[$this->duplicateOp('Foo', 2, 13, 5, 13)]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function duplicateOp($opName, $l1, $c1, $l2, $c2)
|
|
|
|
{
|
|
|
|
return FormattedError::create(
|
|
|
|
UniqueOperationNames::duplicateOperationNameMessage($opName),
|
|
|
|
[new SourceLocation($l1, $c1), new SourceLocation($l2, $c2)]
|
|
|
|
);
|
2016-04-25 16:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('multiple ops of same name of different types (mutation)')
|
2016-04-25 16:29:17 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testMultipleOpsOfSameNameOfDifferentTypesMutation() : void
|
2016-04-25 16:29:17 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectFailsRule(
|
|
|
|
new UniqueOperationNames(),
|
|
|
|
'
|
2016-04-25 16:29:17 +03:00
|
|
|
query Foo {
|
|
|
|
fieldA
|
|
|
|
}
|
|
|
|
mutation Foo {
|
|
|
|
fieldB
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
',
|
|
|
|
[$this->duplicateOp('Foo', 2, 13, 5, 16)]
|
|
|
|
);
|
2016-04-25 16:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('multiple ops of same name of different types (subscription)')
|
2016-04-25 16:29:17 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testMultipleOpsOfSameNameOfDifferentTypesSubscription() : void
|
2016-04-25 16:29:17 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectFailsRule(
|
|
|
|
new UniqueOperationNames(),
|
|
|
|
'
|
2016-04-25 16:29:17 +03:00
|
|
|
query Foo {
|
|
|
|
fieldA
|
|
|
|
}
|
|
|
|
subscription Foo {
|
|
|
|
fieldB
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
',
|
|
|
|
[$this->duplicateOp('Foo', 2, 13, 5, 20)]
|
2016-04-25 16:29:17 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|