From ae5b96e1967e5a79adbddee1041fb08490179210 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Tue, 12 Jun 2018 15:01:51 +0200 Subject: [PATCH] Add multiple queries tests --- .../App/config/multipleQueries/config.yml | 15 +++ .../mapping/RootQuery.types.yml | 13 +++ .../MultipleQueries/MultipleQueriesTest.php | 104 ++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 Tests/Functional/App/config/multipleQueries/config.yml create mode 100644 Tests/Functional/App/config/multipleQueries/mapping/RootQuery.types.yml create mode 100644 Tests/Functional/MultipleQueries/MultipleQueriesTest.php diff --git a/Tests/Functional/App/config/multipleQueries/config.yml b/Tests/Functional/App/config/multipleQueries/config.yml new file mode 100644 index 000000000..d499d2d2b --- /dev/null +++ b/Tests/Functional/App/config/multipleQueries/config.yml @@ -0,0 +1,15 @@ +imports: + - { resource: ../config.yml } + - { resource: ../exception/services.yml } + +overblog_graphql: + definitions: + class_namespace: "Overblog\\GraphQLBundle\\MultipleQueries\\__DEFINITIONS__" + schema: + query: RootQuery + mutation: RootQuery + mappings: + types: + - + type: yaml + dir: "%kernel.root_dir%/config/multipleQueries/mapping" diff --git a/Tests/Functional/App/config/multipleQueries/mapping/RootQuery.types.yml b/Tests/Functional/App/config/multipleQueries/mapping/RootQuery.types.yml new file mode 100644 index 000000000..9e0c7e5ef --- /dev/null +++ b/Tests/Functional/App/config/multipleQueries/mapping/RootQuery.types.yml @@ -0,0 +1,13 @@ +RootQuery: + type: object + config: + fields: + failRequire: + type: String! + resolve: '@=resolver("example_exception")' + failOptional: + type: String + resolve: '@=resolver("example_exception")' + success: + type: String + resolve: 'foo' diff --git a/Tests/Functional/MultipleQueries/MultipleQueriesTest.php b/Tests/Functional/MultipleQueries/MultipleQueriesTest.php new file mode 100644 index 000000000..11df7645e --- /dev/null +++ b/Tests/Functional/MultipleQueries/MultipleQueriesTest.php @@ -0,0 +1,104 @@ + [], + 'errors' => [ + [ + 'message' => 'Internal server Error', + 'category' => 'internal', + 'locations' => [ + [ + 'line' => 2, + 'column' => 3, + ], + ], + 'path' => [ + 'fail', + ], + ], + ], + ]; + + const OPTIONAL_FAILS = [ + 'data' => [ + 'fail' => null, + 'success' => 'foo', + ], + 'errors' => [ + [ + 'message' => 'Internal server Error', + 'category' => 'internal', + 'locations' => [ + [ + 'line' => 2, + 'column' => 3, + ], + ], + 'path' => [ + 'fail', + ], + ], + ], + ]; + + protected function setUp() + { + parent::setUp(); + + static::bootKernel(['test_case' => 'multipleQueries']); + } + + public function testRequiredFails() + { + $query = <<<'EOF' +{ + fail: failRequire + success: success +} +EOF; + $result = $this->executeGraphQLRequest($query); + $this->assertEquals(self::REQUIRED_FAILS, $result); + } + + public function testOptionalFails() + { + $query = <<<'EOF' +{ + fail: failOptional + success: success +} +EOF; + $result = $this->executeGraphQLRequest($query); + $this->assertEquals(self::OPTIONAL_FAILS, $result); + } + + public function testMutationRequiredFails() + { + $query = <<<'EOF' +mutation { + fail: failRequire + success: success +} +EOF; + $result = $this->executeGraphQLRequest($query); + $this->assertEquals(self::REQUIRED_FAILS, $result); + } + + public function testMutationOptionalFails() + { + $query = <<<'EOF' +mutation { + fail: failOptional + success: success +} +EOF; + $result = $this->executeGraphQLRequest($query); + $this->assertEquals(self::OPTIONAL_FAILS, $result); + } +}