From a42ecd7c9b9a0232243a463cd3ce4723d5cfc1e1 Mon Sep 17 00:00:00 2001 From: Andriy Komm Date: Thu, 28 Mar 2019 16:45:30 +0100 Subject: [PATCH] Fix UploadTest webonyx/graphql-php version detection silently failing --- tests/Functional/Upload/UploadTest.php | 60 +++++++++++++------------- tests/VersionHelper.php | 36 ---------------- 2 files changed, 31 insertions(+), 65 deletions(-) delete mode 100644 tests/VersionHelper.php diff --git a/tests/Functional/Upload/UploadTest.php b/tests/Functional/Upload/UploadTest.php index f7aaa7e4e..514934c75 100644 --- a/tests/Functional/Upload/UploadTest.php +++ b/tests/Functional/Upload/UploadTest.php @@ -6,7 +6,6 @@ use GraphQL\Error\InvariantViolation; use Overblog\GraphQLBundle\Tests\Functional\TestCase; -use Overblog\GraphQLBundle\Tests\VersionHelper; use Symfony\Component\HttpFoundation\File\UploadedFile; class UploadTest extends TestCase @@ -112,42 +111,45 @@ public function testSerializationIsUnsupported(): void public function testParseLiteralIsUnsupported(): void { - $willThrowRawException = VersionHelper::compareWebonyxGraphQLPHPVersion('0.13.1', '<'); - if ($willThrowRawException) { + try { + $result = $this->uploadRequest( + [ + 'operations' => [ + 'query' => 'mutation { singleUpload(file: {}) }', + 'variables' => ['file' => null], + ], + 'map' => ['0' => ['variables.file']], + ], + ['0' => 'a.txt'] + ); + } catch (\Exception $e) { + // webonyx/graphql-php (<0.13.1) does not generate error result $this->expectException(InvariantViolation::class); $this->expectExceptionMessage('Upload scalar literal unsupported.'); + + throw $e; } - $result = $this->uploadRequest( + + // webonyx/graphql-php (>=0.13.1) catches exceptions and generates error result + $this->assertEquals( [ - 'operations' => [ - 'query' => 'mutation { singleUpload(file: {}) }', - 'variables' => ['file' => null], - ], - 'map' => ['0' => ['variables.file']], - ], - ['0' => 'a.txt'] - ); - if (!$willThrowRawException) { - $this->assertEquals( - [ - 'errors' => [ - [ - 'message' => 'Field "singleUpload" argument "file" requires type Upload, found {}; GraphQLUpload scalar literal unsupported.', - 'extensions' => [ - 'category' => 'graphql', - ], - 'locations' => [ - [ - 'line' => 1, - 'column' => 31, - ], + 'errors' => [ + [ + 'message' => 'Field "singleUpload" argument "file" requires type Upload, found {}; GraphQLUpload scalar literal unsupported.', + 'extensions' => [ + 'category' => 'graphql', + ], + 'locations' => [ + [ + 'line' => 1, + 'column' => 31, ], ], ], ], - $result - ); - } + ], + $result + ); } private function assertUpload(array $expected, array $parameters, array $files, $uri = '/', $json = true): void diff --git a/tests/VersionHelper.php b/tests/VersionHelper.php deleted file mode 100644 index 462c42085..000000000 --- a/tests/VersionHelper.php +++ /dev/null @@ -1,36 +0,0 @@ -setWorkingDirectory(__DIR__.'/../'); - $process->run(); - if ($process->isSuccessful()) { - $version = $process->getOutput(); - $version = \preg_replace('/[^.0-9]/', '', $version); - } else { - throw new ProcessFailedException($process); - } - } - - return $version; - } -}