Passed
Push — master ( e17f57...acc044 )
by Vladimir
09:17 queued 11s
created

GraphQLTest::testPromiseToExecute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 29
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Tests;
6
7
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
8
use GraphQL\GraphQL;
9
use GraphQL\Type\Definition\ObjectType;
10
use GraphQL\Type\Definition\Type;
11
use GraphQL\Type\Schema;
12
use PHPUnit\Framework\TestCase;
13
use function sprintf;
14
15
class GraphQLTest extends TestCase
16
{
17
    public function testPromiseToExecute() : void
18
    {
19
        $promiseAdapter = new SyncPromiseAdapter();
20
        $schema         = new Schema(
21
            [
22
                'query' => new ObjectType(
23
                    [
24
                        'name' => 'Query',
25
                        'fields' => [
26
                            'sayHi' => [
27
                                'type' => Type::nonNull(Type::string()),
28
                                'args' => [
29
                                    'name' => [
30
                                        'type' => Type::nonNull(Type::string()),
31
                                    ],
32
                                ],
33
                                'resolve' => static function ($value, $args) use ($promiseAdapter) {
34
                                    return $promiseAdapter->createFulfilled(sprintf('Hi %s!', $args['name']));
35
                                },
36
                            ],
37
                        ],
38
                    ]
39
                ),
40
            ]
41
        );
42
43
        $promise = GraphQL::promiseToExecute($promiseAdapter, $schema, '{ sayHi(name: "John") }');
44
        $result  = $promiseAdapter->wait($promise);
45
        self::assertSame(['data' => ['sayHi' => 'Hi John!']], $result->toArray());
46
    }
47
}
48