graphql-php/tests/Validator/ExecutableDefinitionsTest.php

90 lines
1.7 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\Error\FormattedError;
use GraphQL\Language\SourceLocation;
use GraphQL\Validator\Rules\ExecutableDefinitions;
2018-07-29 18:43:10 +03:00
class ExecutableDefinitionsTest extends ValidatorTestCase
{
// Validate: Executable definitions
/**
* @see it('with only operation')
*/
public function testWithOnlyOperation() : void
{
2018-09-02 14:08:49 +03:00
$this->expectPassesRule(
new ExecutableDefinitions(),
'
query Foo {
dog {
name
}
}
2018-09-02 14:08:49 +03:00
'
);
}
/**
* @see it('with operation and fragment')
*/
public function testWithOperationAndFragment() : void
{
2018-09-02 14:08:49 +03:00
$this->expectPassesRule(
new ExecutableDefinitions(),
'
query Foo {
dog {
name
...Frag
}
}
fragment Frag on Dog {
name
}
2018-09-02 14:08:49 +03:00
'
);
}
/**
* @see it('with typeDefinition')
*/
public function testWithTypeDefinition() : void
{
2018-09-02 14:08:49 +03:00
$this->expectFailsRule(
new ExecutableDefinitions(),
'
query Foo {
dog {
name
}
}
type Cow {
name: String
}
extend type Dog {
color: String
}
',
[
$this->nonExecutableDefinition('Cow', 8, 12),
$this->nonExecutableDefinition('Dog', 12, 19),
2018-09-02 14:08:49 +03:00
]
);
}
private function nonExecutableDefinition($defName, $line, $column)
{
return FormattedError::create(
ExecutableDefinitions::nonExecutableDefinitionMessage($defName),
2018-09-02 14:08:49 +03:00
[new SourceLocation($line, $column)]
);
}
}