From d8f41e854f97b8e8b82763f7ced1111603db61da Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Tue, 28 Aug 2018 11:28:57 +0200 Subject: [PATCH 01/18] Add static analysis tool --- .gitignore | 2 ++ .travis.yml | 21 +++++++++---------- composer.json | 8 +++++-- src/Executor/Promise/Promise.php | 1 + src/Language/Visitor.php | 1 + src/Server/StandardServer.php | 2 +- src/Validator/Rules/KnownDirectives.php | 6 +++++- .../Rules/VariablesDefaultValueAllowed.php | 4 ++-- 8 files changed, 28 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 6586246..9846927 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ composer.phar composer.lock phpcs.xml vendor/ +bin/ +phpstan.phar diff --git a/.travis.yml b/.travis.yml index b12d6c4..422a238 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,6 @@ php: - 7.2 - nightly -matrix: - allow_failures: - - php: nightly - cache: directories: - $HOME/.composer/cache @@ -18,12 +14,9 @@ before_install: - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available" - travis_retry composer self-update -install: - - composer require react/promise:2.* - - composer require psr/http-message:1.* - - travis_retry composer update --prefer-dist +install: composer install --dev --prefer-dist -script: ./vendor/bin/phpunit --group default,ReactPromise +script: bin/phpunit --group default,ReactPromise jobs: allow_failures: @@ -41,13 +34,19 @@ jobs: - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,} - if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi script: - - ./vendor/bin/phpunit --coverage-clover clover.xml + - bin/phpunit --coverage-clover clover.xml after_script: - wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover clover.xml - - stage: Coding standard + - stage: Code Quality php: 7.1 install: travis_retry composer install --prefer-dist script: - ./vendor/bin/phpcs + + - stage: Code Quality + php: 7.2 + env: STATIC_ANALYSIS + install: travis_retry composer install --prefer-dist + script: composer static-analysis diff --git a/composer.json b/composer.json index d0a9d34..b36b258 100644 --- a/composer.json +++ b/composer.json @@ -16,9 +16,12 @@ "require-dev": { "doctrine/coding-standard": "^4.0", "phpunit/phpunit": "^7.2", - "psr/http-message": "^1.0" + "phpstan/phpstan-shim": "^0.10", + "psr/http-message": "^1.0", + "react/promise": "2.*" }, "config": { + "bin-dir": "bin", "preferred-install": "dist", "sort-packages": true }, @@ -39,6 +42,7 @@ "psr/http-message": "To use standard GraphQL server" }, "scripts": { - "lint" : "phpcs" + "lint" : "phpcs", + "static-analysis": "@php bin/phpstan.phar analyse --ansi -l 1 -c phpstan.neon src" } } diff --git a/src/Executor/Promise/Promise.php b/src/Executor/Promise/Promise.php index 8079663..2f060e1 100644 --- a/src/Executor/Promise/Promise.php +++ b/src/Executor/Promise/Promise.php @@ -6,6 +6,7 @@ namespace GraphQL\Executor\Promise; use GraphQL\Executor\Promise\Adapter\SyncPromise; use GraphQL\Utils\Utils; +use React\Promise\Promise as ReactPromise; /** * Convenience wrapper for promises represented by Promise Adapter diff --git a/src/Language/Visitor.php b/src/Language/Visitor.php index e266f0f..bab8079 100644 --- a/src/Language/Visitor.php +++ b/src/Language/Visitor.php @@ -264,6 +264,7 @@ class Visitor if ($visitFn) { $result = call_user_func($visitFn, $node, $key, $parent, $path, $ancestors); + $editValue = null; if ($result !== null) { if ($result instanceof VisitorOperation) { diff --git a/src/Server/StandardServer.php b/src/Server/StandardServer.php index c631a83..92a8f3d 100644 --- a/src/Server/StandardServer.php +++ b/src/Server/StandardServer.php @@ -8,7 +8,7 @@ use GraphQL\Error\FormattedError; use GraphQL\Error\InvariantViolation; use GraphQL\Executor\ExecutionResult; use GraphQL\Executor\Promise\Promise; -use GraphQL\Utils; +use GraphQL\Utils\Utils; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamInterface; diff --git a/src/Validator/Rules/KnownDirectives.php b/src/Validator/Rules/KnownDirectives.php index ecccafd..a1b9fe5 100644 --- a/src/Validator/Rules/KnownDirectives.php +++ b/src/Validator/Rules/KnownDirectives.php @@ -7,7 +7,9 @@ namespace GraphQL\Validator\Rules; use GraphQL\Error\Error; use GraphQL\Language\AST\DirectiveNode; use GraphQL\Language\AST\InputObjectTypeDefinitionNode; +use GraphQL\Language\AST\Node; use GraphQL\Language\AST\NodeKind; +use GraphQL\Language\AST\NodeList; use GraphQL\Language\DirectiveLocation; use GraphQL\Validator\ValidationContext; use function count; @@ -59,7 +61,9 @@ class KnownDirectives extends ValidationRule } /** - * @param (Node|NodeList)[] $ancestors + * @param Node[]|NodeList[] $ancestors + * + * @return string */ private function getDirectiveLocationForASTPath(array $ancestors) { diff --git a/src/Validator/Rules/VariablesDefaultValueAllowed.php b/src/Validator/Rules/VariablesDefaultValueAllowed.php index 64808fc..4f2b5cf 100644 --- a/src/Validator/Rules/VariablesDefaultValueAllowed.php +++ b/src/Validator/Rules/VariablesDefaultValueAllowed.php @@ -44,10 +44,10 @@ class VariablesDefaultValueAllowed extends ValidationRule return Visitor::skipNode(); }, - NodeKind::SELECTION_SET => function (SelectionSetNode $node) use ($context) { + NodeKind::SELECTION_SET => function (SelectionSetNode $node) { return Visitor::skipNode(); }, - NodeKind::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $node) use ($context) { + NodeKind::FRAGMENT_DEFINITION => function (FragmentDefinitionNode $node) { return Visitor::skipNode(); }, ]; From 31601d710b741cc698b2ea551acfed56280a8e47 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Tue, 28 Aug 2018 12:00:07 +0200 Subject: [PATCH 02/18] Add default config file --- phpstan.neon | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 phpstan.neon diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..e69de29 From 05dbc0fb961d43a8937760e7bc7f88a6944df234 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Tue, 28 Aug 2018 13:30:11 +0200 Subject: [PATCH 03/18] Fix sprintf call --- src/Type/Definition/InputObjectType.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Type/Definition/InputObjectType.php b/src/Type/Definition/InputObjectType.php index 0e39c05..4b4bb52 100644 --- a/src/Type/Definition/InputObjectType.php +++ b/src/Type/Definition/InputObjectType.php @@ -12,7 +12,6 @@ use function is_array; use function is_callable; use function is_string; use function sprintf; -use function spritnf; /** * Class InputObjectType @@ -70,7 +69,7 @@ class InputObjectType extends Type implements InputType, NamedType if (! is_array($fields)) { throw new InvariantViolation( - spritnf('%s fields must be an array or a callable which returns such an array.', $this->name) + sprintf('%s fields must be an array or a callable which returns such an array.', $this->name) ); } From 18954ea6556ab03de927887a80fe05a232f5bab4 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Tue, 28 Aug 2018 13:30:58 +0200 Subject: [PATCH 04/18] Fix typehint --- src/Type/Definition/InputObjectField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Type/Definition/InputObjectField.php b/src/Type/Definition/InputObjectField.php index 793994b..5ceb3f4 100644 --- a/src/Type/Definition/InputObjectField.php +++ b/src/Type/Definition/InputObjectField.php @@ -21,7 +21,7 @@ class InputObjectField /** @var string|null */ public $description; - /** @var callback|InputType */ + /** @var callable|InputType */ public $type; /** @var InputValueDefinitionNode|null */ From 6866779d26defe52f8880e9359e87756aaaddea6 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Tue, 28 Aug 2018 13:32:01 +0200 Subject: [PATCH 05/18] Remove bin custom path --- .travis.yml | 4 ++-- composer.json | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 422a238..6bce85e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ before_install: install: composer install --dev --prefer-dist -script: bin/phpunit --group default,ReactPromise +script: ./vendor/bin/phpunit --group default,ReactPromise jobs: allow_failures: @@ -34,7 +34,7 @@ jobs: - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,} - if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi script: - - bin/phpunit --coverage-clover clover.xml + - ./vendor/bin/phpunit --coverage-clover clover.xml after_script: - wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover clover.xml diff --git a/composer.json b/composer.json index b36b258..bfd5c65 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,6 @@ "react/promise": "2.*" }, "config": { - "bin-dir": "bin", "preferred-install": "dist", "sort-packages": true }, From da70134c384c3d76ddf5bf0331249a516d1a9e97 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Tue, 28 Aug 2018 13:33:32 +0200 Subject: [PATCH 06/18] Fix travis globale install --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6bce85e..3bb963d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ before_install: - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available" - travis_retry composer self-update -install: composer install --dev --prefer-dist +install: travis_retry composer update --prefer-dist script: ./vendor/bin/phpunit --group default,ReactPromise From 6a4c815b6df84e9cb266f110365e03ec1f40d2c6 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Tue, 28 Aug 2018 13:35:49 +0200 Subject: [PATCH 07/18] Cleanup composer script --- .gitignore | 2 -- composer.json | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 9846927..6586246 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,3 @@ composer.phar composer.lock phpcs.xml vendor/ -bin/ -phpstan.phar diff --git a/composer.json b/composer.json index bfd5c65..aa9fd95 100644 --- a/composer.json +++ b/composer.json @@ -42,6 +42,6 @@ }, "scripts": { "lint" : "phpcs", - "static-analysis": "@php bin/phpstan.phar analyse --ansi -l 1 -c phpstan.neon src" + "static-analysis": "@php ./vendor/bin/phpstan.phar analyse --ansi -l 1 -c phpstan.neon src" } } From b5b27c95b164d34edd2c8d3fa4327e157687813d Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Fri, 31 Aug 2018 10:55:59 +0200 Subject: [PATCH 08/18] Also check tests folder --- composer.json | 5 +++-- phpstan.neon | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index aa9fd95..af85fb9 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,9 @@ }, "require-dev": { "doctrine/coding-standard": "^4.0", + "phpstan/phpstan": "^0.10.3", + "phpstan/phpstan-phpunit": "^0.10.0", "phpunit/phpunit": "^7.2", - "phpstan/phpstan-shim": "^0.10", "psr/http-message": "^1.0", "react/promise": "2.*" }, @@ -42,6 +43,6 @@ }, "scripts": { "lint" : "phpcs", - "static-analysis": "@php ./vendor/bin/phpstan.phar analyse --ansi -l 1 -c phpstan.neon src" + "static-analysis": "@php ./vendor/bin/phpstan analyse --ansi -l 1 -c phpstan.neon src tests" } } diff --git a/phpstan.neon b/phpstan.neon index e69de29..b2b86dc 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -0,0 +1,3 @@ +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-phpunit/rules.neon From eb7ff7048d5460a78a9c92b0a5def98f382a2bae Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Fri, 31 Aug 2018 11:22:03 +0200 Subject: [PATCH 09/18] Removed unused use for anonymous functions --- tests/Executor/ExecutorTest.php | 2 +- tests/Language/ParserTest.php | 4 ++-- tests/Language/VisitorTest.php | 4 ++-- tests/Server/QueryExecutionTest.php | 4 ++-- tests/Type/EnumTypeTest.php | 2 +- tests/Type/ValidationTest.php | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/Executor/ExecutorTest.php b/tests/Executor/ExecutorTest.php index f462c15..64b6eb7 100644 --- a/tests/Executor/ExecutorTest.php +++ b/tests/Executor/ExecutorTest.php @@ -329,7 +329,7 @@ class ExecutorTest extends TestCase 'fields' => [ 'a' => [ 'type' => Type::string(), - 'resolve' => function ($context) use ($doc, &$gotHere) { + 'resolve' => function ($context) use (&$gotHere) { $this->assertEquals('thing', $context['contextThing']); $gotHere = true; }, diff --git a/tests/Language/ParserTest.php b/tests/Language/ParserTest.php index 360e5a1..49f461a 100644 --- a/tests/Language/ParserTest.php +++ b/tests/Language/ParserTest.php @@ -331,7 +331,7 @@ GRAPHQL '); $result = Parser::parse($source); - $loc = function ($start, $end) use ($source) { + $loc = function ($start, $end) { return [ 'start' => $start, 'end' => $end, @@ -442,7 +442,7 @@ GRAPHQL '); $result = Parser::parse($source); - $loc = function ($start, $end) use ($source) { + $loc = function ($start, $end) { return [ 'start' => $start, 'end' => $end, diff --git a/tests/Language/VisitorTest.php b/tests/Language/VisitorTest.php index b3c81f7..5c62397 100644 --- a/tests/Language/VisitorTest.php +++ b/tests/Language/VisitorTest.php @@ -1222,7 +1222,7 @@ class VisitorTest extends ValidatorTestCase $ast, Visitor::visitInParallel([ [ - 'enter' => function ($node) use (&$visited, $ast) { + 'enter' => function ($node) use ($ast) { $this->checkVisitorFnArgs($ast, func_get_args()); if ($node->kind === 'Field' && isset($node->name->value) && $node->name->value === 'b') { return Visitor::removeNode(); @@ -1292,7 +1292,7 @@ class VisitorTest extends ValidatorTestCase $ast, Visitor::visitInParallel([ [ - 'leave' => function ($node) use (&$visited, $ast) { + 'leave' => function ($node) use ($ast) { $this->checkVisitorFnArgs($ast, func_get_args(), true); if ($node->kind === 'Field' && isset($node->name->value) && $node->name->value === 'b') { return Visitor::removeNode(); diff --git a/tests/Server/QueryExecutionTest.php b/tests/Server/QueryExecutionTest.php index b6fc44e..3cba697 100644 --- a/tests/Server/QueryExecutionTest.php +++ b/tests/Server/QueryExecutionTest.php @@ -202,7 +202,7 @@ class QueryExecutionTest extends ServerTestCase $called1 = false; $called2 = false; - $this->config->setValidationRules(function (OperationParams $params) use ($q1, $q2, &$called1, &$called2) { + $this->config->setValidationRules(function (OperationParams $params) use ($q1, &$called1, &$called2) { if ($params->query === $q1) { $called1 = true; @@ -376,7 +376,7 @@ class QueryExecutionTest extends ServerTestCase 'Persistent query loader must return query string or instance of GraphQL\Language\AST\DocumentNode ' . 'but got: {"err":"err"}' ); - $this->config->setPersistentQueryLoader(function ($queryId, OperationParams $params) use (&$called) { + $this->config->setPersistentQueryLoader(function () { return ['err' => 'err']; }); $this->executePersistedQuery('some-id'); diff --git a/tests/Type/EnumTypeTest.php b/tests/Type/EnumTypeTest.php index 55e508d..8445d60 100644 --- a/tests/Type/EnumTypeTest.php +++ b/tests/Type/EnumTypeTest.php @@ -132,7 +132,7 @@ class EnumTypeTest extends TestCase 'type' => Type::boolean(), ], ], - 'resolve' => function ($value, $args) use ($Complex1, $Complex2) { + 'resolve' => function ($value, $args) use ($Complex2) { if (! empty($args['provideGoodValue'])) { // Note: this is one of the references of the internal values which // ComplexEnum allows. diff --git a/tests/Type/ValidationTest.php b/tests/Type/ValidationTest.php index b96f46d..362574b 100644 --- a/tests/Type/ValidationTest.php +++ b/tests/Type/ValidationTest.php @@ -1974,7 +1974,7 @@ class ValidationTest extends TestCase public function testRejectsDifferentInstancesOfTheSameType() : void { // Invalid: always creates new instance vs returning one from registry - $typeLoader = function ($name) use (&$typeLoader) { + $typeLoader = function ($name) { switch ($name) { case 'Query': return new ObjectType([ From 62de403f270c0535c3c17990e95c65a9cc7b8b3f Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Fri, 31 Aug 2018 11:23:02 +0200 Subject: [PATCH 10/18] Use right assert method --- .../Promise/ReactPromiseAdapterTest.php | 26 ++++++++-------- tests/Language/SerializationTest.php | 2 +- tests/Server/QueryExecutionTest.php | 2 +- tests/Server/ServerConfigTest.php | 30 +++++++++---------- tests/Type/ResolutionTest.php | 2 +- tests/Type/ScalarSerializationTest.php | 14 ++++----- tests/Utils/AstFromValueTest.php | 6 ++-- 7 files changed, 40 insertions(+), 42 deletions(-) diff --git a/tests/Executor/Promise/ReactPromiseAdapterTest.php b/tests/Executor/Promise/ReactPromiseAdapterTest.php index e28ba3c..e007ae3 100644 --- a/tests/Executor/Promise/ReactPromiseAdapterTest.php +++ b/tests/Executor/Promise/ReactPromiseAdapterTest.php @@ -31,26 +31,24 @@ class ReactPromiseAdapterTest extends TestCase { $reactAdapter = new ReactPromiseAdapter(); - $this->assertSame( - true, + $this->assertTrue( $reactAdapter->isThenable(new ReactPromise(function () { })) ); - $this->assertSame(true, $reactAdapter->isThenable(new FulfilledPromise())); - $this->assertSame(true, $reactAdapter->isThenable(new RejectedPromise())); - $this->assertSame( - true, + $this->assertTrue($reactAdapter->isThenable(new FulfilledPromise())); + $this->assertTrue($reactAdapter->isThenable(new RejectedPromise())); + $this->assertTrue( $reactAdapter->isThenable(new LazyPromise(function () { })) ); - $this->assertSame(false, $reactAdapter->isThenable(false)); - $this->assertSame(false, $reactAdapter->isThenable(true)); - $this->assertSame(false, $reactAdapter->isThenable(1)); - $this->assertSame(false, $reactAdapter->isThenable(0)); - $this->assertSame(false, $reactAdapter->isThenable('test')); - $this->assertSame(false, $reactAdapter->isThenable('')); - $this->assertSame(false, $reactAdapter->isThenable([])); - $this->assertSame(false, $reactAdapter->isThenable(new \stdClass())); + $this->assertFalse($reactAdapter->isThenable(false)); + $this->assertFalse($reactAdapter->isThenable(true)); + $this->assertFalse($reactAdapter->isThenable(1)); + $this->assertFalse($reactAdapter->isThenable(0)); + $this->assertFalse($reactAdapter->isThenable('test')); + $this->assertFalse($reactAdapter->isThenable('')); + $this->assertFalse($reactAdapter->isThenable([])); + $this->assertFalse($reactAdapter->isThenable(new \stdClass())); } public function testConvertsReactPromisesToGraphQlOnes() : void diff --git a/tests/Language/SerializationTest.php b/tests/Language/SerializationTest.php index a55a509..403dbfb 100644 --- a/tests/Language/SerializationTest.php +++ b/tests/Language/SerializationTest.php @@ -51,7 +51,7 @@ class SerializationTest extends TestCase $expectedVars = get_object_vars($expected); $actualVars = get_object_vars($actual); - $this->assertSame(count($expectedVars), count($actualVars), $err); + $this->assertCount(count($expectedVars), $actualVars, $err); $this->assertEquals(array_keys($expectedVars), array_keys($actualVars), $err); foreach ($expectedVars as $name => $expectedValue) { diff --git a/tests/Server/QueryExecutionTest.php b/tests/Server/QueryExecutionTest.php index 3cba697..2cde99f 100644 --- a/tests/Server/QueryExecutionTest.php +++ b/tests/Server/QueryExecutionTest.php @@ -66,7 +66,7 @@ class QueryExecutionTest extends ServerTestCase $query = '{f1'; $result = $this->executeQuery($query); - $this->assertSame(null, $result->data); + $this->assertNull($result->data); $this->assertCount(1, $result->errors); $this->assertContains( 'Syntax Error: Expected Name, found ', diff --git a/tests/Server/ServerConfigTest.php b/tests/Server/ServerConfigTest.php index 1fc2be8..b02eb38 100644 --- a/tests/Server/ServerConfigTest.php +++ b/tests/Server/ServerConfigTest.php @@ -17,17 +17,17 @@ class ServerConfigTest extends TestCase public function testDefaults() : void { $config = ServerConfig::create(); - $this->assertEquals(null, $config->getSchema()); - $this->assertEquals(null, $config->getContext()); - $this->assertEquals(null, $config->getRootValue()); - $this->assertEquals(null, $config->getErrorFormatter()); - $this->assertEquals(null, $config->getErrorsHandler()); - $this->assertEquals(null, $config->getPromiseAdapter()); - $this->assertEquals(null, $config->getValidationRules()); - $this->assertEquals(null, $config->getFieldResolver()); - $this->assertEquals(null, $config->getPersistentQueryLoader()); - $this->assertEquals(false, $config->getDebug()); - $this->assertEquals(false, $config->getQueryBatching()); + $this->assertNull($config->getSchema()); + $this->assertNull($config->getContext()); + $this->assertNull($config->getRootValue()); + $this->assertNull($config->getErrorFormatter()); + $this->assertNull($config->getErrorsHandler()); + $this->assertNull($config->getPromiseAdapter()); + $this->assertNull($config->getValidationRules()); + $this->assertNull($config->getFieldResolver()); + $this->assertNull($config->getPersistentQueryLoader()); + $this->assertFalse($config->getDebug()); + $this->assertFalse($config->getQueryBatching()); } public function testAllowsSettingSchema() : void @@ -166,10 +166,10 @@ class ServerConfigTest extends TestCase $config = ServerConfig::create(); $config->setDebug(true); - $this->assertSame(true, $config->getDebug()); + $this->assertTrue($config->getDebug()); $config->setDebug(false); - $this->assertSame(false, $config->getDebug()); + $this->assertFalse($config->getDebug()); } public function testAcceptsArray() : void @@ -204,8 +204,8 @@ class ServerConfigTest extends TestCase $this->assertSame($arr['validationRules'], $config->getValidationRules()); $this->assertSame($arr['fieldResolver'], $config->getFieldResolver()); $this->assertSame($arr['persistentQueryLoader'], $config->getPersistentQueryLoader()); - $this->assertSame(true, $config->getDebug()); - $this->assertSame(true, $config->getQueryBatching()); + $this->assertTrue($config->getDebug()); + $this->assertTrue($config->getQueryBatching()); } public function testThrowsOnInvalidArrayKey() : void diff --git a/tests/Type/ResolutionTest.php b/tests/Type/ResolutionTest.php index 352372c..741b13e 100644 --- a/tests/Type/ResolutionTest.php +++ b/tests/Type/ResolutionTest.php @@ -287,7 +287,7 @@ class ResolutionTest extends TestCase ]; $this->assertEquals($expectedDescriptor, $eagerTypeResolution->getDescriptor()); - $this->assertSame(null, $eagerTypeResolution->resolveType('User')); + $this->assertNull($eagerTypeResolution->resolveType('User')); $this->assertSame([], $eagerTypeResolution->resolvePossibleTypes($this->node)); $this->assertSame([], $eagerTypeResolution->resolvePossibleTypes($this->content)); $this->assertSame([], $eagerTypeResolution->resolvePossibleTypes($this->mention)); diff --git a/tests/Type/ScalarSerializationTest.php b/tests/Type/ScalarSerializationTest.php index fa89e01..fce19bc 100644 --- a/tests/Type/ScalarSerializationTest.php +++ b/tests/Type/ScalarSerializationTest.php @@ -186,13 +186,13 @@ class ScalarSerializationTest extends TestCase { $boolType = Type::boolean(); - $this->assertSame(true, $boolType->serialize('string')); - $this->assertSame(false, $boolType->serialize('')); - $this->assertSame(true, $boolType->serialize('1')); - $this->assertSame(true, $boolType->serialize(1)); - $this->assertSame(false, $boolType->serialize(0)); - $this->assertSame(true, $boolType->serialize(true)); - $this->assertSame(false, $boolType->serialize(false)); + $this->assertTrue($boolType->serialize('string')); + $this->assertFalse($boolType->serialize('')); + $this->assertTrue($boolType->serialize('1')); + $this->assertTrue($boolType->serialize(1)); + $this->assertFalse($boolType->serialize(0)); + $this->assertTrue($boolType->serialize(true)); + $this->assertFalse($boolType->serialize(false)); // TODO: how should it behave on '0'? } diff --git a/tests/Utils/AstFromValueTest.php b/tests/Utils/AstFromValueTest.php index da5156c..2f56a53 100644 --- a/tests/Utils/AstFromValueTest.php +++ b/tests/Utils/AstFromValueTest.php @@ -126,7 +126,7 @@ class AstFromValueTest extends TestCase */ public function testDoesNotConvertsNonNullValuestoNullValue() : void { - $this->assertSame(null, AST::astFromValue(null, Type::nonNull(Type::boolean()))); + $this->assertNull(AST::astFromValue(null, Type::nonNull(Type::boolean()))); } /** @@ -141,10 +141,10 @@ class AstFromValueTest extends TestCase ); // Note: case sensitive - $this->assertEquals(null, AST::astFromValue('hello', $this->myEnum())); + $this->assertNull(AST::astFromValue('hello', $this->myEnum())); // Note: Not a valid enum value - $this->assertEquals(null, AST::astFromValue('VALUE', $this->myEnum())); + $this->assertNull(AST::astFromValue('VALUE', $this->myEnum())); } /** From 7428cb8a319413a5890dad8353a6057f069ee3ce Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Fri, 31 Aug 2018 11:24:56 +0200 Subject: [PATCH 11/18] Fix namespaces --- tests/Language/SchemaPrinterTest.php | 2 +- tests/Language/TokenTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Language/SchemaPrinterTest.php b/tests/Language/SchemaPrinterTest.php index 760d036..8c90401 100644 --- a/tests/Language/SchemaPrinterTest.php +++ b/tests/Language/SchemaPrinterTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace GraphQL\Tests; +namespace GraphQL\Tests\Language; use GraphQL\Language\AST\NameNode; use GraphQL\Language\AST\ScalarTypeDefinitionNode; diff --git a/tests/Language/TokenTest.php b/tests/Language/TokenTest.php index cb78c4e..54fc245 100644 --- a/tests/Language/TokenTest.php +++ b/tests/Language/TokenTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace GraphQL\Tests; +namespace GraphQL\Tests\Language; use GraphQL\Language\Token; use PHPUnit\Framework\TestCase; From ff0733d013a13d3354beb2d15d6f22ec729df242 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Fri, 31 Aug 2018 11:31:00 +0200 Subject: [PATCH 12/18] Use .dist extension --- .gitignore | 1 + composer.json | 2 +- phpstan.neon => phpstan.neon.dist | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename phpstan.neon => phpstan.neon.dist (100%) diff --git a/.gitignore b/.gitignore index 6586246..c529ad8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.phar composer.lock phpcs.xml vendor/ +phpstan.neon diff --git a/composer.json b/composer.json index af85fb9..f871e1b 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,6 @@ }, "scripts": { "lint" : "phpcs", - "static-analysis": "@php ./vendor/bin/phpstan analyse --ansi -l 1 -c phpstan.neon src tests" + "static-analysis": "@php ./vendor/bin/phpstan analyse --ansi -l 1 -c phpstan.neon.dist src tests" } } diff --git a/phpstan.neon b/phpstan.neon.dist similarity index 100% rename from phpstan.neon rename to phpstan.neon.dist From 21a7611820d449cabbe27d74fc9b654db3246d94 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Fri, 31 Aug 2018 11:42:36 +0200 Subject: [PATCH 13/18] fix script path --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f871e1b..152bcdf 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,6 @@ }, "scripts": { "lint" : "phpcs", - "static-analysis": "@php ./vendor/bin/phpstan analyse --ansi -l 1 -c phpstan.neon.dist src tests" + "static-analysis": "phpstan analyse --ansi -l 1 -c phpstan.neon.dist src tests" } } From be12d6f273234563a1b910fe269c39b5d04d885f Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Fri, 31 Aug 2018 13:32:36 +0200 Subject: [PATCH 14/18] Sort gitignore alphabetic --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c529ad8..0166075 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ composer.phar composer.lock phpcs.xml -vendor/ phpstan.neon +vendor/ From 2f63387864d2f5af57efed2d9bc5b72ec11fc2e4 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Sun, 2 Sep 2018 17:23:07 +0200 Subject: [PATCH 15/18] Add CODING_STANDARD env var --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3bb963d..db13416 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,6 +41,7 @@ jobs: - stage: Code Quality php: 7.1 + env: CODING_STANDARD install: travis_retry composer install --prefer-dist script: - ./vendor/bin/phpcs From eed9cc7f1b5aa574279ad00c59468e93486dc827 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Sun, 2 Sep 2018 17:26:03 +0200 Subject: [PATCH 16/18] Give some love to PHP CS --- src/Language/Visitor.php | 2 +- src/Validator/Rules/KnownDirectives.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Language/Visitor.php b/src/Language/Visitor.php index bab8079..94c83e7 100644 --- a/src/Language/Visitor.php +++ b/src/Language/Visitor.php @@ -263,7 +263,7 @@ class Visitor $visitFn = self::getVisitFn($visitor, $node->kind, $isLeaving); if ($visitFn) { - $result = call_user_func($visitFn, $node, $key, $parent, $path, $ancestors); + $result = call_user_func($visitFn, $node, $key, $parent, $path, $ancestors); $editValue = null; if ($result !== null) { diff --git a/src/Validator/Rules/KnownDirectives.php b/src/Validator/Rules/KnownDirectives.php index a1b9fe5..e9a0b8c 100644 --- a/src/Validator/Rules/KnownDirectives.php +++ b/src/Validator/Rules/KnownDirectives.php @@ -61,7 +61,7 @@ class KnownDirectives extends ValidationRule } /** - * @param Node[]|NodeList[] $ancestors + * @param Node[]|NodeList[] $ancestors The type is actually (Node|NodeList)[] but this PSR-5 syntax is so far not supported by most of the tools * * @return string */ From 48c6f566400b2162f30c44c3b016d2091e001ba4 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Sun, 2 Sep 2018 17:47:58 +0200 Subject: [PATCH 17/18] Use php 7.1 build instead of 7.2 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index db13416..95f327c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,7 +47,7 @@ jobs: - ./vendor/bin/phpcs - stage: Code Quality - php: 7.2 + php: 7.1 env: STATIC_ANALYSIS install: travis_retry composer install --prefer-dist script: composer static-analysis From a400f27dce88260a692db20a8655ac9dc58180a7 Mon Sep 17 00:00:00 2001 From: Jeremiah VALERIE Date: Sun, 2 Sep 2018 18:25:41 +0200 Subject: [PATCH 18/18] Ignore phpcs cache file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0166075..3f9bc5e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.phpcs-cache composer.phar composer.lock phpcs.xml