mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-25 06:16:05 +03:00
Add a test to cover promises
This commit is contained in:
parent
e55c7d72cb
commit
0b4b1485e0
47
tests/GraphQLTest.php
Normal file
47
tests/GraphQLTest.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace GraphQL\Tests;
|
||||||
|
|
||||||
|
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
|
||||||
|
use GraphQL\GraphQL;
|
||||||
|
use GraphQL\Type\Definition\ObjectType;
|
||||||
|
use GraphQL\Type\Definition\Type;
|
||||||
|
use GraphQL\Type\Schema;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use function sprintf;
|
||||||
|
|
||||||
|
class GraphQLTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testPromiseToExecute() : void
|
||||||
|
{
|
||||||
|
$promiseAdapter = new SyncPromiseAdapter();
|
||||||
|
$schema = new Schema(
|
||||||
|
[
|
||||||
|
'query' => new ObjectType(
|
||||||
|
[
|
||||||
|
'name' => 'Query',
|
||||||
|
'fields' => [
|
||||||
|
'sayHi' => [
|
||||||
|
'type' => Type::nonNull(Type::string()),
|
||||||
|
'args' => [
|
||||||
|
'name' => [
|
||||||
|
'type' => Type::nonNull(Type::string()),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'resolve' => static function ($value, $args) use ($promiseAdapter) {
|
||||||
|
return $promiseAdapter->createFulfilled(sprintf('Hi %s!', $args['name']));
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$promise = GraphQL::promiseToExecute($promiseAdapter, $schema, '{ sayHi(name: "John") }');
|
||||||
|
$result = $promiseAdapter->wait($promise);
|
||||||
|
$this->assertSame(['data' => ['sayHi' => 'Hi John!']], $result->toArray());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user