2016-04-25 00:57:09 +03:00
|
|
|
<?php
|
|
|
|
namespace GraphQL\Tests\Validator;
|
|
|
|
|
2016-10-21 12:39:57 +03:00
|
|
|
use GraphQL\Error\FormattedError;
|
2016-04-25 00:57:09 +03:00
|
|
|
use GraphQL\Language\SourceLocation;
|
|
|
|
use GraphQL\Validator\Rules\LoneAnonymousOperation;
|
|
|
|
|
2018-07-29 18:43:10 +03:00
|
|
|
class LoneAnonymousOperationTest extends ValidatorTestCase
|
2016-04-25 00:57:09 +03:00
|
|
|
{
|
|
|
|
// Validate: Anonymous operation must be alone
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it no operations
|
|
|
|
*/
|
|
|
|
public function testNoOperations()
|
|
|
|
{
|
|
|
|
$this->expectPassesRule(new LoneAnonymousOperation, '
|
|
|
|
fragment fragA on Type {
|
|
|
|
field
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it one anon operation
|
|
|
|
*/
|
|
|
|
public function testOneAnonOperation()
|
|
|
|
{
|
|
|
|
$this->expectPassesRule(new LoneAnonymousOperation, '
|
|
|
|
{
|
|
|
|
field
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it multiple named operations
|
|
|
|
*/
|
|
|
|
public function testMultipleNamedOperations()
|
|
|
|
{
|
|
|
|
$this->expectPassesRule(new LoneAnonymousOperation, '
|
|
|
|
query Foo {
|
|
|
|
field
|
|
|
|
}
|
|
|
|
|
|
|
|
query Bar {
|
|
|
|
field
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it anon operation with fragment
|
|
|
|
*/
|
|
|
|
public function testAnonOperationWithFragment()
|
|
|
|
{
|
|
|
|
$this->expectPassesRule(new LoneAnonymousOperation, '
|
|
|
|
{
|
|
|
|
...Foo
|
|
|
|
}
|
|
|
|
fragment Foo on Type {
|
|
|
|
field
|
|
|
|
}
|
|
|
|
');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it multiple anon operations
|
|
|
|
*/
|
|
|
|
public function testMultipleAnonOperations()
|
|
|
|
{
|
|
|
|
$this->expectFailsRule(new LoneAnonymousOperation, '
|
|
|
|
{
|
|
|
|
fieldA
|
|
|
|
}
|
|
|
|
{
|
|
|
|
fieldB
|
|
|
|
}
|
|
|
|
', [
|
|
|
|
$this->anonNotAlone(2, 7),
|
|
|
|
$this->anonNotAlone(5, 7)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it anon operation with a mutation
|
|
|
|
*/
|
|
|
|
public function testAnonOperationWithMutation()
|
|
|
|
{
|
|
|
|
$this->expectFailsRule(new LoneAnonymousOperation, '
|
|
|
|
{
|
|
|
|
fieldA
|
|
|
|
}
|
|
|
|
mutation Foo {
|
|
|
|
fieldB
|
|
|
|
}
|
|
|
|
', [
|
|
|
|
$this->anonNotAlone(2, 7)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @it anon operation with a subscription
|
|
|
|
*/
|
|
|
|
public function testAnonOperationWithSubscription()
|
|
|
|
{
|
|
|
|
$this->expectFailsRule(new LoneAnonymousOperation, '
|
|
|
|
{
|
|
|
|
fieldA
|
|
|
|
}
|
|
|
|
subscription Foo {
|
|
|
|
fieldB
|
|
|
|
}
|
|
|
|
', [
|
|
|
|
$this->anonNotAlone(2, 7)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function anonNotAlone($line, $column)
|
|
|
|
{
|
|
|
|
return FormattedError::create(
|
|
|
|
LoneAnonymousOperation::anonOperationNotAloneMessage(),
|
|
|
|
[new SourceLocation($line, $column)]
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
2018-07-29 18:43:10 +03:00
|
|
|
}
|