mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 06:16:05 +03:00
Fix CS in tests/Utils
This commit is contained in:
parent
ec54d6152b
commit
737da333fb
@ -1,4 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Tests\Utils;
|
||||
|
||||
use GraphQL\Error\Error;
|
||||
@ -9,7 +12,6 @@ use PHPUnit\Framework\TestCase;
|
||||
class AssertValidNameTest extends TestCase
|
||||
{
|
||||
// Describe: assertValidName()
|
||||
|
||||
/**
|
||||
* @see it('throws for use of leading double underscores')
|
||||
*/
|
||||
|
@ -1,4 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Tests\Utils;
|
||||
|
||||
use GraphQL\Language\AST\BooleanValueNode;
|
||||
@ -16,10 +19,12 @@ use GraphQL\Type\Definition\InputObjectType;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
use GraphQL\Utils\AST;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use stdClass;
|
||||
|
||||
class AstFromValueTest extends TestCase
|
||||
{
|
||||
// Describe: astFromValue
|
||||
/** @var stdClass */
|
||||
private $complexValue;
|
||||
|
||||
/**
|
||||
* @see it('converts boolean values to ASTs')
|
||||
@ -31,8 +36,14 @@ class AstFromValueTest extends TestCase
|
||||
$this->assertEquals(new NullValueNode([]), AST::astFromValue(null, Type::boolean()));
|
||||
$this->assertEquals(new BooleanValueNode(['value' => false]), AST::astFromValue(0, Type::boolean()));
|
||||
$this->assertEquals(new BooleanValueNode(['value' => true]), AST::astFromValue(1, Type::boolean()));
|
||||
$this->assertEquals(new BooleanValueNode(['value' => false]), AST::astFromValue(0, Type::nonNull(Type::boolean())));
|
||||
$this->assertEquals(null, AST::astFromValue(null, Type::nonNull(Type::boolean()))); // Note: null means that AST cannot
|
||||
$this->assertEquals(
|
||||
new BooleanValueNode(['value' => false]),
|
||||
AST::astFromValue(0, Type::nonNull(Type::boolean()))
|
||||
);
|
||||
$this->assertEquals(
|
||||
null,
|
||||
AST::astFromValue(null, Type::nonNull(Type::boolean()))
|
||||
); // Note: null means that AST cannot
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +70,10 @@ class AstFromValueTest extends TestCase
|
||||
{
|
||||
$this->expectException(\Throwable::class);
|
||||
$this->expectExceptionMessage('Int cannot represent non 32-bit signed integer value: 1.0E+40');
|
||||
AST::astFromValue(1e40, Type::int()); // Note: js version will produce 1e+40, both values are valid GraphQL floats
|
||||
AST::astFromValue(
|
||||
1e40,
|
||||
Type::int()
|
||||
); // Note: js version will produce 1e+40, both values are valid GraphQL floats
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,7 +135,10 @@ class AstFromValueTest extends TestCase
|
||||
public function testConvertsStringValuesToEnumASTsIfPossible() : void
|
||||
{
|
||||
$this->assertEquals(new EnumValueNode(['value' => 'HELLO']), AST::astFromValue('HELLO', $this->myEnum()));
|
||||
$this->assertEquals(new EnumValueNode(['value' => 'COMPLEX']), AST::astFromValue($this->complexValue(), $this->myEnum()));
|
||||
$this->assertEquals(
|
||||
new EnumValueNode(['value' => 'COMPLEX']),
|
||||
AST::astFromValue($this->complexValue(), $this->myEnum())
|
||||
);
|
||||
|
||||
// Note: case sensitive
|
||||
$this->assertEquals(null, AST::astFromValue('hello', $this->myEnum()));
|
||||
@ -130,92 +147,6 @@ class AstFromValueTest extends TestCase
|
||||
$this->assertEquals(null, AST::astFromValue('VALUE', $this->myEnum()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('converts array values to List ASTs')
|
||||
*/
|
||||
public function testConvertsArrayValuesToListASTs() : void
|
||||
{
|
||||
$value1 = new ListValueNode([
|
||||
'values' => [
|
||||
new StringValueNode(['value' => 'FOO']),
|
||||
new StringValueNode(['value' => 'BAR'])
|
||||
]
|
||||
]);
|
||||
$this->assertEquals($value1, AST::astFromValue(['FOO', 'BAR'], Type::listOf(Type::string())));
|
||||
|
||||
$value2 = new ListValueNode([
|
||||
'values' => [
|
||||
new EnumValueNode(['value' => 'HELLO']),
|
||||
new EnumValueNode(['value' => 'GOODBYE']),
|
||||
]
|
||||
]);
|
||||
$this->assertEquals($value2, AST::astFromValue(['HELLO', 'GOODBYE'], Type::listOf($this->myEnum())));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('converts list singletons')
|
||||
*/
|
||||
public function testConvertsListSingletons() : void
|
||||
{
|
||||
$this->assertEquals(new StringValueNode(['value' => 'FOO']), AST::astFromValue('FOO', Type::listOf(Type::string())));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('converts input objects')
|
||||
*/
|
||||
public function testConvertsInputObjects() : void
|
||||
{
|
||||
$inputObj = new InputObjectType([
|
||||
'name' => 'MyInputObj',
|
||||
'fields' => [
|
||||
'foo' => Type::float(),
|
||||
'bar' => $this->myEnum()
|
||||
]
|
||||
]);
|
||||
|
||||
$expected = new ObjectValueNode([
|
||||
'fields' => [
|
||||
$this->objectField('foo', new IntValueNode(['value' => '3'])),
|
||||
$this->objectField('bar', new EnumValueNode(['value' => 'HELLO']))
|
||||
]
|
||||
]);
|
||||
|
||||
$data = ['foo' => 3, 'bar' => 'HELLO'];
|
||||
$this->assertEquals($expected, AST::astFromValue($data, $inputObj));
|
||||
$this->assertEquals($expected, AST::astFromValue((object) $data, $inputObj));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('converts input objects with explicit nulls')
|
||||
*/
|
||||
public function testConvertsInputObjectsWithExplicitNulls() : void
|
||||
{
|
||||
$inputObj = new InputObjectType([
|
||||
'name' => 'MyInputObj',
|
||||
'fields' => [
|
||||
'foo' => Type::float(),
|
||||
'bar' => $this->myEnum()
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertEquals(new ObjectValueNode([
|
||||
'fields' => [
|
||||
$this->objectField('foo', new NullValueNode([]))
|
||||
]
|
||||
]), AST::astFromValue(['foo' => null], $inputObj));
|
||||
}
|
||||
|
||||
private $complexValue;
|
||||
|
||||
private function complexValue()
|
||||
{
|
||||
if (!$this->complexValue) {
|
||||
$this->complexValue = new \stdClass();
|
||||
$this->complexValue->someArbitrary = 'complexValue';
|
||||
}
|
||||
return $this->complexValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EnumType
|
||||
*/
|
||||
@ -226,21 +157,111 @@ class AstFromValueTest extends TestCase
|
||||
'values' => [
|
||||
'HELLO' => [],
|
||||
'GOODBYE' => [],
|
||||
'COMPLEX' => ['value' => $this->complexValue()]
|
||||
]
|
||||
'COMPLEX' => ['value' => $this->complexValue()],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
private function complexValue()
|
||||
{
|
||||
if (! $this->complexValue) {
|
||||
$this->complexValue = new \stdClass();
|
||||
$this->complexValue->someArbitrary = 'complexValue';
|
||||
}
|
||||
|
||||
return $this->complexValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('converts array values to List ASTs')
|
||||
*/
|
||||
public function testConvertsArrayValuesToListASTs() : void
|
||||
{
|
||||
$value1 = new ListValueNode([
|
||||
'values' => [
|
||||
new StringValueNode(['value' => 'FOO']),
|
||||
new StringValueNode(['value' => 'BAR']),
|
||||
],
|
||||
]);
|
||||
$this->assertEquals($value1, AST::astFromValue(['FOO', 'BAR'], Type::listOf(Type::string())));
|
||||
|
||||
$value2 = new ListValueNode([
|
||||
'values' => [
|
||||
new EnumValueNode(['value' => 'HELLO']),
|
||||
new EnumValueNode(['value' => 'GOODBYE']),
|
||||
],
|
||||
]);
|
||||
$this->assertEquals($value2, AST::astFromValue(['HELLO', 'GOODBYE'], Type::listOf($this->myEnum())));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('converts list singletons')
|
||||
*/
|
||||
public function testConvertsListSingletons() : void
|
||||
{
|
||||
$this->assertEquals(
|
||||
new StringValueNode(['value' => 'FOO']),
|
||||
AST::astFromValue('FOO', Type::listOf(Type::string()))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('converts input objects')
|
||||
*/
|
||||
public function testConvertsInputObjects() : void
|
||||
{
|
||||
$inputObj = new InputObjectType([
|
||||
'name' => 'MyInputObj',
|
||||
'fields' => [
|
||||
'foo' => Type::float(),
|
||||
'bar' => $this->myEnum(),
|
||||
],
|
||||
]);
|
||||
|
||||
$expected = new ObjectValueNode([
|
||||
'fields' => [
|
||||
$this->objectField('foo', new IntValueNode(['value' => '3'])),
|
||||
$this->objectField('bar', new EnumValueNode(['value' => 'HELLO'])),
|
||||
],
|
||||
]);
|
||||
|
||||
$data = ['foo' => 3, 'bar' => 'HELLO'];
|
||||
$this->assertEquals($expected, AST::astFromValue($data, $inputObj));
|
||||
$this->assertEquals($expected, AST::astFromValue((object) $data, $inputObj));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @return ObjectFieldNode
|
||||
*/
|
||||
private function objectField(string $name, $value)
|
||||
{
|
||||
return new ObjectFieldNode([
|
||||
'name' => new NameNode(['value' => $name]),
|
||||
'value' => $value,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $value
|
||||
* @return ObjectFieldNode
|
||||
* @see it('converts input objects with explicit nulls')
|
||||
*/
|
||||
private function objectField($name, $value)
|
||||
public function testConvertsInputObjectsWithExplicitNulls() : void
|
||||
{
|
||||
return new ObjectFieldNode([
|
||||
'name' => new NameNode(['value' => $name]),
|
||||
'value' => $value
|
||||
$inputObj = new InputObjectType([
|
||||
'name' => 'MyInputObj',
|
||||
'fields' => [
|
||||
'foo' => Type::float(),
|
||||
'bar' => $this->myEnum(),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(
|
||||
new ObjectValueNode([
|
||||
'fields' => [
|
||||
$this->objectField('foo', new NullValueNode([])),
|
||||
],
|
||||
]),
|
||||
AST::astFromValue(['foo' => null], $inputObj)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Tests\Utils;
|
||||
|
||||
use GraphQL\Language\Parser;
|
||||
@ -8,14 +11,6 @@ use PHPUnit\Framework\TestCase;
|
||||
class AstFromValueUntypedTest extends TestCase
|
||||
{
|
||||
// Describe: valueFromASTUntyped
|
||||
|
||||
private function assertTestCase($valueText, $expected, array $variables = null) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
AST::valueFromASTUntyped(Parser::parseValue($valueText), $variables)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('parses simple values')
|
||||
*/
|
||||
@ -29,6 +24,17 @@ class AstFromValueUntypedTest extends TestCase
|
||||
$this->assertTestCase('abc123', 'abc123');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[]|null $variables
|
||||
*/
|
||||
private function assertTestCase($valueText, $expected, ?array $variables = null) : void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
AST::valueFromASTUntyped(Parser::parseValue($valueText), $variables)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('parses lists of values')
|
||||
*/
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Tests\Utils;
|
||||
|
||||
use GraphQL\Error\Error;
|
||||
@ -8,24 +11,19 @@ use GraphQL\Language\AST\InterfaceTypeDefinitionNode;
|
||||
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
|
||||
use GraphQL\Language\Parser;
|
||||
use GraphQL\Language\Printer;
|
||||
use GraphQL\Type\Definition\Directive;
|
||||
use GraphQL\Type\Definition\EnumType;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Utils\BuildSchema;
|
||||
use GraphQL\Utils\SchemaPrinter;
|
||||
use GraphQL\Type\Definition\Directive;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use function array_keys;
|
||||
use function count;
|
||||
|
||||
class BuildSchemaTest extends TestCase
|
||||
{
|
||||
// Describe: Schema Builder
|
||||
|
||||
private function cycleOutput($body, $options = [])
|
||||
{
|
||||
$ast = Parser::parse($body);
|
||||
$schema = BuildSchema::buildAST($ast, null, $options);
|
||||
return "\n" . SchemaPrinter::doPrint($schema, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('can use built schema for limited execution')
|
||||
*/
|
||||
@ -46,16 +44,16 @@ class BuildSchemaTest extends TestCase
|
||||
*/
|
||||
public function testBuildSchemaDirectlyFromSource() : void
|
||||
{
|
||||
$schema = BuildSchema::build("
|
||||
$schema = BuildSchema::build('
|
||||
type Query {
|
||||
add(x: Int, y: Int): Int
|
||||
}
|
||||
");
|
||||
');
|
||||
|
||||
$root = [
|
||||
'add' => function ($root, $args) {
|
||||
return $args['x'] + $args['y'];
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
$result = GraphQL::executeQuery(
|
||||
@ -84,6 +82,14 @@ type HelloScalars {
|
||||
$this->assertEquals($output, $body);
|
||||
}
|
||||
|
||||
private function cycleOutput($body, $options = [])
|
||||
{
|
||||
$ast = Parser::parse($body);
|
||||
$schema = BuildSchema::buildAST($ast, null, $options);
|
||||
|
||||
return "\n" . SchemaPrinter::doPrint($schema, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('With directives')
|
||||
*/
|
||||
@ -467,16 +473,16 @@ type WorldTwo {
|
||||
[
|
||||
'length' => 5,
|
||||
'__typename' => 'Banana',
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
$expected = [
|
||||
'data' => [
|
||||
'fruits' => [
|
||||
['color' => 'green'],
|
||||
['length' => 5],
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$result = GraphQL::executeQuery($schema, $query, $root);
|
||||
@ -531,16 +537,16 @@ type WorldTwo {
|
||||
'name' => 'R2-D2',
|
||||
'primaryFunction' => 'Astromech',
|
||||
'__typename' => 'Droid',
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
$expected = [
|
||||
'data' => [
|
||||
'characters' => [
|
||||
['name' => 'Han Solo', 'totalCredits' => 10],
|
||||
['name' => 'R2-D2', 'primaryFunction' => 'Astromech'],
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$result = GraphQL::executeQuery($schema, $query, $root);
|
||||
@ -813,9 +819,15 @@ type Query {
|
||||
$testField = $query->getField('testField');
|
||||
$this->assertEquals('testField(testArg: TestInput): TestUnion', Printer::doPrint($testField->astNode));
|
||||
$this->assertEquals('testArg: TestInput', Printer::doPrint($testField->args[0]->astNode));
|
||||
$this->assertEquals('testInputField: TestEnum', Printer::doPrint($testInput->getField('testInputField')->astNode));
|
||||
$this->assertEquals(
|
||||
'testInputField: TestEnum',
|
||||
Printer::doPrint($testInput->getField('testInputField')->astNode)
|
||||
);
|
||||
$this->assertEquals('TEST_VALUE', Printer::doPrint($testEnum->getValue('TEST_VALUE')->astNode));
|
||||
$this->assertEquals('interfaceField: String', Printer::doPrint($testInterface->getField('interfaceField')->astNode));
|
||||
$this->assertEquals(
|
||||
'interfaceField: String',
|
||||
Printer::doPrint($testInterface->getField('interfaceField')->astNode)
|
||||
);
|
||||
$this->assertEquals('interfaceField: String', Printer::doPrint($testType->getField('interfaceField')->astNode));
|
||||
$this->assertEquals('arg: TestScalar', Printer::doPrint($testDirective->args[0]->astNode));
|
||||
}
|
||||
@ -1187,6 +1199,7 @@ interface Hello {
|
||||
$typeConfigDecorator = function ($defaultConfig, $node, $allNodesMap) use (&$decorated, &$calls) {
|
||||
$decorated[] = $defaultConfig['name'];
|
||||
$calls[] = [$defaultConfig, $node, $allNodesMap];
|
||||
|
||||
return ['description' => 'My description of ' . $node->name->value] + $defaultConfig;
|
||||
};
|
||||
|
||||
@ -1204,19 +1217,21 @@ interface Hello {
|
||||
$this->assertEquals(array_keys($allNodesMap), ['Query', 'Color', 'Hello']);
|
||||
$this->assertEquals('My description of Query', $schema->getType('Query')->description);
|
||||
|
||||
|
||||
list($defaultConfig, $node, $allNodesMap) = $calls[1];
|
||||
$this->assertInstanceOf(EnumTypeDefinitionNode::class, $node);
|
||||
$this->assertEquals('Color', $defaultConfig['name']);
|
||||
$enumValue = [
|
||||
'description' => '',
|
||||
'deprecationReason' => ''
|
||||
'deprecationReason' => '',
|
||||
];
|
||||
$this->assertArraySubset([
|
||||
$this->assertArraySubset(
|
||||
[
|
||||
'RED' => $enumValue,
|
||||
'GREEN' => $enumValue,
|
||||
'BLUE' => $enumValue,
|
||||
], $defaultConfig['values']);
|
||||
],
|
||||
$defaultConfig['values']
|
||||
);
|
||||
$this->assertCount(4, $defaultConfig); // 3 + astNode
|
||||
$this->assertEquals(array_keys($allNodesMap), ['Query', 'Color', 'Hello']);
|
||||
$this->assertEquals('My description of Color', $schema->getType('Color')->description);
|
||||
@ -1263,6 +1278,7 @@ type World implements Hello {
|
||||
|
||||
$typeConfigDecorator = function ($config, $node) use (&$created) {
|
||||
$created[] = $node->name->value;
|
||||
|
||||
return $config;
|
||||
};
|
||||
|
||||
@ -1282,5 +1298,4 @@ type World implements Hello {
|
||||
$this->assertArrayHasKey('Hello', $types);
|
||||
$this->assertArrayHasKey('World', $types);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Tests\Utils;
|
||||
|
||||
use GraphQL\Error\Error;
|
||||
use GraphQL\Executor\Values;
|
||||
use GraphQL\Type\Definition\EnumType;
|
||||
use GraphQL\Type\Definition\InputObjectType;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
@ -12,7 +13,10 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CoerceValueTest extends TestCase
|
||||
{
|
||||
/** @var EnumType */
|
||||
private $testEnum;
|
||||
|
||||
/** @var InputObjectType */
|
||||
private $testInputObject;
|
||||
|
||||
public function setUp()
|
||||
@ -34,9 +38,9 @@ class CoerceValueTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
// Describe: coerceValue
|
||||
|
||||
/**
|
||||
* Describe: coerceValue
|
||||
*
|
||||
* @see it('coercing an array to GraphQLString produces an error')
|
||||
*/
|
||||
public function testCoercingAnArrayToGraphQLStringProducesAnError() : void
|
||||
@ -53,7 +57,17 @@ class CoerceValueTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
// Describe: for GraphQLInt
|
||||
/**
|
||||
* Describe: for GraphQLInt
|
||||
*/
|
||||
private function expectError($result, $expected)
|
||||
{
|
||||
$this->assertInternalType('array', $result);
|
||||
$this->assertInternalType('array', $result['errors']);
|
||||
$this->assertCount(1, $result['errors']);
|
||||
$this->assertEquals($expected, $result['errors'][0]->getMessage());
|
||||
$this->assertEquals(Utils::undefined(), $result['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('returns no error for int input')
|
||||
@ -64,6 +78,13 @@ class CoerceValueTest extends TestCase
|
||||
$this->expectNoErrors($result);
|
||||
}
|
||||
|
||||
private function expectNoErrors($result)
|
||||
{
|
||||
$this->assertInternalType('array', $result);
|
||||
$this->assertNull($result['errors']);
|
||||
$this->assertNotEquals(Utils::undefined(), $result['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('returns no error for negative int input')
|
||||
*/
|
||||
@ -115,6 +136,8 @@ class CoerceValueTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
// Describe: for GraphQLFloat
|
||||
|
||||
/**
|
||||
* @see it('returns a single error for char input')
|
||||
*/
|
||||
@ -139,8 +162,6 @@ class CoerceValueTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
// Describe: for GraphQLFloat
|
||||
|
||||
/**
|
||||
* @see it('returns no error for int input')
|
||||
*/
|
||||
@ -189,6 +210,8 @@ class CoerceValueTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
// DESCRIBE: for GraphQLEnum
|
||||
|
||||
/**
|
||||
* @see it('returns a single error for char input')
|
||||
*/
|
||||
@ -213,8 +236,6 @@ class CoerceValueTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
// DESCRIBE: for GraphQLEnum
|
||||
|
||||
/**
|
||||
* @see it('returns no error for a known enum name')
|
||||
*/
|
||||
@ -229,6 +250,8 @@ class CoerceValueTest extends TestCase
|
||||
$this->assertEquals(123456789, $barResult['value']);
|
||||
}
|
||||
|
||||
// DESCRIBE: for GraphQLInputObject
|
||||
|
||||
/**
|
||||
* @see it('results error for misspelled enum value')
|
||||
*/
|
||||
@ -250,8 +273,6 @@ class CoerceValueTest extends TestCase
|
||||
$this->expectError($result2, 'Expected type TestEnum.');
|
||||
}
|
||||
|
||||
// DESCRIBE: for GraphQLInputObject
|
||||
|
||||
/**
|
||||
* @see it('returns no error for a valid input')
|
||||
*/
|
||||
@ -277,7 +298,10 @@ class CoerceValueTest extends TestCase
|
||||
public function testReturnErrorForAnInvalidField() : void
|
||||
{
|
||||
$result = Value::coerceValue(['foo' => 'abc'], $this->testInputObject);
|
||||
$this->expectError($result, 'Expected type Int at value.foo; Int cannot represent non 32-bit signed integer value: abc');
|
||||
$this->expectError(
|
||||
$result,
|
||||
'Expected type Int at value.foo; Int cannot represent non 32-bit signed integer value: abc'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -286,10 +310,13 @@ class CoerceValueTest extends TestCase
|
||||
public function testReturnsMultipleErrorsForMultipleInvalidFields() : void
|
||||
{
|
||||
$result = Value::coerceValue(['foo' => 'abc', 'bar' => 'def'], $this->testInputObject);
|
||||
$this->assertEquals([
|
||||
$this->assertEquals(
|
||||
[
|
||||
'Expected type Int at value.foo; Int cannot represent non 32-bit signed integer value: abc',
|
||||
'Expected type Int at value.bar; Int cannot represent non 32-bit signed integer value: def',
|
||||
], $result['errors']);
|
||||
],
|
||||
$result['errors']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -318,20 +345,4 @@ class CoerceValueTest extends TestCase
|
||||
$result = Value::coerceValue(['foo' => 123, 'bart' => 123], $this->testInputObject);
|
||||
$this->expectError($result, 'Field "bart" is not defined by type TestInputObject; did you mean bar?');
|
||||
}
|
||||
|
||||
private function expectNoErrors($result)
|
||||
{
|
||||
$this->assertInternalType('array', $result);
|
||||
$this->assertNull($result['errors']);
|
||||
$this->assertNotEquals(Utils::undefined(), $result['value']);
|
||||
}
|
||||
|
||||
|
||||
private function expectError($result, $expected) {
|
||||
$this->assertInternalType('array', $result);
|
||||
$this->assertInternalType('array', $result['errors']);
|
||||
$this->assertCount(1, $result['errors']);
|
||||
$this->assertEquals($expected, $result['errors'][0]->getMessage());
|
||||
$this->assertEquals(Utils::undefined(), $result['value']);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
namespace Utils;
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Tests\Utils;
|
||||
|
||||
use GraphQL\Error\InvariantViolation;
|
||||
use GraphQL\Type\Definition\InputObjectType;
|
||||
@ -12,72 +15,43 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ExtractTypesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectType
|
||||
*/
|
||||
/** @var ObjectType */
|
||||
private $query;
|
||||
|
||||
/**
|
||||
* @var ObjectType
|
||||
*/
|
||||
/** @var ObjectType */
|
||||
private $mutation;
|
||||
|
||||
/**
|
||||
* @var InterfaceType
|
||||
*/
|
||||
/** @var InterfaceType */
|
||||
private $node;
|
||||
|
||||
/**
|
||||
* @var InterfaceType
|
||||
*/
|
||||
/** @var InterfaceType */
|
||||
private $content;
|
||||
|
||||
/**
|
||||
* @var ObjectType
|
||||
*/
|
||||
/** @var ObjectType */
|
||||
private $blogStory;
|
||||
|
||||
/**
|
||||
* @var ObjectType
|
||||
*/
|
||||
private $link;
|
||||
|
||||
/**
|
||||
* @var ObjectType
|
||||
*/
|
||||
private $video;
|
||||
|
||||
/**
|
||||
* @var ObjectType
|
||||
*/
|
||||
private $videoMetadata;
|
||||
|
||||
/**
|
||||
* @var ObjectType
|
||||
*/
|
||||
/** @var ObjectType */
|
||||
private $comment;
|
||||
|
||||
/**
|
||||
* @var ObjectType
|
||||
*/
|
||||
/** @var ObjectType */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @var ObjectType
|
||||
*/
|
||||
/** @var ObjectType */
|
||||
private $category;
|
||||
|
||||
/**
|
||||
* @var UnionType
|
||||
*/
|
||||
/** @var UnionType */
|
||||
private $mention;
|
||||
|
||||
/** @var ObjectType */
|
||||
private $postStoryMutation;
|
||||
|
||||
/** @var InputObjectType */
|
||||
private $postStoryMutationInput;
|
||||
|
||||
/** @var ObjectType */
|
||||
private $postCommentMutation;
|
||||
|
||||
/** @var InputObjectType */
|
||||
private $postCommentMutationInput;
|
||||
|
||||
public function setUp()
|
||||
@ -85,8 +59,8 @@ class ExtractTypesTest extends TestCase
|
||||
$this->node = new InterfaceType([
|
||||
'name' => 'Node',
|
||||
'fields' => [
|
||||
'id' => Type::string()
|
||||
]
|
||||
'id' => Type::string(),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->content = new InterfaceType([
|
||||
@ -97,16 +71,16 @@ class ExtractTypesTest extends TestCase
|
||||
'body' => Type::string(),
|
||||
'author' => $this->user,
|
||||
'comments' => Type::listOf($this->comment),
|
||||
'categories' => Type::listOf($this->category)
|
||||
'categories' => Type::listOf($this->category),
|
||||
];
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
$this->blogStory = new ObjectType([
|
||||
'name' => 'BlogStory',
|
||||
'interfaces' => [
|
||||
$this->node,
|
||||
$this->content
|
||||
$this->content,
|
||||
],
|
||||
'fields' => function () {
|
||||
return [
|
||||
@ -115,106 +89,106 @@ class ExtractTypesTest extends TestCase
|
||||
$this->content->getField('body'),
|
||||
$this->content->getField('author'),
|
||||
$this->content->getField('comments'),
|
||||
$this->content->getField('categories')
|
||||
$this->content->getField('categories'),
|
||||
];
|
||||
},
|
||||
]);
|
||||
|
||||
$this->link = new ObjectType([
|
||||
new ObjectType([
|
||||
'name' => 'Link',
|
||||
'interfaces' => [
|
||||
$this->node,
|
||||
$this->content
|
||||
$this->content,
|
||||
],
|
||||
'fields' => function () {
|
||||
return [
|
||||
$this->node->getField('id'),
|
||||
$this->content->getField('title'),
|
||||
$this->content->getField('body'),
|
||||
$this->content->getField('author'),
|
||||
$this->content->getField('comments'),
|
||||
$this->content->getField('categories'),
|
||||
'url' => Type::string()
|
||||
'id' => $this->node->getField('id'),
|
||||
'title' => $this->content->getField('title'),
|
||||
'body' => $this->content->getField('body'),
|
||||
'author' => $this->content->getField('author'),
|
||||
'comments' => $this->content->getField('comments'),
|
||||
'categories' => $this->content->getField('categories'),
|
||||
'url' => Type::string(),
|
||||
];
|
||||
},
|
||||
]);
|
||||
|
||||
$this->video = new ObjectType([
|
||||
new ObjectType([
|
||||
'name' => 'Video',
|
||||
'interfaces' => [
|
||||
$this->node,
|
||||
$this->content
|
||||
$this->content,
|
||||
],
|
||||
'fields' => function () {
|
||||
return [
|
||||
$this->node->getField('id'),
|
||||
$this->content->getField('title'),
|
||||
$this->content->getField('body'),
|
||||
$this->content->getField('author'),
|
||||
$this->content->getField('comments'),
|
||||
$this->content->getField('categories'),
|
||||
'id' => $this->node->getField('id'),
|
||||
'title' => $this->content->getField('title'),
|
||||
'body' => $this->content->getField('body'),
|
||||
'author' => $this->content->getField('author'),
|
||||
'comments' => $this->content->getField('comments'),
|
||||
'categories' => $this->content->getField('categories'),
|
||||
'streamUrl' => Type::string(),
|
||||
'downloadUrl' => Type::string(),
|
||||
'metadata' => $this->videoMetadata = new ObjectType([
|
||||
'metadata' => new ObjectType([
|
||||
'name' => 'VideoMetadata',
|
||||
'fields' => [
|
||||
'lat' => Type::float(),
|
||||
'lng' => Type::float()
|
||||
]
|
||||
])
|
||||
'lng' => Type::float(),
|
||||
],
|
||||
]),
|
||||
];
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
$this->comment = new ObjectType([
|
||||
'name' => 'Comment',
|
||||
'interfaces' => [
|
||||
$this->node
|
||||
$this->node,
|
||||
],
|
||||
'fields' => function () {
|
||||
return [
|
||||
$this->node->getField('id'),
|
||||
'id' => $this->node->getField('id'),
|
||||
'author' => $this->user,
|
||||
'text' => Type::string(),
|
||||
'replies' => Type::listOf($this->comment),
|
||||
'parent' => $this->comment,
|
||||
'content' => $this->content
|
||||
'content' => $this->content,
|
||||
];
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
$this->user = new ObjectType([
|
||||
'name' => 'User',
|
||||
'interfaces' => [
|
||||
$this->node
|
||||
$this->node,
|
||||
],
|
||||
'fields' => function () {
|
||||
return [
|
||||
$this->node->getField('id'),
|
||||
'id' => $this->node->getField('id'),
|
||||
'name' => Type::string(),
|
||||
];
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
$this->category = new ObjectType([
|
||||
'name' => 'Category',
|
||||
'interfaces' => [
|
||||
$this->node
|
||||
$this->node,
|
||||
],
|
||||
'fields' => function () {
|
||||
return [
|
||||
$this->node->getField('id'),
|
||||
'name' => Type::string()
|
||||
'id' => $this->node->getField('id'),
|
||||
'name' => Type::string(),
|
||||
];
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
$this->mention = new UnionType([
|
||||
'name' => 'Mention',
|
||||
'types' => [
|
||||
$this->user,
|
||||
$this->category
|
||||
]
|
||||
$this->category,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->query = new ObjectType([
|
||||
@ -223,8 +197,18 @@ class ExtractTypesTest extends TestCase
|
||||
'viewer' => $this->user,
|
||||
'latestContent' => $this->content,
|
||||
'node' => $this->node,
|
||||
'mentions' => Type::listOf($this->mention)
|
||||
]
|
||||
'mentions' => Type::listOf($this->mention),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->postStoryMutationInput = new InputObjectType([
|
||||
'name' => 'PostStoryMutationInput',
|
||||
'fields' => [
|
||||
'title' => Type::string(),
|
||||
'body' => Type::string(),
|
||||
'author' => Type::id(),
|
||||
'category' => Type::id(),
|
||||
],
|
||||
]);
|
||||
|
||||
$this->mutation = new ObjectType([
|
||||
@ -234,28 +218,20 @@ class ExtractTypesTest extends TestCase
|
||||
'type' => $this->postStoryMutation = new ObjectType([
|
||||
'name' => 'PostStoryMutation',
|
||||
'fields' => [
|
||||
'story' => $this->blogStory
|
||||
]
|
||||
'story' => $this->blogStory,
|
||||
],
|
||||
]),
|
||||
'args' => [
|
||||
'input' => Type::nonNull($this->postStoryMutationInput = new InputObjectType([
|
||||
'name' => 'PostStoryMutationInput',
|
||||
'fields' => [
|
||||
'title' => Type::string(),
|
||||
'body' => Type::string(),
|
||||
'author' => Type::id(),
|
||||
'category' => Type::id()
|
||||
]
|
||||
])),
|
||||
'clientRequestId' => Type::string()
|
||||
]
|
||||
'input' => Type::nonNull($this->postStoryMutationInput),
|
||||
'clientRequestId' => Type::string(),
|
||||
],
|
||||
],
|
||||
'postComment' => [
|
||||
'type' => $this->postCommentMutation = new ObjectType([
|
||||
'name' => 'PostCommentMutation',
|
||||
'fields' => [
|
||||
'comment' => $this->comment
|
||||
]
|
||||
'comment' => $this->comment,
|
||||
],
|
||||
]),
|
||||
'args' => [
|
||||
'input' => Type::nonNull($this->postCommentMutationInput = new InputObjectType([
|
||||
@ -264,13 +240,13 @@ class ExtractTypesTest extends TestCase
|
||||
'text' => Type::nonNull(Type::string()),
|
||||
'author' => Type::nonNull(Type::id()),
|
||||
'content' => Type::id(),
|
||||
'parent' => Type::id()
|
||||
]
|
||||
'parent' => Type::id(),
|
||||
],
|
||||
])),
|
||||
'clientRequestId' => Type::string()
|
||||
]
|
||||
]
|
||||
]
|
||||
'clientRequestId' => Type::string(),
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
@ -317,15 +293,15 @@ class ExtractTypesTest extends TestCase
|
||||
{
|
||||
$otherUserType = new ObjectType([
|
||||
'name' => 'User',
|
||||
'fields' => ['a' => Type::string()]
|
||||
'fields' => ['a' => Type::string()],
|
||||
]);
|
||||
|
||||
$queryType = new ObjectType([
|
||||
'name' => 'Test',
|
||||
'fields' => [
|
||||
'otherUser' => $otherUserType,
|
||||
'user' => $this->user
|
||||
]
|
||||
'user' => $this->user,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->expectException(InvariantViolation::class);
|
||||
|
@ -1,17 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Tests\Utils;
|
||||
|
||||
use GraphQL\Language\Parser;
|
||||
use GraphQL\Language\SourceLocation;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
use GraphQL\Utils\Utils;
|
||||
use GraphQL\Validator\DocumentValidator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class IsValidLiteralValueTest extends TestCase
|
||||
{
|
||||
// DESCRIBE: isValidLiteralValue
|
||||
|
||||
/**
|
||||
* @see it('Returns no errors for a valid value')
|
||||
*/
|
||||
|
@ -1,16 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Tests\Utils;
|
||||
|
||||
|
||||
use GraphQL\Utils\Utils;
|
||||
use GraphQL\Utils\MixedStore;
|
||||
use GraphQL\Utils\Utils;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class MixedStoreTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var MixedStore
|
||||
*/
|
||||
/** @var MixedStore */
|
||||
private $mixedStore;
|
||||
|
||||
public function setUp()
|
||||
@ -18,6 +18,13 @@ class MixedStoreTest extends TestCase
|
||||
$this->mixedStore = new MixedStore();
|
||||
}
|
||||
|
||||
public function testAcceptsNullKeys() : void
|
||||
{
|
||||
foreach ($this->getPossibleValues() as $value) {
|
||||
$this->assertAcceptsKeyValue(null, $value);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPossibleValues()
|
||||
{
|
||||
return [
|
||||
@ -30,16 +37,38 @@ class MixedStoreTest extends TestCase
|
||||
'a',
|
||||
[],
|
||||
new \stdClass(),
|
||||
function() {},
|
||||
new MixedStore()
|
||||
function () {
|
||||
},
|
||||
new MixedStore(),
|
||||
];
|
||||
}
|
||||
|
||||
public function testAcceptsNullKeys() : void
|
||||
private function assertAcceptsKeyValue($key, $value)
|
||||
{
|
||||
foreach ($this->getPossibleValues() as $value) {
|
||||
$this->assertAcceptsKeyValue(null, $value);
|
||||
$err = 'Failed assertion that MixedStore accepts key ' .
|
||||
Utils::printSafe($key) . ' with value ' . Utils::printSafe($value);
|
||||
|
||||
$this->assertFalse($this->mixedStore->offsetExists($key), $err);
|
||||
$this->mixedStore->offsetSet($key, $value);
|
||||
$this->assertTrue($this->mixedStore->offsetExists($key), $err);
|
||||
$this->assertSame($value, $this->mixedStore->offsetGet($key), $err);
|
||||
$this->mixedStore->offsetUnset($key);
|
||||
$this->assertFalse($this->mixedStore->offsetExists($key), $err);
|
||||
$this->assertProvidesArrayAccess($key, $value);
|
||||
}
|
||||
|
||||
private function assertProvidesArrayAccess($key, $value)
|
||||
{
|
||||
$err = 'Failed assertion that MixedStore provides array access for key ' .
|
||||
Utils::printSafe($key) . ' with value ' . Utils::printSafe($value);
|
||||
|
||||
$this->assertFalse(isset($this->mixedStore[$key]), $err);
|
||||
$this->mixedStore[$key] = $value;
|
||||
$this->assertTrue(isset($this->mixedStore[$key]), $err);
|
||||
$this->assertEquals(! empty($value), ! empty($this->mixedStore[$key]), $err);
|
||||
$this->assertSame($value, $this->mixedStore[$key], $err);
|
||||
unset($this->mixedStore[$key]);
|
||||
$this->assertFalse(isset($this->mixedStore[$key]), $err);
|
||||
}
|
||||
|
||||
public function testAcceptsBoolKeys() : void
|
||||
@ -93,35 +122,11 @@ class MixedStoreTest extends TestCase
|
||||
foreach ($this->getPossibleValues() as $value) {
|
||||
$this->assertAcceptsKeyValue(new \stdClass(), $value);
|
||||
$this->assertAcceptsKeyValue(new MixedStore(), $value);
|
||||
$this->assertAcceptsKeyValue(function() {}, $value);
|
||||
$this->assertAcceptsKeyValue(
|
||||
function () {
|
||||
},
|
||||
$value
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function assertAcceptsKeyValue($key, $value)
|
||||
{
|
||||
$err = 'Failed assertion that MixedStore accepts key ' .
|
||||
Utils::printSafe($key) . ' with value ' . Utils::printSafe($value);
|
||||
|
||||
$this->assertFalse($this->mixedStore->offsetExists($key), $err);
|
||||
$this->mixedStore->offsetSet($key, $value);
|
||||
$this->assertTrue($this->mixedStore->offsetExists($key), $err);
|
||||
$this->assertSame($value, $this->mixedStore->offsetGet($key), $err);
|
||||
$this->mixedStore->offsetUnset($key);
|
||||
$this->assertFalse($this->mixedStore->offsetExists($key), $err);
|
||||
$this->assertProvidesArrayAccess($key, $value);
|
||||
}
|
||||
|
||||
private function assertProvidesArrayAccess($key, $value)
|
||||
{
|
||||
$err = 'Failed assertion that MixedStore provides array access for key ' .
|
||||
Utils::printSafe($key) . ' with value ' . Utils::printSafe($value);
|
||||
|
||||
$this->assertFalse(isset($this->mixedStore[$key]), $err);
|
||||
$this->mixedStore[$key] = $value;
|
||||
$this->assertTrue(isset($this->mixedStore[$key]), $err);
|
||||
$this->assertEquals(!empty($value), !empty($this->mixedStore[$key]), $err);
|
||||
$this->assertSame($value, $this->mixedStore[$key], $err);
|
||||
unset($this->mixedStore[$key]);
|
||||
$this->assertFalse(isset($this->mixedStore[$key]), $err);
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Tests\Utils;
|
||||
|
||||
use GraphQL\Executor\Values;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
use GraphQL\Utils\Utils;
|
||||
use GraphQL\Utils\Value;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class QuotedOrListTest extends TestCase
|
||||
{
|
||||
// DESCRIBE: quotedOrList
|
||||
|
||||
/**
|
||||
* @see it('Does not accept an empty list')
|
||||
*/
|
||||
|
@ -1,16 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Tests\Utils;
|
||||
|
||||
use GraphQL\Language\DirectiveLocation;
|
||||
use GraphQL\Type\Schema;
|
||||
use GraphQL\Type\Definition\CustomScalarType;
|
||||
use GraphQL\Type\Definition\Directive;
|
||||
use GraphQL\Type\Definition\EnumType;
|
||||
use GraphQL\Type\Definition\InputObjectType;
|
||||
use GraphQL\Type\Definition\InterfaceType;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
use GraphQL\Type\Definition\EnumType;
|
||||
use GraphQL\Type\Definition\UnionType;
|
||||
use GraphQL\Type\Schema;
|
||||
use GraphQL\Utils\BuildSchema;
|
||||
use GraphQL\Utils\SchemaPrinter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@ -19,37 +22,40 @@ class SchemaPrinterTest extends TestCase
|
||||
{
|
||||
// Describe: Type System Printer
|
||||
|
||||
private function printForTest($schema)
|
||||
{
|
||||
$schemaText = SchemaPrinter::doPrint($schema);
|
||||
$this->assertEquals($schemaText, SchemaPrinter::doPrint(BuildSchema::build($schemaText)));
|
||||
return "\n" . $schemaText;
|
||||
}
|
||||
|
||||
private function printSingleFieldSchema($fieldConfig)
|
||||
{
|
||||
$query = new ObjectType([
|
||||
'name' => 'Query',
|
||||
'fields' => [
|
||||
'singleField' => $fieldConfig
|
||||
]
|
||||
]);
|
||||
return $this->printForTest(new Schema(['query' => $query]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('Prints String Field')
|
||||
*/
|
||||
public function testPrintsStringField() : void
|
||||
{
|
||||
$output = $this->printSingleFieldSchema([
|
||||
'type' => Type::string()
|
||||
'type' => Type::string(),
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField: String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
private function printSingleFieldSchema($fieldConfig)
|
||||
{
|
||||
$query = new ObjectType([
|
||||
'name' => 'Query',
|
||||
'fields' => ['singleField' => $fieldConfig],
|
||||
]);
|
||||
|
||||
return $this->printForTest(new Schema(['query' => $query]));
|
||||
}
|
||||
|
||||
private function printForTest($schema)
|
||||
{
|
||||
$schemaText = SchemaPrinter::doPrint($schema);
|
||||
$this->assertEquals($schemaText, SchemaPrinter::doPrint(BuildSchema::build($schemaText)));
|
||||
|
||||
return "\n" . $schemaText;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,13 +64,16 @@ type Query {
|
||||
public function testPrintArrayStringField() : void
|
||||
{
|
||||
$output = $this->printSingleFieldSchema([
|
||||
'type' => Type::listOf(Type::string())
|
||||
'type' => Type::listOf(Type::string()),
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField: [String]
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,13 +82,16 @@ type Query {
|
||||
public function testPrintNonNullStringField() : void
|
||||
{
|
||||
$output = $this->printSingleFieldSchema([
|
||||
'type' => Type::nonNull(Type::string())
|
||||
'type' => Type::nonNull(Type::string()),
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField: String!
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,13 +100,16 @@ type Query {
|
||||
public function testPrintNonNullArrayStringField() : void
|
||||
{
|
||||
$output = $this->printSingleFieldSchema([
|
||||
'type' => Type::nonNull(Type::listOf(Type::string()))
|
||||
'type' => Type::nonNull(Type::listOf(Type::string())),
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField: [String]!
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,13 +118,16 @@ type Query {
|
||||
public function testPrintArrayNonNullStringField() : void
|
||||
{
|
||||
$output = $this->printSingleFieldSchema([
|
||||
'type' => Type::listOf(Type::nonNull(Type::string()))
|
||||
'type' => Type::listOf(Type::nonNull(Type::string())),
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField: [String!]
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,13 +136,16 @@ type Query {
|
||||
public function testPrintNonNullArrayNonNullStringField() : void
|
||||
{
|
||||
$output = $this->printSingleFieldSchema([
|
||||
'type' => Type::nonNull(Type::listOf(Type::nonNull(Type::string())))
|
||||
'type' => Type::nonNull(Type::listOf(Type::nonNull(Type::string()))),
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField: [String!]!
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,17 +155,18 @@ type Query {
|
||||
{
|
||||
$fooType = new ObjectType([
|
||||
'name' => 'Foo',
|
||||
'fields' => ['str' => ['type' => Type::string()]]
|
||||
'fields' => ['str' => ['type' => Type::string()]],
|
||||
]);
|
||||
|
||||
$root = new ObjectType([
|
||||
'name' => 'Query',
|
||||
'fields' => ['foo' => ['type' => $fooType]]
|
||||
'fields' => ['foo' => ['type' => $fooType]],
|
||||
]);
|
||||
|
||||
$schema = new Schema(['query' => $root]);
|
||||
$output = $this->printForTest($schema);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Foo {
|
||||
str: String
|
||||
}
|
||||
@ -152,7 +174,9 @@ type Foo {
|
||||
type Query {
|
||||
foo: Foo
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -162,13 +186,16 @@ type Query {
|
||||
{
|
||||
$output = $this->printSingleFieldSchema([
|
||||
'type' => Type::string(),
|
||||
'args' => ['argOne' => ['type' => Type::int()]]
|
||||
'args' => ['argOne' => ['type' => Type::int()]],
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField(argOne: Int): String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -178,13 +205,16 @@ type Query {
|
||||
{
|
||||
$output = $this->printSingleFieldSchema([
|
||||
'type' => Type::string(),
|
||||
'args' => ['argOne' => ['type' => Type::int(), 'defaultValue' => 2]]
|
||||
'args' => ['argOne' => ['type' => Type::int(), 'defaultValue' => 2]],
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField(argOne: Int = 2): String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -196,11 +226,14 @@ type Query {
|
||||
'type' => Type::string(),
|
||||
'args' => ['argOne' => ['type' => Type::string(), 'defaultValue' => "tes\t de\fault"]],
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField(argOne: String = "tes\t de\fault"): String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,13 +243,16 @@ type Query {
|
||||
{
|
||||
$output = $this->printSingleFieldSchema([
|
||||
'type' => Type::string(),
|
||||
'args' => ['argOne' => ['type' => Type::int(), 'defaultValue' => null]]
|
||||
'args' => ['argOne' => ['type' => Type::int(), 'defaultValue' => null]],
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField(argOne: Int = null): String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -226,13 +262,16 @@ type Query {
|
||||
{
|
||||
$output = $this->printSingleFieldSchema([
|
||||
'type' => Type::string(),
|
||||
'args' => ['argOne' => ['type' => Type::nonNull(Type::int())]]
|
||||
'args' => ['argOne' => ['type' => Type::nonNull(Type::int())]],
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField(argOne: Int!): String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,14 +283,17 @@ type Query {
|
||||
'type' => Type::string(),
|
||||
'args' => [
|
||||
'argOne' => ['type' => Type::int()],
|
||||
'argTwo' => ['type' => Type::string()]
|
||||
]
|
||||
'argTwo' => ['type' => Type::string()],
|
||||
],
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField(argOne: Int, argTwo: String): String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -264,14 +306,17 @@ type Query {
|
||||
'args' => [
|
||||
'argOne' => ['type' => Type::int(), 'defaultValue' => 1],
|
||||
'argTwo' => ['type' => Type::string()],
|
||||
'argThree' => ['type' => Type::boolean()]
|
||||
]
|
||||
'argThree' => ['type' => Type::boolean()],
|
||||
],
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField(argOne: Int = 1, argTwo: String, argThree: Boolean): String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -284,14 +329,17 @@ type Query {
|
||||
'args' => [
|
||||
'argOne' => ['type' => Type::int()],
|
||||
'argTwo' => ['type' => Type::string(), 'defaultValue' => 'foo'],
|
||||
'argThree' => ['type' => Type::boolean()]
|
||||
]
|
||||
'argThree' => ['type' => Type::boolean()],
|
||||
],
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField(argOne: Int, argTwo: String = "foo", argThree: Boolean): String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -304,14 +352,17 @@ type Query {
|
||||
'args' => [
|
||||
'argOne' => ['type' => Type::int()],
|
||||
'argTwo' => ['type' => Type::string()],
|
||||
'argThree' => ['type' => Type::boolean(), 'defaultValue' => false]
|
||||
]
|
||||
'argThree' => ['type' => Type::boolean(), 'defaultValue' => false],
|
||||
],
|
||||
]);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
singleField(argOne: Int, argTwo: String, argThree: Boolean = false): String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -324,9 +375,7 @@ type Query {
|
||||
'fields' => ['bar' => ['type' => Type::string()]],
|
||||
]);
|
||||
|
||||
$schema = new Schema([
|
||||
'query' => $customQueryType,
|
||||
]);
|
||||
$schema = new Schema(['query' => $customQueryType]);
|
||||
$output = $this->printForTest($schema);
|
||||
$expected = '
|
||||
schema {
|
||||
@ -347,26 +396,27 @@ type CustomQueryType {
|
||||
{
|
||||
$fooType = new InterfaceType([
|
||||
'name' => 'Foo',
|
||||
'fields' => ['str' => ['type' => Type::string()]]
|
||||
'fields' => ['str' => ['type' => Type::string()]],
|
||||
]);
|
||||
|
||||
$barType = new ObjectType([
|
||||
'name' => 'Bar',
|
||||
'fields' => ['str' => ['type' => Type::string()]],
|
||||
'interfaces' => [$fooType]
|
||||
'interfaces' => [$fooType],
|
||||
]);
|
||||
|
||||
$query = new ObjectType([
|
||||
'name' => 'Query',
|
||||
'fields' => ['bar' => ['type' => $barType]]
|
||||
'fields' => ['bar' => ['type' => $barType]],
|
||||
]);
|
||||
|
||||
$schema = new Schema([
|
||||
'query' => $query,
|
||||
'types' => [$barType]
|
||||
'types' => [$barType],
|
||||
]);
|
||||
$output = $this->printForTest($schema);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Bar implements Foo {
|
||||
str: String
|
||||
}
|
||||
@ -378,7 +428,9 @@ interface Foo {
|
||||
type Query {
|
||||
bar: Bar
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -388,34 +440,35 @@ type Query {
|
||||
{
|
||||
$fooType = new InterfaceType([
|
||||
'name' => 'Foo',
|
||||
'fields' => ['str' => ['type' => Type::string()]]
|
||||
'fields' => ['str' => ['type' => Type::string()]],
|
||||
]);
|
||||
|
||||
$baazType = new InterfaceType([
|
||||
'name' => 'Baaz',
|
||||
'fields' => ['int' => ['type' => Type::int()]]
|
||||
'fields' => ['int' => ['type' => Type::int()]],
|
||||
]);
|
||||
|
||||
$barType = new ObjectType([
|
||||
'name' => 'Bar',
|
||||
'fields' => [
|
||||
'str' => ['type' => Type::string()],
|
||||
'int' => ['type' => Type::int()]
|
||||
'int' => ['type' => Type::int()],
|
||||
],
|
||||
'interfaces' => [$fooType, $baazType]
|
||||
'interfaces' => [$fooType, $baazType],
|
||||
]);
|
||||
|
||||
$query = new ObjectType([
|
||||
'name' => 'Query',
|
||||
'fields' => ['bar' => ['type' => $barType]]
|
||||
'fields' => ['bar' => ['type' => $barType]],
|
||||
]);
|
||||
|
||||
$schema = new Schema([
|
||||
'query' => $query,
|
||||
'types' => [$barType]
|
||||
'types' => [$barType],
|
||||
]);
|
||||
$output = $this->printForTest($schema);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
interface Baaz {
|
||||
int: Int
|
||||
}
|
||||
@ -432,7 +485,9 @@ interface Foo {
|
||||
type Query {
|
||||
bar: Bar
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -442,35 +497,36 @@ type Query {
|
||||
{
|
||||
$fooType = new ObjectType([
|
||||
'name' => 'Foo',
|
||||
'fields' => ['bool' => ['type' => Type::boolean()]]
|
||||
'fields' => ['bool' => ['type' => Type::boolean()]],
|
||||
]);
|
||||
|
||||
$barType = new ObjectType([
|
||||
'name' => 'Bar',
|
||||
'fields' => ['str' => ['type' => Type::string()]]
|
||||
'fields' => ['str' => ['type' => Type::string()]],
|
||||
]);
|
||||
|
||||
$singleUnion = new UnionType([
|
||||
'name' => 'SingleUnion',
|
||||
'types' => [$fooType]
|
||||
'types' => [$fooType],
|
||||
]);
|
||||
|
||||
$multipleUnion = new UnionType([
|
||||
'name' => 'MultipleUnion',
|
||||
'types' => [$fooType, $barType]
|
||||
'types' => [$fooType, $barType],
|
||||
]);
|
||||
|
||||
$query = new ObjectType([
|
||||
'name' => 'Query',
|
||||
'fields' => [
|
||||
'single' => ['type' => $singleUnion],
|
||||
'multiple' => ['type' => $multipleUnion]
|
||||
]
|
||||
'multiple' => ['type' => $multipleUnion],
|
||||
],
|
||||
]);
|
||||
|
||||
$schema = new Schema(['query' => $query]);
|
||||
$output = $this->printForTest($schema);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Bar {
|
||||
str: String
|
||||
}
|
||||
@ -487,7 +543,9 @@ type Query {
|
||||
}
|
||||
|
||||
union SingleUnion = Foo
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -497,7 +555,7 @@ union SingleUnion = Foo
|
||||
{
|
||||
$inputType = new InputObjectType([
|
||||
'name' => 'InputType',
|
||||
'fields' => ['int' => ['type' => Type::int()]]
|
||||
'fields' => ['int' => ['type' => Type::int()]],
|
||||
]);
|
||||
|
||||
$query = new ObjectType([
|
||||
@ -505,14 +563,15 @@ union SingleUnion = Foo
|
||||
'fields' => [
|
||||
'str' => [
|
||||
'type' => Type::string(),
|
||||
'args' => ['argOne' => ['type' => $inputType]]
|
||||
]
|
||||
]
|
||||
'args' => ['argOne' => ['type' => $inputType]],
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$schema = new Schema(['query' => $query]);
|
||||
$output = $this->printForTest($schema);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
input InputType {
|
||||
int: Int
|
||||
}
|
||||
@ -520,7 +579,9 @@ input InputType {
|
||||
type Query {
|
||||
str(argOne: InputType): String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -532,25 +593,28 @@ type Query {
|
||||
'name' => 'Odd',
|
||||
'serialize' => function ($value) {
|
||||
return $value % 2 === 1 ? $value : null;
|
||||
}
|
||||
},
|
||||
]);
|
||||
|
||||
$query = new ObjectType([
|
||||
'name' => 'Query',
|
||||
'fields' => [
|
||||
'odd' => ['type' => $oddType]
|
||||
]
|
||||
'odd' => ['type' => $oddType],
|
||||
],
|
||||
]);
|
||||
|
||||
$schema = new Schema(['query' => $query]);
|
||||
$output = $this->printForTest($schema);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
scalar Odd
|
||||
|
||||
type Query {
|
||||
odd: Odd
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -563,20 +627,21 @@ type Query {
|
||||
'values' => [
|
||||
'RED' => ['value' => 0],
|
||||
'GREEN' => ['value' => 1],
|
||||
'BLUE' => ['value' => 2]
|
||||
]
|
||||
'BLUE' => ['value' => 2],
|
||||
],
|
||||
]);
|
||||
|
||||
$query = new ObjectType([
|
||||
'name' => 'Query',
|
||||
'fields' => [
|
||||
'rgb' => ['type' => $RGBType]
|
||||
]
|
||||
'rgb' => ['type' => $RGBType],
|
||||
],
|
||||
]);
|
||||
|
||||
$schema = new Schema(['query' => $query]);
|
||||
$output = $this->printForTest($schema);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
rgb: RGB
|
||||
}
|
||||
@ -586,7 +651,9 @@ enum RGB {
|
||||
GREEN
|
||||
BLUE
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -598,14 +665,14 @@ enum RGB {
|
||||
'name' => 'Query',
|
||||
'fields' => [
|
||||
'field' => ['type' => Type::string()],
|
||||
]
|
||||
],
|
||||
]);
|
||||
|
||||
$customDirectives = new Directive([
|
||||
'name' => 'customDirective',
|
||||
'locations' => [
|
||||
DirectiveLocation::FIELD
|
||||
]
|
||||
DirectiveLocation::FIELD,
|
||||
],
|
||||
]);
|
||||
|
||||
$schema = new Schema([
|
||||
@ -614,13 +681,16 @@ enum RGB {
|
||||
]);
|
||||
|
||||
$output = $this->printForTest($schema);
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
directive @customDirective on FIELD
|
||||
|
||||
type Query {
|
||||
field: String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -630,16 +700,19 @@ type Query {
|
||||
{
|
||||
$description = 'This field is awesome';
|
||||
$output = $this->printSingleFieldSchema([
|
||||
"type" => Type::string(),
|
||||
"description" => $description
|
||||
'type' => Type::string(),
|
||||
'description' => $description,
|
||||
]);
|
||||
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
"""This field is awesome"""
|
||||
singleField: String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
|
||||
$recreatedRoot = BuildSchema::build($output)->getTypeMap()['Query'];
|
||||
$recreatedField = $recreatedRoot->getFields()['singleField'];
|
||||
@ -653,18 +726,21 @@ type Query {
|
||||
{
|
||||
$description = 'This field is "awesome"';
|
||||
$output = $this->printSingleFieldSchema([
|
||||
"type" => Type::string(),
|
||||
"description" => $description
|
||||
'type' => Type::string(),
|
||||
'description' => $description,
|
||||
]);
|
||||
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
"""
|
||||
This field is "awesome"
|
||||
"""
|
||||
singleField: String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
|
||||
$recreatedRoot = BuildSchema::build($output)->getTypeMap()['Query'];
|
||||
$recreatedField = $recreatedRoot->getFields()['singleField'];
|
||||
@ -678,17 +754,20 @@ type Query {
|
||||
{
|
||||
$description = ' This field is "awesome"';
|
||||
$output = $this->printSingleFieldSchema([
|
||||
"type" => Type::string(),
|
||||
"description" => $description
|
||||
'type' => Type::string(),
|
||||
'description' => $description,
|
||||
]);
|
||||
|
||||
$this->assertEquals('
|
||||
$this->assertEquals(
|
||||
'
|
||||
type Query {
|
||||
""" This field is "awesome"
|
||||
"""
|
||||
singleField: String
|
||||
}
|
||||
', $output);
|
||||
',
|
||||
$output
|
||||
);
|
||||
|
||||
$recreatedRoot = BuildSchema::build($output)->getTypeMap()['Query'];
|
||||
$recreatedField = $recreatedRoot->getFields()['singleField'];
|
||||
@ -703,8 +782,8 @@ type Query {
|
||||
$query = new ObjectType([
|
||||
'name' => 'Query',
|
||||
'fields' => [
|
||||
'onlyField' => ['type' => Type::string()]
|
||||
]
|
||||
'onlyField' => ['type' => Type::string()],
|
||||
],
|
||||
]);
|
||||
|
||||
$schema = new Schema(['query' => $query]);
|
||||
@ -948,14 +1027,15 @@ EOT;
|
||||
$query = new ObjectType([
|
||||
'name' => 'Query',
|
||||
'fields' => [
|
||||
'onlyField' => ['type' => Type::string()]
|
||||
]
|
||||
'onlyField' => ['type' => Type::string()],
|
||||
],
|
||||
]);
|
||||
|
||||
$schema = new Schema(['query' => $query]);
|
||||
$output = SchemaPrinter::printIntrosepctionSchema($schema, [
|
||||
'commentDescriptions' => true
|
||||
]);
|
||||
$output = SchemaPrinter::printIntrosepctionSchema(
|
||||
$schema,
|
||||
['commentDescriptions' => true]
|
||||
);
|
||||
$introspectionSchema = <<<'EOT'
|
||||
# Directs the executor to include this field or fragment only when the `if` argument is true.
|
||||
directive @include(
|
||||
|
@ -1,16 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Tests\Utils;
|
||||
|
||||
use GraphQL\Executor\Values;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
use GraphQL\Utils\Utils;
|
||||
use GraphQL\Utils\Value;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SuggestionListTest extends TestCase
|
||||
{
|
||||
// DESCRIBE: suggestionList
|
||||
|
||||
/**
|
||||
* @see it('Returns results when input is empty')
|
||||
*/
|
||||
|
@ -1,26 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Tests\Utils;
|
||||
|
||||
use GraphQL\Language\AST\NullValueNode;
|
||||
use GraphQL\Language\Parser;
|
||||
use GraphQL\Type\Definition\EnumType;
|
||||
use GraphQL\Type\Definition\InputObjectType;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
use GraphQL\Utils\Utils;
|
||||
use GraphQL\Utils\AST;
|
||||
use GraphQL\Utils\Utils;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ValueFromAstTest extends TestCase
|
||||
{
|
||||
private function runTestCase($type, $valueText, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, AST::valueFromAST(Parser::parseValue($valueText), $type));
|
||||
}
|
||||
|
||||
private function runTestCaseWithVars($variables, $type, $valueText, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, AST::valueFromAST(Parser::parseValue($valueText), $type, $variables));
|
||||
}
|
||||
/** @var InputObjectType */
|
||||
private $inputObj;
|
||||
|
||||
/**
|
||||
* @see it('rejects empty input')
|
||||
@ -45,6 +40,11 @@ class ValueFromAstTest extends TestCase
|
||||
$this->runTestCase(Type::id(), '"123456"', '123456');
|
||||
}
|
||||
|
||||
private function runTestCase($type, $valueText, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, AST::valueFromAST(Parser::parseValue($valueText), $type));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('does not convert when input coercion rules reject a value')
|
||||
*/
|
||||
@ -74,7 +74,7 @@ class ValueFromAstTest extends TestCase
|
||||
'GREEN' => ['value' => 2],
|
||||
'BLUE' => ['value' => 3],
|
||||
'NULL' => ['value' => null],
|
||||
]
|
||||
],
|
||||
]);
|
||||
|
||||
$this->runTestCase($testEnum, 'RED', 1);
|
||||
@ -159,20 +159,6 @@ class ValueFromAstTest extends TestCase
|
||||
$this->runTestCase($nonNullListOfNonNullBool, '[true, null]', $undefined);
|
||||
}
|
||||
|
||||
private $inputObj;
|
||||
|
||||
private function inputObj()
|
||||
{
|
||||
return $this->inputObj ?: $this->inputObj = new InputObjectType([
|
||||
'name' => 'TestInput',
|
||||
'fields' => [
|
||||
'int' => [ 'type' => Type::int(), 'defaultValue' => 42 ],
|
||||
'bool' => [ 'type' => Type::boolean() ],
|
||||
'requiredBool' => [ 'type' => Type::nonNull(Type::boolean()) ],
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('coerces input objects according to input coercion rules')
|
||||
*/
|
||||
@ -185,12 +171,28 @@ class ValueFromAstTest extends TestCase
|
||||
$this->runTestCase($testInputObj, '123', $undefined);
|
||||
$this->runTestCase($testInputObj, '[]', $undefined);
|
||||
$this->runTestCase($testInputObj, '{ int: 123, requiredBool: false }', ['int' => 123, 'requiredBool' => false]);
|
||||
$this->runTestCase($testInputObj, '{ bool: true, requiredBool: false }', [ 'int' => 42, 'bool' => true, 'requiredBool' => false ]);
|
||||
$this->runTestCase(
|
||||
$testInputObj,
|
||||
'{ bool: true, requiredBool: false }',
|
||||
['int' => 42, 'bool' => true, 'requiredBool' => false]
|
||||
);
|
||||
$this->runTestCase($testInputObj, '{ int: true, requiredBool: true }', $undefined);
|
||||
$this->runTestCase($testInputObj, '{ requiredBool: null }', $undefined);
|
||||
$this->runTestCase($testInputObj, '{ bool: true }', $undefined);
|
||||
}
|
||||
|
||||
private function inputObj()
|
||||
{
|
||||
return $this->inputObj ?: $this->inputObj = new InputObjectType([
|
||||
'name' => 'TestInput',
|
||||
'fields' => [
|
||||
'int' => ['type' => Type::int(), 'defaultValue' => 42],
|
||||
'bool' => ['type' => Type::boolean()],
|
||||
'requiredBool' => ['type' => Type::nonNull(Type::boolean())],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('accepts variable values assuming already coerced')
|
||||
*/
|
||||
@ -201,6 +203,11 @@ class ValueFromAstTest extends TestCase
|
||||
$this->runTestCaseWithVars(['var' => null], Type::boolean(), '$var', null);
|
||||
}
|
||||
|
||||
private function runTestCaseWithVars($variables, $type, $valueText, $expected)
|
||||
{
|
||||
$this->assertEquals($expected, AST::valueFromAST(Parser::parseValue($valueText), $type, $variables));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see it('asserts variables are provided as items in lists')
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user