2015-07-15 20:05:46 +03:00
|
|
|
<?php
|
2016-11-27 00:28:46 +03:00
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-04-09 10:36:53 +03:00
|
|
|
namespace GraphQL\Tests\Executor;
|
2015-07-15 20:05:46 +03:00
|
|
|
|
2016-12-03 00:11:14 +03:00
|
|
|
use GraphQL\Deferred;
|
2017-07-18 16:57:30 +03:00
|
|
|
use GraphQL\Error\UserError;
|
2016-04-09 10:36:53 +03:00
|
|
|
use GraphQL\Executor\Executor;
|
2015-07-15 20:05:46 +03:00
|
|
|
use GraphQL\Language\Parser;
|
|
|
|
use GraphQL\Type\Definition\ObjectType;
|
|
|
|
use GraphQL\Type\Definition\Type;
|
2018-09-01 18:07:06 +03:00
|
|
|
use GraphQL\Type\Schema;
|
2018-07-29 18:43:10 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2015-07-15 20:05:46 +03:00
|
|
|
|
2018-07-29 18:43:10 +03:00
|
|
|
class ListsTest extends TestCase
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2016-05-02 00:42:05 +03:00
|
|
|
// Describe: Execute: Handles list nullability
|
|
|
|
/**
|
2018-08-31 12:07:29 +03:00
|
|
|
* [T]
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testHandlesNullableListsWithArray() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2016-05-02 00:42:05 +03:00
|
|
|
// Contains values
|
2016-11-27 00:28:46 +03:00
|
|
|
$this->checkHandlesNullableLists(
|
2018-09-01 18:07:06 +03:00
|
|
|
[1, 2],
|
|
|
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Contains null
|
2016-11-27 00:28:46 +03:00
|
|
|
$this->checkHandlesNullableLists(
|
2018-09-01 18:07:06 +03:00
|
|
|
[1, null, 2],
|
|
|
|
['data' => ['nest' => ['test' => [1, null, 2]]]]
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Returns null
|
2016-11-27 00:28:46 +03:00
|
|
|
$this->checkHandlesNullableLists(
|
2016-05-02 00:42:05 +03:00
|
|
|
null,
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => null]]]
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
private function checkHandlesNullableLists($testData, $expected)
|
|
|
|
{
|
|
|
|
$testType = Type::listOf(Type::int());
|
|
|
|
$this->check($testType, $testData, $expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function check($testType, $testData, $expected, $debug = false)
|
|
|
|
{
|
|
|
|
$data = ['test' => $testData];
|
|
|
|
$dataType = null;
|
|
|
|
|
|
|
|
$dataType = new ObjectType([
|
|
|
|
'name' => 'DataType',
|
|
|
|
'fields' => function () use (&$testType, &$dataType, $data) {
|
|
|
|
return [
|
|
|
|
'test' => ['type' => $testType],
|
|
|
|
'nest' => [
|
|
|
|
'type' => $dataType,
|
|
|
|
'resolve' => function () use ($data) {
|
|
|
|
return $data;
|
|
|
|
},
|
|
|
|
],
|
|
|
|
];
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
$schema = new Schema(['query' => $dataType]);
|
|
|
|
|
|
|
|
$ast = Parser::parse('{ nest { test } }');
|
|
|
|
|
|
|
|
$result = Executor::execute($schema, $ast, $data);
|
2018-09-19 18:12:09 +03:00
|
|
|
self::assertArraySubset($expected, $result->toArray($debug));
|
2018-09-01 18:07:06 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 12:07:29 +03:00
|
|
|
* [T]
|
2016-11-27 00:28:46 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testHandlesNullableListsWithPromiseArray() : void
|
2016-11-27 00:28:46 +03:00
|
|
|
{
|
|
|
|
// Contains values
|
|
|
|
$this->checkHandlesNullableLists(
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
|
|
|
return [1, 2];
|
2016-12-03 00:11:14 +03:00
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Contains null
|
|
|
|
$this->checkHandlesNullableLists(
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return [1, null, 2];
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => [1, null, 2]]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Returns null
|
|
|
|
$this->checkHandlesNullableLists(
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return null;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => null]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Rejected
|
|
|
|
$this->checkHandlesNullableLists(
|
|
|
|
function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return new Deferred(function () {
|
2017-07-18 16:57:30 +03:00
|
|
|
throw new UserError('bad');
|
2016-12-03 00:11:14 +03:00
|
|
|
});
|
2016-11-27 00:28:46 +03:00
|
|
|
},
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => ['test' => null]],
|
2016-11-27 00:28:46 +03:00
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' => 'bad',
|
2016-11-27 00:28:46 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'path' => ['nest', 'test'],
|
|
|
|
],
|
|
|
|
],
|
2016-11-27 00:28:46 +03:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 12:07:29 +03:00
|
|
|
* [T]
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testHandlesNullableListsWithArrayPromise() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2016-11-27 00:28:46 +03:00
|
|
|
// Contains values
|
|
|
|
$this->checkHandlesNullableLists(
|
2016-12-03 00:11:14 +03:00
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 1;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 2;
|
2018-09-01 18:07:06 +03:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Contains null
|
|
|
|
$this->checkHandlesNullableLists(
|
2016-12-03 00:11:14 +03:00
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
|
|
|
return 1;
|
|
|
|
}),
|
|
|
|
new Deferred(function () {
|
|
|
|
return null;
|
|
|
|
}),
|
|
|
|
new Deferred(function () {
|
|
|
|
return 2;
|
|
|
|
}),
|
2016-12-03 00:11:14 +03:00
|
|
|
],
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => [1, null, 2]]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Returns null
|
|
|
|
$this->checkHandlesNullableLists(
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:23:21 +03:00
|
|
|
return null;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => null]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Contains reject
|
|
|
|
$this->checkHandlesNullableLists(
|
|
|
|
function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return [
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 1;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2017-07-18 16:57:30 +03:00
|
|
|
throw new UserError('bad');
|
2016-12-03 00:11:14 +03:00
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 2;
|
2018-09-01 18:07:06 +03:00
|
|
|
}),
|
2016-12-03 00:11:14 +03:00
|
|
|
];
|
2016-11-27 00:28:46 +03:00
|
|
|
},
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => ['test' => [1, null, 2]]],
|
2016-11-27 00:28:46 +03:00
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' => 'bad',
|
2016-11-27 00:28:46 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'path' => ['nest', 'test', 1],
|
|
|
|
],
|
|
|
|
],
|
2016-11-27 00:28:46 +03:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2016-05-02 00:42:05 +03:00
|
|
|
|
2016-11-27 00:28:46 +03:00
|
|
|
/**
|
2018-08-31 12:07:29 +03:00
|
|
|
* [T]!
|
2016-11-27 00:28:46 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testHandlesNonNullableListsWithArray() : void
|
2016-11-27 00:28:46 +03:00
|
|
|
{
|
2016-05-02 00:42:05 +03:00
|
|
|
// Contains values
|
2016-11-27 00:28:46 +03:00
|
|
|
$this->checkHandlesNonNullableLists(
|
2018-09-01 18:07:06 +03:00
|
|
|
[1, 2],
|
|
|
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Contains null
|
2016-11-27 00:28:46 +03:00
|
|
|
$this->checkHandlesNonNullableLists(
|
2018-09-01 18:07:06 +03:00
|
|
|
[1, null, 2],
|
|
|
|
['data' => ['nest' => ['test' => [1, null, 2]]]]
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Returns null
|
2016-11-27 00:28:46 +03:00
|
|
|
$this->checkHandlesNonNullableLists(
|
2016-05-02 00:42:05 +03:00
|
|
|
null,
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => null],
|
2016-05-02 00:42:05 +03:00
|
|
|
'errors' => [
|
2017-07-18 16:57:30 +03:00
|
|
|
[
|
|
|
|
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
|
2018-09-01 18:07:06 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
|
|
|
],
|
|
|
|
],
|
2017-07-18 16:57:30 +03:00
|
|
|
],
|
|
|
|
true
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
private function checkHandlesNonNullableLists($testData, $expected, $debug = false)
|
|
|
|
{
|
|
|
|
$testType = Type::nonNull(Type::listOf(Type::int()));
|
|
|
|
$this->check($testType, $testData, $expected, $debug);
|
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 12:07:29 +03:00
|
|
|
* [T]!
|
2016-11-27 00:28:46 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testHandlesNonNullableListsWithPromiseArray() : void
|
2016-11-27 00:28:46 +03:00
|
|
|
{
|
|
|
|
// Contains values
|
|
|
|
$this->checkHandlesNonNullableLists(
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
|
|
|
return [1, 2];
|
2016-12-03 00:11:14 +03:00
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Contains null
|
|
|
|
$this->checkHandlesNonNullableLists(
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return [1, null, 2];
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => [1, null, 2]]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Returns null
|
|
|
|
$this->checkHandlesNonNullableLists(
|
|
|
|
null,
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => null],
|
2016-11-27 00:28:46 +03:00
|
|
|
'errors' => [
|
2017-07-18 16:57:30 +03:00
|
|
|
[
|
|
|
|
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
|
2018-09-01 18:07:06 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
|
|
|
],
|
|
|
|
],
|
2017-07-18 16:57:30 +03:00
|
|
|
],
|
|
|
|
true
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Rejected
|
|
|
|
$this->checkHandlesNonNullableLists(
|
|
|
|
function () {
|
2018-09-01 18:07:06 +03:00
|
|
|
return new Deferred(function () {
|
2017-07-18 16:57:30 +03:00
|
|
|
throw new UserError('bad');
|
2016-12-03 00:11:14 +03:00
|
|
|
});
|
2016-11-27 00:28:46 +03:00
|
|
|
},
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => null],
|
2016-11-27 00:28:46 +03:00
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' => 'bad',
|
2016-11-27 00:28:46 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'path' => ['nest', 'test'],
|
|
|
|
],
|
|
|
|
],
|
2016-11-27 00:28:46 +03:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 12:07:29 +03:00
|
|
|
* [T]!
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testHandlesNonNullableListsWithArrayPromise() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2016-11-27 00:28:46 +03:00
|
|
|
// Contains values
|
|
|
|
$this->checkHandlesNonNullableLists(
|
2016-12-03 00:11:14 +03:00
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 1;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 2;
|
2018-09-01 18:07:06 +03:00
|
|
|
}),
|
2016-12-03 00:11:14 +03:00
|
|
|
],
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Contains null
|
|
|
|
$this->checkHandlesNonNullableLists(
|
2016-12-03 00:11:14 +03:00
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 1;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return null;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 2;
|
2018-09-01 18:07:06 +03:00
|
|
|
}),
|
2016-12-03 00:11:14 +03:00
|
|
|
],
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => [1, null, 2]]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
2016-05-02 00:42:05 +03:00
|
|
|
|
2016-11-27 00:28:46 +03:00
|
|
|
// Contains reject
|
|
|
|
$this->checkHandlesNonNullableLists(
|
|
|
|
function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return [
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 1;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2017-07-18 16:57:30 +03:00
|
|
|
throw new UserError('bad');
|
2016-12-03 00:11:14 +03:00
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 2;
|
2018-09-01 18:07:06 +03:00
|
|
|
}),
|
2016-12-03 00:11:14 +03:00
|
|
|
];
|
2016-11-27 00:28:46 +03:00
|
|
|
},
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => ['test' => [1, null, 2]]],
|
2016-11-27 00:28:46 +03:00
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' => 'bad',
|
2016-11-27 00:28:46 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'path' => ['nest', 'test', 1],
|
|
|
|
],
|
|
|
|
],
|
2016-11-27 00:28:46 +03:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 12:07:29 +03:00
|
|
|
* [T!]
|
2016-11-27 00:28:46 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testHandlesListOfNonNullsWithArray() : void
|
2016-11-27 00:28:46 +03:00
|
|
|
{
|
2016-05-02 00:42:05 +03:00
|
|
|
// Contains values
|
2016-11-27 00:28:46 +03:00
|
|
|
$this->checkHandlesListOfNonNulls(
|
2018-09-01 18:07:06 +03:00
|
|
|
[1, 2],
|
|
|
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Contains null
|
2016-11-27 00:28:46 +03:00
|
|
|
$this->checkHandlesListOfNonNulls(
|
2018-09-01 18:07:06 +03:00
|
|
|
[1, null, 2],
|
2016-05-02 00:42:05 +03:00
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => ['test' => null]],
|
2016-05-02 00:42:05 +03:00
|
|
|
'errors' => [
|
2017-07-18 16:57:30 +03:00
|
|
|
[
|
|
|
|
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
|
2018-09-01 18:07:06 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
|
|
|
],
|
|
|
|
],
|
2017-07-18 16:57:30 +03:00
|
|
|
],
|
|
|
|
true
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Returns null
|
2016-11-27 00:28:46 +03:00
|
|
|
$this->checkHandlesListOfNonNulls(
|
2016-05-02 00:42:05 +03:00
|
|
|
null,
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => null]]]
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
private function checkHandlesListOfNonNulls($testData, $expected, $debug = false)
|
|
|
|
{
|
|
|
|
$testType = Type::listOf(Type::nonNull(Type::int()));
|
|
|
|
$this->check($testType, $testData, $expected, $debug);
|
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 12:07:29 +03:00
|
|
|
* [T!]
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testHandlesListOfNonNullsWithPromiseArray() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2016-11-27 00:28:46 +03:00
|
|
|
// Contains values
|
|
|
|
$this->checkHandlesListOfNonNulls(
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return [1, 2];
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
2016-05-02 00:42:05 +03:00
|
|
|
|
2016-11-27 00:28:46 +03:00
|
|
|
// Contains null
|
|
|
|
$this->checkHandlesListOfNonNulls(
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return [1, null, 2];
|
|
|
|
}),
|
2016-11-27 00:28:46 +03:00
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => ['test' => null]],
|
2016-11-27 00:28:46 +03:00
|
|
|
'errors' => [
|
2017-07-18 16:57:30 +03:00
|
|
|
[
|
|
|
|
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
|
2018-09-01 18:07:06 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
|
|
|
],
|
|
|
|
],
|
2017-07-18 16:57:30 +03:00
|
|
|
],
|
|
|
|
true
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Returns null
|
|
|
|
$this->checkHandlesListOfNonNulls(
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:23:21 +03:00
|
|
|
return null;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => null]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Rejected
|
|
|
|
$this->checkHandlesListOfNonNulls(
|
|
|
|
function () {
|
2018-09-01 18:07:06 +03:00
|
|
|
return new Deferred(function () {
|
2017-07-18 16:57:30 +03:00
|
|
|
throw new UserError('bad');
|
2016-12-03 00:11:14 +03:00
|
|
|
});
|
2016-11-27 00:28:46 +03:00
|
|
|
},
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => ['test' => null]],
|
2016-11-27 00:28:46 +03:00
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' => 'bad',
|
2016-11-27 00:28:46 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'path' => ['nest', 'test'],
|
|
|
|
],
|
|
|
|
],
|
2016-11-27 00:28:46 +03:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 12:07:29 +03:00
|
|
|
* [T]!
|
2016-11-27 00:28:46 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testHandlesListOfNonNullsWithArrayPromise() : void
|
2016-11-27 00:28:46 +03:00
|
|
|
{
|
|
|
|
// Contains values
|
|
|
|
$this->checkHandlesListOfNonNulls(
|
2016-12-03 00:11:14 +03:00
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 1;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 2;
|
2018-09-01 18:07:06 +03:00
|
|
|
}),
|
2016-12-03 00:11:14 +03:00
|
|
|
],
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Contains null
|
|
|
|
$this->checkHandlesListOfNonNulls(
|
2016-12-03 00:23:21 +03:00
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
|
|
|
return 1;
|
|
|
|
}),
|
|
|
|
new Deferred(function () {
|
|
|
|
return null;
|
|
|
|
}),
|
|
|
|
new Deferred(function () {
|
|
|
|
return 2;
|
|
|
|
}),
|
2016-12-03 00:23:21 +03:00
|
|
|
],
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => null]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Contains reject
|
|
|
|
$this->checkHandlesListOfNonNulls(
|
|
|
|
function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return [
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 1;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2017-07-18 16:57:30 +03:00
|
|
|
throw new UserError('bad');
|
2016-12-03 00:11:14 +03:00
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 2;
|
2018-09-01 18:07:06 +03:00
|
|
|
}),
|
2016-12-03 00:11:14 +03:00
|
|
|
];
|
2016-11-27 00:28:46 +03:00
|
|
|
},
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => ['test' => null]],
|
2016-11-27 00:28:46 +03:00
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' => 'bad',
|
2016-11-27 00:28:46 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'path' => ['nest', 'test', 1],
|
|
|
|
],
|
|
|
|
],
|
2016-11-27 00:28:46 +03:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 12:07:29 +03:00
|
|
|
* [T!]!
|
2016-11-27 00:28:46 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testHandlesNonNullListOfNonNullsWithArray() : void
|
2016-11-27 00:28:46 +03:00
|
|
|
{
|
2016-05-02 00:42:05 +03:00
|
|
|
// Contains values
|
2016-11-27 00:28:46 +03:00
|
|
|
$this->checkHandlesNonNullListOfNonNulls(
|
2018-09-01 18:07:06 +03:00
|
|
|
[1, 2],
|
|
|
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Contains null
|
2016-11-27 00:28:46 +03:00
|
|
|
$this->checkHandlesNonNullListOfNonNulls(
|
2018-09-01 18:07:06 +03:00
|
|
|
[1, null, 2],
|
2016-05-02 00:42:05 +03:00
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => null],
|
2016-05-02 00:42:05 +03:00
|
|
|
'errors' => [
|
2017-07-18 16:57:30 +03:00
|
|
|
[
|
|
|
|
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
|
2018-09-01 18:07:06 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
|
|
|
],
|
|
|
|
],
|
2017-07-18 16:57:30 +03:00
|
|
|
],
|
|
|
|
true
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Returns null
|
2016-11-27 00:28:46 +03:00
|
|
|
$this->checkHandlesNonNullListOfNonNulls(
|
2016-05-02 00:42:05 +03:00
|
|
|
null,
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => null],
|
2016-05-02 00:42:05 +03:00
|
|
|
'errors' => [
|
2017-07-18 16:57:30 +03:00
|
|
|
[
|
|
|
|
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
|
2018-09-01 18:07:06 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
|
|
|
],
|
|
|
|
],
|
2017-07-18 16:57:30 +03:00
|
|
|
],
|
|
|
|
true
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
2016-11-27 00:28:46 +03:00
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
public function checkHandlesNonNullListOfNonNulls($testData, $expected, $debug = false)
|
|
|
|
{
|
|
|
|
$testType = Type::nonNull(Type::listOf(Type::nonNull(Type::int())));
|
|
|
|
$this->check($testType, $testData, $expected, $debug);
|
|
|
|
}
|
|
|
|
|
2016-11-27 00:28:46 +03:00
|
|
|
/**
|
2018-08-31 12:07:29 +03:00
|
|
|
* [T!]!
|
2016-11-27 00:28:46 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testHandlesNonNullListOfNonNullsWithPromiseArray() : void
|
2016-11-27 00:28:46 +03:00
|
|
|
{
|
|
|
|
// Contains values
|
|
|
|
$this->checkHandlesNonNullListOfNonNulls(
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return [1, 2];
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Contains null
|
|
|
|
$this->checkHandlesNonNullListOfNonNulls(
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return [1, null, 2];
|
|
|
|
}),
|
2016-11-27 00:28:46 +03:00
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => null],
|
2016-11-27 00:28:46 +03:00
|
|
|
'errors' => [
|
2017-07-18 16:57:30 +03:00
|
|
|
[
|
|
|
|
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
|
2018-09-01 18:07:06 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
|
|
|
],
|
|
|
|
],
|
2017-07-18 16:57:30 +03:00
|
|
|
],
|
|
|
|
true
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Returns null
|
|
|
|
$this->checkHandlesNonNullListOfNonNulls(
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return null;
|
|
|
|
}),
|
2016-11-27 00:28:46 +03:00
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => null],
|
2016-11-27 00:28:46 +03:00
|
|
|
'errors' => [
|
2017-07-18 16:57:30 +03:00
|
|
|
[
|
|
|
|
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
|
2018-09-01 18:07:06 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
|
|
|
],
|
|
|
|
],
|
2017-07-18 16:57:30 +03:00
|
|
|
],
|
|
|
|
true
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Rejected
|
|
|
|
$this->checkHandlesNonNullListOfNonNulls(
|
|
|
|
function () {
|
2018-09-01 18:07:06 +03:00
|
|
|
return new Deferred(function () {
|
2017-07-18 16:57:30 +03:00
|
|
|
throw new UserError('bad');
|
2016-12-03 00:11:14 +03:00
|
|
|
});
|
2016-11-27 00:28:46 +03:00
|
|
|
},
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => null],
|
2016-11-27 00:28:46 +03:00
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' => 'bad',
|
2016-11-27 00:28:46 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'path' => ['nest', 'test'],
|
|
|
|
],
|
|
|
|
],
|
2016-11-27 00:28:46 +03:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 12:07:29 +03:00
|
|
|
* [T!]!
|
2016-11-27 00:28:46 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testHandlesNonNullListOfNonNullsWithArrayPromise() : void
|
2016-11-27 00:28:46 +03:00
|
|
|
{
|
|
|
|
// Contains values
|
|
|
|
$this->checkHandlesNonNullListOfNonNulls(
|
2016-12-03 00:11:14 +03:00
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 1;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 2;
|
2018-09-01 18:07:06 +03:00
|
|
|
}),
|
2016-12-03 00:11:14 +03:00
|
|
|
|
|
|
|
],
|
2018-09-01 18:07:06 +03:00
|
|
|
['data' => ['nest' => ['test' => [1, 2]]]]
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Contains null
|
|
|
|
$this->checkHandlesNonNullListOfNonNulls(
|
2016-12-03 00:11:14 +03:00
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 1;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return null;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 2;
|
2018-09-01 18:07:06 +03:00
|
|
|
}),
|
2016-12-03 00:11:14 +03:00
|
|
|
],
|
2016-11-27 00:28:46 +03:00
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => null],
|
2016-11-27 00:28:46 +03:00
|
|
|
'errors' => [
|
2017-07-18 16:57:30 +03:00
|
|
|
[
|
|
|
|
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
|
2018-09-01 18:07:06 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
|
|
|
],
|
|
|
|
],
|
2017-07-18 16:57:30 +03:00
|
|
|
],
|
|
|
|
true
|
2016-11-27 00:28:46 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// Contains reject
|
|
|
|
$this->checkHandlesNonNullListOfNonNulls(
|
|
|
|
function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return [
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 1;
|
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2017-07-18 16:57:30 +03:00
|
|
|
throw new UserError('bad');
|
2016-12-03 00:11:14 +03:00
|
|
|
}),
|
2018-09-01 18:07:06 +03:00
|
|
|
new Deferred(function () {
|
2016-12-03 00:11:14 +03:00
|
|
|
return 2;
|
2018-09-01 18:07:06 +03:00
|
|
|
}),
|
2016-12-03 00:11:14 +03:00
|
|
|
];
|
2016-11-27 00:28:46 +03:00
|
|
|
},
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['nest' => null],
|
2016-11-27 00:28:46 +03:00
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' => 'bad',
|
2016-11-27 00:28:46 +03:00
|
|
|
'locations' => [['line' => 1, 'column' => 10]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'path' => ['nest', 'test'],
|
|
|
|
],
|
|
|
|
],
|
2016-11-27 00:28:46 +03:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2016-04-09 10:36:53 +03:00
|
|
|
}
|