From 0b4b1485e07ecbfb02b3d16c6106b9f2106c179e Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Sun, 2 Jun 2019 20:15:33 +0200 Subject: [PATCH] Add a test to cover promises --- tests/GraphQLTest.php | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/GraphQLTest.php diff --git a/tests/GraphQLTest.php b/tests/GraphQLTest.php new file mode 100644 index 0000000..9617e9e --- /dev/null +++ b/tests/GraphQLTest.php @@ -0,0 +1,47 @@ + 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()); + } +}