Skip to content

Commit 0aef7ef

Browse files
committed
Merge branch '0.11'
2 parents 8c45095 + 674adde commit 0aef7ef

File tree

11 files changed

+105
-16
lines changed

11 files changed

+105
-16
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ script: composer test
3030

3131
jobs:
3232
include:
33-
- php: 7.2
33+
- php: 7.1
3434
env: SYMFONY_VERSION=3.4.*
3535
- php: 7.2
3636
env: SYMFONY_VERSION=4.0.*

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
"symfony/framework-bundle": "^3.4 || ^4.0",
3838
"symfony/options-resolver": "^3.4 || ^4.0",
3939
"symfony/property-access": "^3.4 || ^4.0",
40-
"webonyx/graphql-php": "^0.12.0"
41-
},
40+
"webonyx/graphql-php": "^0.13.0"
41+
},
4242
"replace": {
4343
"overblog/graphql-php-generator": "self.version"
4444
},

lib/generator/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"require": {
1818
"php": ">=7.1",
19-
"webonyx/graphql-php": "^0.11.2|^0.12.0"
19+
"webonyx/graphql-php": "^0.13.0"
2020
},
2121
"require-dev": {
2222
"friendsofphp/php-cs-fixer": "^2.14",

tests/Config/Parser/GraphQLParserTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\CustomScalarNode;
88
use Overblog\GraphQLBundle\Config\Parser\GraphQLParser;
9+
use Overblog\GraphQLBundle\Tests\VersionHelper;
910
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1011
use Symfony\Component\DependencyInjection\ContainerBuilder;
1112
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;

tests/Error/ErrorHandlerTest.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Overblog\GraphQLBundle\Error\UserError;
1212
use Overblog\GraphQLBundle\Error\UserErrors;
1313
use Overblog\GraphQLBundle\Error\UserWarning;
14+
use Overblog\GraphQLBundle\Tests\VersionHelper;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Component\EventDispatcher\EventDispatcher;
1617

@@ -86,7 +87,7 @@ public function testMaskErrorWithThrowExceptionSetToFalse(): void
8687
],
8788
];
8889

89-
$this->assertSame($expected, $executionResult->toArray());
90+
$this->assertSame(VersionHelper::normalizedPayload($expected), $executionResult->toArray());
9091
}
9192

9293
public function testMaskErrorWithWrappedExceptionAndThrowExceptionSetToTrue(): void
@@ -135,7 +136,7 @@ public function testMaskErrorWithWrappedUserErrorAndThrowExceptionSetToTrue(): v
135136
],
136137
];
137138

138-
$this->assertSame($expected, $executionResult->toArray());
139+
$this->assertSame(VersionHelper::normalizedPayload($expected), $executionResult->toArray());
139140
}
140141

141142
public function testDebugEnabled(): void
@@ -181,7 +182,7 @@ public function testMaskErrorWithoutWrappedExceptionAndThrowExceptionSetToTrue()
181182
],
182183
];
183184

184-
$this->assertSame($expected, $executionResult->toArray());
185+
$this->assertSame(VersionHelper::normalizedPayload($expected), $executionResult->toArray());
185186
}
186187

187188
public function testConvertExceptionToUserWarning(): void
@@ -208,7 +209,7 @@ public function testConvertExceptionToUserWarning(): void
208209
],
209210
];
210211

211-
$this->assertSame($expected, $executionResult->toArray());
212+
$this->assertSame(VersionHelper::normalizedPayload($expected), $executionResult->toArray());
212213
}
213214

214215
/**
@@ -242,7 +243,7 @@ public function testConvertExceptionUsingParentExceptionMatchesAlwaysFirstExactE
242243
$errorHandler->handleErrors($executionResult, true);
243244

244245
if (\is_array($expectedUserError)) {
245-
$this->assertSame($expectedUserError, $executionResult->toArray());
246+
$this->assertSame(VersionHelper::normalizedPayload($expectedUserError), $executionResult->toArray());
246247
}
247248
}
248249

tests/Functional/Command/GraphDumpSchemaCommandTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Overblog\GraphQLBundle\Tests\Functional\Command;
66

77
use Overblog\GraphQLBundle\Tests\Functional\TestCase;
8+
use Overblog\GraphQLBundle\Tests\VersionHelper;
89
use Symfony\Component\Console\Command\Command;
910
use Symfony\Component\Console\Tester\CommandTester;
1011

tests/Functional/Exception/ExceptionTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Overblog\GraphQLBundle\Tests\Functional\Exception;
66

77
use Overblog\GraphQLBundle\Tests\Functional\TestCase;
8+
use Overblog\GraphQLBundle\Tests\VersionHelper;
89

910
class ExceptionTest extends TestCase
1011
{
@@ -41,6 +42,6 @@ public function testExceptionIsMappedToAWarning(): void
4142
],
4243
];
4344

44-
$this->assertGraphQL($query, $expectedData, $expectedErrors);
45+
$this->assertGraphQL($query, $expectedData, VersionHelper::normalizedErrors($expectedErrors));
4546
}
4647
}

tests/Functional/MultipleQueries/MultipleQueriesTest.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Overblog\GraphQLBundle\Tests\Functional\MultipleQueries;
66

77
use Overblog\GraphQLBundle\Tests\Functional\TestCase;
8+
use Overblog\GraphQLBundle\Tests\VersionHelper;
89

910
class MultipleQueriesTest extends TestCase
1011
{
@@ -62,7 +63,7 @@ public function testRequiredFails(): void
6263
}
6364
EOF;
6465
$result = $this->executeGraphQLRequest($query);
65-
$this->assertSame(self::REQUIRED_FAILS_ERRORS, $result['errors']);
66+
$this->assertSame(VersionHelper::normalizedErrors(self::REQUIRED_FAILS_ERRORS), $result['errors']);
6667
$this->assertTrue(empty($result['data']));
6768
}
6869

@@ -75,7 +76,7 @@ public function testOptionalFails(): void
7576
}
7677
EOF;
7778
$result = $this->executeGraphQLRequest($query);
78-
$this->assertSame(self::OPTIONAL_FAILS, $result);
79+
$this->assertSame(VersionHelper::normalizedPayload(self::OPTIONAL_FAILS), $result);
7980
}
8081

8182
public function testMutationRequiredFails(): void
@@ -87,7 +88,7 @@ public function testMutationRequiredFails(): void
8788
}
8889
EOF;
8990
$result = $this->executeGraphQLRequest($query);
90-
$this->assertSame(self::REQUIRED_FAILS_ERRORS, $result['errors']);
91+
$this->assertSame(VersionHelper::normalizedErrors(self::REQUIRED_FAILS_ERRORS), $result['errors']);
9192
$this->assertTrue(empty($result['data']));
9293
}
9394

@@ -100,6 +101,6 @@ public function testMutationOptionalFails(): void
100101
}
101102
EOF;
102103
$result = $this->executeGraphQLRequest($query);
103-
$this->assertSame(self::OPTIONAL_FAILS, $result);
104+
$this->assertSame(VersionHelper::normalizedPayload(self::OPTIONAL_FAILS), $result);
104105
}
105106
}

tests/Functional/TestCase.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction;
88
use Overblog\GraphQLBundle\Tests\Functional\App\TestKernel;
9+
use Overblog\GraphQLBundle\Tests\VersionHelper;
910
use Symfony\Bundle\FrameworkBundle\Client;
1011
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1112
use Symfony\Component\Filesystem\Filesystem;
@@ -123,7 +124,7 @@ protected static function assertResponse($query, array $expected, $username, $te
123124
$client = self::createClientAuthenticated($username, $testCase, $password);
124125
$result = self::sendRequest($client, $query, false, $variables);
125126

126-
static::assertSame($expected, \json_decode($result, true), $result);
127+
static::assertSame(VersionHelper::normalizedPayload($expected), \json_decode($result, true), $result);
127128

128129
return $client;
129130
}

tests/Resolver/ResolverTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class ResolverTest extends TestCase
1919
*/
2020
public function testDefaultResolveFn($fieldName, $source, $expected): void
2121
{
22-
$info = new ResolveInfo(['fieldName' => $fieldName]);
22+
$info = $this->getMockBuilder(ResolveInfo::class)->disableOriginalConstructor()->getMock();
23+
$info->fieldName = $fieldName;
2324

2425
$this->assertSame($expected, Resolver::defaultResolveFn($source, [], [], $info));
2526
}

tests/VersionHelper.php

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace Overblog\GraphQLBundle\Tests;
4+
5+
use Symfony\Component\Process\Exception\ProcessFailedException;
6+
use Symfony\Component\Process\Process;
7+
8+
class VersionHelper
9+
{
10+
const KEYS_WEIGHT = [
11+
'message' => 100,
12+
'extensions' => 90,
13+
'locations' => 80,
14+
'path' => 70,
15+
];
16+
17+
public static function normalizedPayload(array $payload)
18+
{
19+
if (self::needNormalized()) {
20+
if (!empty($payload['errors'])) {
21+
$payload['errors'] = self::normalizedErrors($payload['errors']);
22+
}
23+
24+
if (!empty($payload['extensions']['warnings'])) {
25+
$payload['extensions']['warnings'] = self::normalizedErrors($payload['extensions']['warnings']);
26+
}
27+
}
28+
29+
return $payload;
30+
}
31+
32+
public static function normalizedErrors(array $errors)
33+
{
34+
if (self::needNormalized()) {
35+
foreach ($errors as &$error) {
36+
foreach ($error as $key => $value) {
37+
if (!\in_array($key, ['message', 'locations', 'path', 'extensions'])) {
38+
$error['extensions'] = isset($error['extensions']) ? $error['extensions'] : [];
39+
$error['extensions'][$key] = $value;
40+
unset($error[$key]);
41+
}
42+
}
43+
44+
\uksort($error, function ($key1, $key2) {
45+
return self::KEYS_WEIGHT[$key1] > self::KEYS_WEIGHT[$key2] ? -1 : 1;
46+
});
47+
}
48+
}
49+
50+
return $errors;
51+
}
52+
53+
public static function needNormalized()
54+
{
55+
return self::compareWebonyxGraphQLPHPVersion('0.13', '>=');
56+
}
57+
58+
public static function compareWebonyxGraphQLPHPVersion($version, $operator)
59+
{
60+
return \version_compare(self::webonyxGraphQLPHPVersion(), $version, $operator);
61+
}
62+
63+
public static function webonyxGraphQLPHPVersion()
64+
{
65+
static $version = null;
66+
67+
if (empty($version)) {
68+
$composerBinPath = \file_exists(__DIR__.'/../composer.phar') ? __DIR__.'/../composer.phar' : '`which composer`';
69+
$process = new Process($composerBinPath.' show \'webonyx/graphql-php\' | grep \'versions\' | grep -o -E \'\*\ .+\' | cut -d\' \' -f2 | cut -d\',\' -f1');
70+
$process->setWorkingDirectory(__DIR__.'/../');
71+
$process->run();
72+
if ($process->isSuccessful()) {
73+
$version = $process->getOutput();
74+
$version = \preg_replace('/[^.0-9]/', '', $version);
75+
} else {
76+
throw new ProcessFailedException($process);
77+
}
78+
}
79+
80+
return $version;
81+
}
82+
}

0 commit comments

Comments
 (0)