2016-04-25 00:57:09 +03:00
|
|
|
<?php
|
2018-09-02 14:08:49 +03:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-04-25 00:57:09 +03:00
|
|
|
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
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('no operations')
|
2016-04-25 00:57:09 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testNoOperations() : void
|
2016-04-25 00:57:09 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectPassesRule(
|
|
|
|
new LoneAnonymousOperation(),
|
|
|
|
'
|
2016-04-25 00:57:09 +03:00
|
|
|
fragment fragA on Type {
|
|
|
|
field
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
'
|
|
|
|
);
|
2016-04-25 00:57:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('one anon operation')
|
2016-04-25 00:57:09 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testOneAnonOperation() : void
|
2016-04-25 00:57:09 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectPassesRule(
|
|
|
|
new LoneAnonymousOperation(),
|
|
|
|
'
|
2016-04-25 00:57:09 +03:00
|
|
|
{
|
|
|
|
field
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
'
|
|
|
|
);
|
2016-04-25 00:57:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('multiple named operations')
|
2016-04-25 00:57:09 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testMultipleNamedOperations() : void
|
2016-04-25 00:57:09 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectPassesRule(
|
|
|
|
new LoneAnonymousOperation(),
|
|
|
|
'
|
2016-04-25 00:57:09 +03:00
|
|
|
query Foo {
|
|
|
|
field
|
|
|
|
}
|
|
|
|
|
|
|
|
query Bar {
|
|
|
|
field
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
'
|
|
|
|
);
|
2016-04-25 00:57:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('anon operation with fragment')
|
2016-04-25 00:57:09 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAnonOperationWithFragment() : void
|
2016-04-25 00:57:09 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectPassesRule(
|
|
|
|
new LoneAnonymousOperation(),
|
|
|
|
'
|
2016-04-25 00:57:09 +03:00
|
|
|
{
|
|
|
|
...Foo
|
|
|
|
}
|
|
|
|
fragment Foo on Type {
|
|
|
|
field
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
'
|
|
|
|
);
|
2016-04-25 00:57:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('multiple anon operations')
|
2016-04-25 00:57:09 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testMultipleAnonOperations() : void
|
2016-04-25 00:57:09 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectFailsRule(
|
|
|
|
new LoneAnonymousOperation(),
|
|
|
|
'
|
2016-04-25 00:57:09 +03:00
|
|
|
{
|
|
|
|
fieldA
|
|
|
|
}
|
|
|
|
{
|
|
|
|
fieldB
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
',
|
|
|
|
[
|
|
|
|
$this->anonNotAlone(2, 7),
|
|
|
|
$this->anonNotAlone(5, 7),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function anonNotAlone($line, $column)
|
|
|
|
{
|
|
|
|
return FormattedError::create(
|
|
|
|
LoneAnonymousOperation::anonOperationNotAloneMessage(),
|
|
|
|
[new SourceLocation($line, $column)]
|
|
|
|
);
|
2016-04-25 00:57:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('anon operation with a mutation')
|
2016-04-25 00:57:09 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAnonOperationWithMutation() : void
|
2016-04-25 00:57:09 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectFailsRule(
|
|
|
|
new LoneAnonymousOperation(),
|
|
|
|
'
|
2016-04-25 00:57:09 +03:00
|
|
|
{
|
|
|
|
fieldA
|
|
|
|
}
|
|
|
|
mutation Foo {
|
|
|
|
fieldB
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
',
|
|
|
|
[
|
|
|
|
$this->anonNotAlone(2, 7),
|
|
|
|
]
|
|
|
|
);
|
2016-04-25 00:57:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('anon operation with a subscription')
|
2016-04-25 00:57:09 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAnonOperationWithSubscription() : void
|
2016-04-25 00:57:09 +03:00
|
|
|
{
|
2018-09-02 14:08:49 +03:00
|
|
|
$this->expectFailsRule(
|
|
|
|
new LoneAnonymousOperation(),
|
|
|
|
'
|
2016-04-25 00:57:09 +03:00
|
|
|
{
|
|
|
|
fieldA
|
|
|
|
}
|
|
|
|
subscription Foo {
|
|
|
|
fieldB
|
|
|
|
}
|
2018-09-02 14:08:49 +03:00
|
|
|
',
|
|
|
|
[
|
|
|
|
$this->anonNotAlone(2, 7),
|
|
|
|
]
|
2016-04-25 00:57:09 +03:00
|
|
|
);
|
|
|
|
}
|
2018-07-29 18:43:10 +03:00
|
|
|
}
|