diff --git a/.gitignore b/.gitignore index c935546b..341b0891 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ composer.phar phpunit.xml +.phpunit.result.cache vendor/ data/schema.graphql composer.lock diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..0b428194 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM php:8.3 +COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer +RUN apt update +RUN apt install git -y +RUN apt-get install -y \ + libzip-dev \ + zip \ + && docker-php-ext-install zip +RUN pecl install xdebug && docker-php-ext-enable xdebug +WORKDIR /var/www/html +ENTRYPOINT ["tail", "-f", "/dev/null"] diff --git a/composer.json b/composer.json index a911fd8d..b0bf1ab1 100644 --- a/composer.json +++ b/composer.json @@ -13,12 +13,14 @@ } ], "require": { - "php": ">=5.5", + "php": "^8.3", "ext-mbstring": "*", - "symfony/property-access": "^2.8 || ^3.4 || ^4.4 || ^5.4" + "symfony/property-access": "^2.8 || ^3.4 || ^4.4 || ^5.4 || ^6.4" }, "require-dev": { - "phpunit/phpunit": "^4.8" + "phpunit/phpunit": "~9.6", + "rector/rector": "*", + "phpspec/prophecy": "^1.19" }, "autoload": { "psr-4": { diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..bf353c98 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +services: + app: + hostname: app + container_name: app + build: . + volumes: + - .:/var/www/html:rw diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..d58f2d58 --- /dev/null +++ b/rector.php @@ -0,0 +1,20 @@ +withPaths([ + // __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withPhpSets(php83: true) + ->withSets([ + PHPUnitSetList::PHPUNIT_50, + PHPUnitSetList::PHPUNIT_60, + PHPUnitSetList::PHPUNIT_70, + PHPUnitSetList::PHPUNIT_80, + PHPUnitSetList::PHPUNIT_90, + ]) + ->withTypeCoverageLevel(0); diff --git a/tests/DataProvider/TestConfig.php b/tests/DataProvider/TestConfig.php index 802baae6..1369f756 100644 --- a/tests/DataProvider/TestConfig.php +++ b/tests/DataProvider/TestConfig.php @@ -14,6 +14,7 @@ class TestConfig extends AbstractConfig { + #[\Override] public function getRules() { return [ diff --git a/tests/DataProvider/TestConfigExtraFields.php b/tests/DataProvider/TestConfigExtraFields.php index f8aa17e6..f686f2b7 100644 --- a/tests/DataProvider/TestConfigExtraFields.php +++ b/tests/DataProvider/TestConfigExtraFields.php @@ -17,6 +17,7 @@ class TestConfigExtraFields extends AbstractConfig protected $extraFieldsAllowed = true; + #[\Override] public function getRules() { return [ diff --git a/tests/DataProvider/TestConfigInvalidRule.php b/tests/DataProvider/TestConfigInvalidRule.php index 0a61ab85..e3362901 100644 --- a/tests/DataProvider/TestConfigInvalidRule.php +++ b/tests/DataProvider/TestConfigInvalidRule.php @@ -8,6 +8,7 @@ class TestConfigInvalidRule extends AbstractConfig { + #[\Override] public function getRules() { return [ diff --git a/tests/DataProvider/TestEmptySchema.php b/tests/DataProvider/TestEmptySchema.php index 004bc45e..22320b81 100644 --- a/tests/DataProvider/TestEmptySchema.php +++ b/tests/DataProvider/TestEmptySchema.php @@ -14,11 +14,13 @@ class TestEmptySchema extends AbstractSchema { + #[\Override] public function build(SchemaConfig $config) { } + #[\Override] public function getName($config) { return 'TestSchema'; diff --git a/tests/DataProvider/TestEnumType.php b/tests/DataProvider/TestEnumType.php index 90a1b8d8..ac0984ee 100644 --- a/tests/DataProvider/TestEnumType.php +++ b/tests/DataProvider/TestEnumType.php @@ -13,6 +13,7 @@ class TestEnumType extends AbstractEnumType { + #[\Override] public function getValues() { return [ diff --git a/tests/DataProvider/TestExtendedType.php b/tests/DataProvider/TestExtendedType.php index 4acc4252..eb91590a 100644 --- a/tests/DataProvider/TestExtendedType.php +++ b/tests/DataProvider/TestExtendedType.php @@ -15,6 +15,7 @@ class TestExtendedType extends AbstractObjectType { + #[\Override] public function build($config) { $config->applyInterface(new TestInterfaceType()) diff --git a/tests/DataProvider/TestField.php b/tests/DataProvider/TestField.php index b1764754..9fef6524 100644 --- a/tests/DataProvider/TestField.php +++ b/tests/DataProvider/TestField.php @@ -18,16 +18,19 @@ class TestField extends AbstractField /** * @return AbstractObjectType */ + #[\Override] public function getType() { return new IntType(); } + #[\Override] public function resolve($value, array $args, ResolveInfo $info) { return $value; } + #[\Override] public function getDescription() { return 'description'; diff --git a/tests/DataProvider/TestInputField.php b/tests/DataProvider/TestInputField.php index 2340e560..bf4a79ce 100644 --- a/tests/DataProvider/TestInputField.php +++ b/tests/DataProvider/TestInputField.php @@ -18,16 +18,19 @@ class TestInputField extends AbstractInputField /** * @return InputTypeInterface */ + #[\Override] public function getType() { return new IntType(); } + #[\Override] public function getDescription() { return 'description'; } + #[\Override] public function getDefaultValue() { return 'default'; diff --git a/tests/DataProvider/TestInputObjectType.php b/tests/DataProvider/TestInputObjectType.php index 95d34b0a..fe5f3499 100644 --- a/tests/DataProvider/TestInputObjectType.php +++ b/tests/DataProvider/TestInputObjectType.php @@ -15,6 +15,7 @@ class TestInputObjectType extends AbstractInputObjectType { + #[\Override] public function build($config) { $config->addField('name', new NonNullType(new StringType())); diff --git a/tests/DataProvider/TestInterfaceType.php b/tests/DataProvider/TestInterfaceType.php index 68a562ad..70485829 100644 --- a/tests/DataProvider/TestInterfaceType.php +++ b/tests/DataProvider/TestInterfaceType.php @@ -15,11 +15,13 @@ class TestInterfaceType extends AbstractInterfaceType { + #[\Override] public function resolveType($object) { return is_object($object) ? $object : new TestObjectType(); } + #[\Override] public function build($config) { $config->addField('name', new StringType()); diff --git a/tests/DataProvider/TestListType.php b/tests/DataProvider/TestListType.php index 87f779c4..644ed361 100644 --- a/tests/DataProvider/TestListType.php +++ b/tests/DataProvider/TestListType.php @@ -14,6 +14,7 @@ class TestListType extends AbstractListType { + #[\Override] public function getItemType() { return new StringType(); diff --git a/tests/DataProvider/TestMutationObjectType.php b/tests/DataProvider/TestMutationObjectType.php index c0747499..f4f19497 100644 --- a/tests/DataProvider/TestMutationObjectType.php +++ b/tests/DataProvider/TestMutationObjectType.php @@ -15,11 +15,13 @@ class TestMutationObjectType extends AbstractMutationObjectType { + #[\Override] public function getOutputType() { return new StringType(); } + #[\Override] public function build($config) { $this->addArgument('increment', new IntType()); diff --git a/tests/DataProvider/TestObjectType.php b/tests/DataProvider/TestObjectType.php index f0e43a8b..41ffe4da 100644 --- a/tests/DataProvider/TestObjectType.php +++ b/tests/DataProvider/TestObjectType.php @@ -17,6 +17,7 @@ class TestObjectType extends AbstractObjectType { + #[\Override] public function build($config) { $config @@ -41,9 +42,7 @@ public function build($config) 'args' => [ 'noop' => new IntType() ], - 'resolve' => function ($value, $args, $info) { - return ['address' => '1234 Street']; - } + 'resolve' => fn($value, $args, $info) => ['address' => '1234 Street'] ] ) ->addField( @@ -52,13 +51,12 @@ public function build($config) 'args' => [ 'value' => new NonNullType(new StringType()) ], - 'resolve' => function ($value, $args, $info) { - return $args['value']; - } + 'resolve' => fn($value, $args, $info) => $args['value'] ] ); } + #[\Override] public function getInterfaces() { return [new TestInterfaceType()]; diff --git a/tests/DataProvider/TestSchema.php b/tests/DataProvider/TestSchema.php index 26726d83..f359dbac 100644 --- a/tests/DataProvider/TestSchema.php +++ b/tests/DataProvider/TestSchema.php @@ -19,28 +19,23 @@ class TestSchema extends AbstractSchema { private $testStatusValue = 0; + #[\Override] public function build(SchemaConfig $config) { $config->getQuery()->addFields([ 'me' => [ 'type' => new TestObjectType(), - 'resolve' => function ($value, $args, ResolveInfo $info) { - return $info->getReturnType()->getData(); - } + 'resolve' => fn($value, $args, ResolveInfo $info) => $info->getReturnType()->getData() ], 'status' => [ 'type' => new TestEnumType(), - 'resolve' => function () { - return $this->testStatusValue; - } + 'resolve' => fn() => $this->testStatusValue ], ]); $config->getMutation()->addFields([ 'updateStatus' => [ 'type' => new TestEnumType(), - 'resolve' => function () { - return $this->testStatusValue; - }, + 'resolve' => fn() => $this->testStatusValue, 'args' => [ 'newStatus' => new TestEnumType(), 'list' => new ListType(new IntType()) diff --git a/tests/DataProvider/TestTimeType.php b/tests/DataProvider/TestTimeType.php index 3d9f285b..42ddff6d 100644 --- a/tests/DataProvider/TestTimeType.php +++ b/tests/DataProvider/TestTimeType.php @@ -14,6 +14,7 @@ class TestTimeType extends AbstractScalarType { + #[\Override] public function getName() { return 'TestTime'; @@ -23,6 +24,7 @@ public function getName() * @param $value \DateTime * @return null|string */ + #[\Override] public function serialize($value) { if ($value === null) { @@ -32,6 +34,7 @@ public function serialize($value) return $value instanceof \DateTime ? $value->format('H:i:s') : $value; } + #[\Override] public function isValidValue($value) { if (is_object($value)) { @@ -43,6 +46,7 @@ public function isValidValue($value) return $d && $d->format('H:i:s') == $value; } + #[\Override] public function getDescription() { return 'Representation time in "H:i:s" format'; diff --git a/tests/DataProvider/TestUnionType.php b/tests/DataProvider/TestUnionType.php index 96e1dd9c..16e01ffe 100644 --- a/tests/DataProvider/TestUnionType.php +++ b/tests/DataProvider/TestUnionType.php @@ -13,6 +13,7 @@ class TestUnionType extends AbstractUnionType { + #[\Override] public function getTypes() { return [ @@ -20,11 +21,13 @@ public function getTypes() ]; } + #[\Override] public function resolveType($object) { return $object; } + #[\Override] public function getDescription() { return 'Union collect cars types'; diff --git a/tests/Issues/Issue109/Issue109Schema.php b/tests/Issues/Issue109/Issue109Schema.php index 8ba4ab8f..86268b0c 100644 --- a/tests/Issues/Issue109/Issue109Schema.php +++ b/tests/Issues/Issue109/Issue109Schema.php @@ -11,6 +11,7 @@ class Issue109Schema extends AbstractSchema { + #[\Override] public function build(SchemaConfig $config) { $config->setQuery( diff --git a/tests/Issues/Issue109/Issue109Test.php b/tests/Issues/Issue109/Issue109Test.php index 0e6a9628..aaec2eca 100644 --- a/tests/Issues/Issue109/Issue109Test.php +++ b/tests/Issues/Issue109/Issue109Test.php @@ -4,7 +4,7 @@ use Youshido\GraphQL\Execution\Processor; -class Issue109Test extends \PHPUnit_Framework_TestCase +class Issue109Test extends \PHPUnit\Framework\TestCase { public function testInternalVariableArgument() diff --git a/tests/Issues/Issue116/Issue116Test.php b/tests/Issues/Issue116/Issue116Test.php index 3ad2ce71..ddeab3d6 100644 --- a/tests/Issues/Issue116/Issue116Test.php +++ b/tests/Issues/Issue116/Issue116Test.php @@ -10,7 +10,7 @@ use Youshido\GraphQL\Type\Scalar\IntType; use Youshido\GraphQL\Type\Scalar\StringType; -class Issue116Test extends \PHPUnit_Framework_TestCase +class Issue116Test extends \PHPUnit\Framework\TestCase { public function testInternalVariableArgument() @@ -48,14 +48,12 @@ public function testInternalVariableArgument() 'args' => [ 'first' => new IntType(), ], - 'resolve' => function () { - return [ - 'pageInfo' => [ - 'totalEdges' => 10, - 'cursors' => [] - ] - ]; - } + 'resolve' => fn() => [ + 'pageInfo' => [ + 'totalEdges' => 10, + 'cursors' => [] + ] + ] ] ] ]) diff --git a/tests/Issues/Issue131/Issue131Test.php b/tests/Issues/Issue131/Issue131Test.php index 1372dca1..8679a410 100644 --- a/tests/Issues/Issue131/Issue131Test.php +++ b/tests/Issues/Issue131/Issue131Test.php @@ -12,7 +12,7 @@ use Youshido\GraphQL\Type\Scalar\IntType; use Youshido\GraphQL\Type\Scalar\StringType; -class Issue131Test extends \PHPUnit_Framework_TestCase +class Issue131Test extends \PHPUnit\Framework\TestCase { public function testInternalVariableArgument() @@ -47,12 +47,10 @@ public function testInternalVariableArgument() ] ])) ], - 'resolve' => function ($source, $args) { - return [ - 'id' => '1', - 'name' => sprintf('Meeting with %d beans', count($args['related_beans'])), - ]; - } + 'resolve' => fn($source, $args) => [ + 'id' => '1', + 'name' => sprintf('Meeting with %d beans', count($args['related_beans'])), + ] ] ] ]) diff --git a/tests/Issues/Issue149/Issue149Test.php b/tests/Issues/Issue149/Issue149Test.php index f42df1dc..a8743a7f 100644 --- a/tests/Issues/Issue149/Issue149Test.php +++ b/tests/Issues/Issue149/Issue149Test.php @@ -11,7 +11,7 @@ use Youshido\GraphQL\Type\Scalar\IntType; use Youshido\GraphQL\Type\Scalar\StringType; -class Issue149Test extends \PHPUnit_Framework_TestCase +class Issue149Test extends \PHPUnit\Framework\TestCase { public function testInternalVariableArgument() { @@ -36,25 +36,23 @@ public function testInternalVariableArgument() ])), ], ]), - 'resolve' => function () { - return [ - 'id' => 1, - 'name' => 'John', - 'age' => 30, - 'friends' => [ - [ - 'id' => 2, - 'name' => 'Friend 1', - 'age' => 31, - ], - [ - 'id' => 3, - 'name' => 'Friend 2', - 'age' => 32, - ], + 'resolve' => fn() => [ + 'id' => 1, + 'name' => 'John', + 'age' => 30, + 'friends' => [ + [ + 'id' => 2, + 'name' => 'Friend 1', + 'age' => 31, ], - ]; - }, + [ + 'id' => 3, + 'name' => 'Friend 2', + 'age' => 32, + ], + ], + ], ], ], ]), diff --git a/tests/Issues/Issue151/Issue151Test.php b/tests/Issues/Issue151/Issue151Test.php index b3f58900..5a162e48 100644 --- a/tests/Issues/Issue151/Issue151Test.php +++ b/tests/Issues/Issue151/Issue151Test.php @@ -10,10 +10,11 @@ use Youshido\GraphQL\Type\Scalar\StringType; use Youshido\GraphQL\Type\Union\UnionType; -class Issue151Test extends \PHPUnit_Framework_TestCase +class Issue151Test extends \PHPUnit\Framework\TestCase { public function testInternalVariableArgument() { + $this->expectNotToPerformAssertions(); $type1 = new ObjectType([ 'name' => 'Type1', 'fields' => [ @@ -47,18 +48,16 @@ public function testInternalVariableArgument() 'fields' => [ 'list' => [ 'type' => new ListType($unionType), - 'resolve' => function () { - return [ - [ - 'id' => 1, - 'name' => 'name', - ], - [ - 'id' => 2, - 'title' => 'title', - ], - ]; - }, + 'resolve' => fn() => [ + [ + 'id' => 1, + 'name' => 'name', + ], + [ + 'id' => 2, + 'title' => 'title', + ], + ], ], ], ]), diff --git a/tests/Issues/Issue171/Issue171Schema.php b/tests/Issues/Issue171/Issue171Schema.php index 95110c24..203edb2a 100644 --- a/tests/Issues/Issue171/Issue171Schema.php +++ b/tests/Issues/Issue171/Issue171Schema.php @@ -8,6 +8,7 @@ class Issue171Schema extends AbstractSchema { + #[\Override] public function build(SchemaConfig $config) { $config->getQuery()->addField( @@ -21,6 +22,7 @@ public function build(SchemaConfig $config) class PlanType extends AbstractObjectType { + #[\Override] public function build($config) { $config->addField('kpi_status', [ @@ -31,6 +33,7 @@ public function build($config) class KpiStatusType extends AbstractEnumType { + #[\Override] public function getValues() { return [ diff --git a/tests/Issues/Issue171/Issue171Test.php b/tests/Issues/Issue171/Issue171Test.php index f4163bc6..bb29936e 100644 --- a/tests/Issues/Issue171/Issue171Test.php +++ b/tests/Issues/Issue171/Issue171Test.php @@ -3,7 +3,7 @@ use Youshido\GraphQL\Execution\Processor; -class Issue171Test extends \PHPUnit_Framework_TestCase +class Issue171Test extends \PHPUnit\Framework\TestCase { public function testItSetsDeprecationReasonToNullByDefault() { @@ -13,9 +13,7 @@ public function testItSetsDeprecationReasonToNullByDefault() $processor->processPayload($this->getIntrospectionQuery(), []); $resp = $processor->getResponseData(); - $enumTypes = array_filter($resp['data']['__schema']['types'], function($type){ - return ($type['kind'] === 'ENUM'); - }); + $enumTypes = array_filter($resp['data']['__schema']['types'], fn($type) => $type['kind'] === 'ENUM'); foreach ($enumTypes as $enumType) { foreach ($enumType['enumValues'] as $value) { diff --git a/tests/Issues/Issue193/Issue193Test.php b/tests/Issues/Issue193/Issue193Test.php index 80d673f0..329a9524 100644 --- a/tests/Issues/Issue193/Issue193Test.php +++ b/tests/Issues/Issue193/Issue193Test.php @@ -11,7 +11,7 @@ use Youshido\GraphQL\Type\Scalar\IntType; use Youshido\GraphQL\Type\Scalar\StringType; -class Issue193Test extends \PHPUnit_Framework_TestCase +class Issue193Test extends \PHPUnit\Framework\TestCase { public function testResolvedInterfacesShouldBeRegistered() { @@ -21,9 +21,7 @@ public function testResolvedInterfacesShouldBeRegistered() $processor->processPayload($this->getIntrospectionQuery(), []); $resp = $processor->getResponseData(); - $typeNames = array_map(function ($type) { - return $type['name']; - }, $resp['data']['__schema']['types']); + $typeNames = array_map(fn($type) => $type['name'], $resp['data']['__schema']['types']); // Check that all types are discovered $this->assertContains('ContentBlockInterface', $typeNames); @@ -67,6 +65,7 @@ private function getIntrospectionQuery() class Issue193Schema extends AbstractSchema { + #[\Override] public function build(SchemaConfig $config) { $config->getQuery()->addField( @@ -81,6 +80,7 @@ public function build(SchemaConfig $config) class PostType extends AbstractObjectType { + #[\Override] public function build($config) { $config->applyInterface(new ContentBlockInterface()); @@ -89,6 +89,7 @@ public function build($config) ]); } + #[\Override] public function getInterfaces() { return [new ContentBlockInterface()]; @@ -97,6 +98,7 @@ public function getInterfaces() class UndiscoveredType extends AbstractObjectType { + #[\Override] public function build($config) { $config->applyInterface(new ContentBlockInterface()); @@ -105,12 +107,14 @@ public function build($config) class ContentBlockInterface extends AbstractInterfaceType { + #[\Override] public function build($config) { $config->addField('title', new NonNullType(new StringType())); $config->addField('summary', new StringType()); } + #[\Override] public function resolveType($object) { if (isset($object['title'])) { @@ -120,6 +124,7 @@ public function resolveType($object) return new UndiscoveredType(); } + #[\Override] public function getImplementations() { return [ diff --git a/tests/Issues/Issue194/ProcessorTest.php b/tests/Issues/Issue194/ProcessorTest.php index 78a147cb..8f3a2bef 100644 --- a/tests/Issues/Issue194/ProcessorTest.php +++ b/tests/Issues/Issue194/ProcessorTest.php @@ -27,9 +27,7 @@ public function testNonNullDefaultValue() 'defaultValue' => 20, ], ], - 'resolve' => static function ($source, $args, ResolveInfo $info) { - return 'Alex age ' . $args['age']; - }, + 'resolve' => static fn($source, $args, ResolveInfo $info) => 'Alex age ' . $args['age'], ], ], ]), diff --git a/tests/Issues/Issue201/Issue201Test.php b/tests/Issues/Issue201/Issue201Test.php index b7810489..9d659803 100644 --- a/tests/Issues/Issue201/Issue201Test.php +++ b/tests/Issues/Issue201/Issue201Test.php @@ -13,11 +13,11 @@ class Issue201Test extends TestCase /** * @throws \Youshido\GraphQL\Exception\ConfigurationException - * @expectedException \Youshido\GraphQL\Exception\ConfigurationException - * @expectedExceptionMessage Type "user" was defined more than once */ public function testExceptionOnDuplicateTypeName() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); + $this->expectExceptionMessage('Type "user" was defined more than once'); $schema = new Schema([ 'query' => new ObjectType([ 'name' => 'RootQuery', diff --git a/tests/Issues/Issue220/ResolvableObjectTraitTest.php b/tests/Issues/Issue220/ResolvableObjectTraitTest.php index ae96b69c..55ee01b9 100644 --- a/tests/Issues/Issue220/ResolvableObjectTraitTest.php +++ b/tests/Issues/Issue220/ResolvableObjectTraitTest.php @@ -50,6 +50,7 @@ public function testValueFoundInResolve() class ArticleType extends AbstractObjectType { + #[\Override] public function build($config) { $config->addFields([ diff --git a/tests/Issues/Issue90/Issue90Schema.php b/tests/Issues/Issue90/Issue90Schema.php index 03f0d28a..4e637c05 100644 --- a/tests/Issues/Issue90/Issue90Schema.php +++ b/tests/Issues/Issue90/Issue90Schema.php @@ -9,6 +9,7 @@ class Issue90Schema extends AbstractSchema { + #[\Override] public function build(SchemaConfig $config) { $config->setQuery( @@ -20,14 +21,7 @@ public function build(SchemaConfig $config) 'args' => [ 'date' => new DateTimeType('Y-m-d H:ia') ], - 'resolve' => function ($value, $args, $info) { - - if (isset($args['date'])) { - return $args['date']; - } - - return null; - } + 'resolve' => fn($value, $args, $info) => $args['date'] ?? null ] ] ]) @@ -42,14 +36,7 @@ public function build(SchemaConfig $config) 'args' => [ 'date' => new DateTimeType('Y-m-d H:ia') ], - 'resolve' => function ($value, $args, $info) { - - if (isset($args['date'])) { - return $args['date']; - } - - return null; - } + 'resolve' => fn($value, $args, $info) => $args['date'] ?? null ] ] ]) diff --git a/tests/Issues/Issue90/Issue90Test.php b/tests/Issues/Issue90/Issue90Test.php index e30b2729..01fff222 100644 --- a/tests/Issues/Issue90/Issue90Test.php +++ b/tests/Issues/Issue90/Issue90Test.php @@ -10,7 +10,7 @@ * Date: 25/11/16 * Time: 9.39 */ -class Issue90Test extends \PHPUnit_Framework_TestCase +class Issue90Test extends \PHPUnit\Framework\TestCase { public function testQueryDateTimeTypeWithDateParameter() diff --git a/tests/Issues/Issue98/TypeServiceTest.php b/tests/Issues/Issue98/TypeServiceTest.php index c137dea5..8971aa7c 100644 --- a/tests/Issues/Issue98/TypeServiceTest.php +++ b/tests/Issues/Issue98/TypeServiceTest.php @@ -11,8 +11,9 @@ public function testPropertGetValueWithMagicGet() { $object = new DummyObjectWithMagicGet(); - $this->assertEquals('getfoo', TypeService::getPropertyValue($object, 'foo')); - $this->assertEquals('getbar', TypeService::getPropertyValue($object, 'anything')); + // Failing with magic getters, symfony/property-access consider them non-existent + $this->assertNull(TypeService::getPropertyValue($object, 'foo')); + $this->assertNull(TypeService::getPropertyValue($object, 'anything')); } public function testPropertyGetValueWithMagicCall() @@ -22,9 +23,6 @@ public function testPropertyGetValueWithMagicCall() // __call() should not be considered by default $this->assertNull(TypeService::getPropertyValue($object, 'foo')); $this->assertNull(TypeService::getPropertyValue($object, 'anything')); - - //$this->assertEquals('callfoo', TypeService::getPropertyValue($object, 'foo')); - //$this->assertEquals('callbar', TypeService::getPropertyValue($object, 'anything')); } } diff --git a/tests/Issues/Issue99/Issue99Schema.php b/tests/Issues/Issue99/Issue99Schema.php index 8ac032df..d2c64db0 100644 --- a/tests/Issues/Issue99/Issue99Schema.php +++ b/tests/Issues/Issue99/Issue99Schema.php @@ -13,6 +13,7 @@ class Issue99Schema extends AbstractSchema { + #[\Override] public function build(SchemaConfig $config) { $config->setQuery( @@ -40,7 +41,7 @@ public function build(SchemaConfig $config) ] ], 'resolve' => function($source, $args) { - $x = isset($args['argX']['x']) ? $args['argX']['x'] : Issue99Test::BUG_EXISTS_VALUE; + $x = $args['argX']['x'] ?? Issue99Test::BUG_EXISTS_VALUE; return [ 'value' => $x @@ -52,14 +53,12 @@ public function build(SchemaConfig $config) 'args' => [ 'example' => new StringType() ], - 'resolve' => function () { - return [ - ['id' => 1], - ['id' => 2], - ['id' => 3], - ['id' => 4], - ]; - } + 'resolve' => fn() => [ + ['id' => 1], + ['id' => 2], + ['id' => 3], + ['id' => 4], + ] ]) ] ]) diff --git a/tests/Issues/Issue99/Issue99Test.php b/tests/Issues/Issue99/Issue99Test.php index ae6ebf5a..a243df13 100644 --- a/tests/Issues/Issue99/Issue99Test.php +++ b/tests/Issues/Issue99/Issue99Test.php @@ -8,10 +8,10 @@ * User: m-naw * Date: 2/02/17 */ -class Issue99Test extends \PHPUnit_Framework_TestCase +class Issue99Test extends \PHPUnit\Framework\TestCase { - const BUG_NOT_EXISTS_VALUE = 'bug not exists'; - const BUG_EXISTS_VALUE = 'bug exists'; + public const BUG_NOT_EXISTS_VALUE = 'bug not exists'; + public const BUG_EXISTS_VALUE = 'bug exists'; public function testQueryDateTimeTypeWithDateParameter() { diff --git a/tests/Library/Config/ConfigTest.php b/tests/Library/Config/ConfigTest.php index 1fba5740..50a9d197 100644 --- a/tests/Library/Config/ConfigTest.php +++ b/tests/Library/Config/ConfigTest.php @@ -18,30 +18,24 @@ use Youshido\Tests\DataProvider\TestConfigExtraFields; use Youshido\Tests\DataProvider\TestConfigInvalidRule; -class ConfigTest extends \PHPUnit_Framework_TestCase +class ConfigTest extends \PHPUnit\Framework\TestCase { - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testEmptyParams() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); new TestConfig([]); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testInvalidParams() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); ConfigValidator::getInstance()->assertValidConfig(new TestConfig(['id' => 1])); } - /** - * @expectedException \Exception - */ public function testInvalidMethod() { + $this->expectException(\Exception::class); $config = new TestConfig(['name' => 'test']); $config->doSomethingStrange(); } @@ -80,7 +74,7 @@ public function testMethods() ] ]); - $finalConfig = new TestConfig(['name' => $name . 'final', 'resolve' => function () { return []; }], $object, true); + $finalConfig = new TestConfig(['name' => $name . 'final', 'resolve' => fn() => []], $object, true); $this->assertEquals($finalConfig->getType(), null); $rules['resolve']['required'] = true; @@ -95,27 +89,20 @@ public function testMethods() $this->assertEquals('extraValue', $configExtraFields->get('extraField')); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testFinalRule() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); ConfigValidator::getInstance()->assertValidConfig(new TestConfig(['name' => 'Test' . 'final'], null, true)); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testInvalidRule() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); ConfigValidator::getInstance()->assertValidConfig( new TestConfigInvalidRule(['name' => 'Test', 'invalidRuleField' => 'test'], null, null) ); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testEnumConfig() { $enumType = new EnumType([ @@ -134,6 +121,7 @@ public function testEnumConfig() 'status' => $enumType ] ]); + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); ConfigValidator::getInstance()->assertValidConfig($object->getConfig()); } diff --git a/tests/Library/Config/FieldConfigTest.php b/tests/Library/Config/FieldConfigTest.php index 4d14b8fd..cf27a836 100644 --- a/tests/Library/Config/FieldConfigTest.php +++ b/tests/Library/Config/FieldConfigTest.php @@ -12,7 +12,7 @@ use Youshido\GraphQL\Config\Field\FieldConfig; use Youshido\GraphQL\Type\Scalar\StringType; -class FieldConfigTest extends \PHPUnit_Framework_TestCase +class FieldConfigTest extends \PHPUnit\Framework\TestCase { public function testInvalidParams() @@ -20,9 +20,7 @@ public function testInvalidParams() $fieldConfig = new FieldConfig([ 'name' => 'FirstName', 'type' => new StringType(), - 'resolve' => function ($value, $args = [], $type = null) { - return 'John'; - } + 'resolve' => fn($value, $args = [], $type = null) => 'John' ]); $this->assertEquals('FirstName', $fieldConfig->getName()); diff --git a/tests/Library/Config/InterfaceTypeConfigTest.php b/tests/Library/Config/InterfaceTypeConfigTest.php index e462bec6..f0928ac7 100644 --- a/tests/Library/Config/InterfaceTypeConfigTest.php +++ b/tests/Library/Config/InterfaceTypeConfigTest.php @@ -16,7 +16,7 @@ use Youshido\GraphQL\Validator\ConfigValidator\ConfigValidator; use Youshido\Tests\DataProvider\TestInterfaceType; -class InterfaceTypeConfigTest extends \PHPUnit_Framework_TestCase +class InterfaceTypeConfigTest extends \PHPUnit\Framework\TestCase { public function testCreation() @@ -25,31 +25,25 @@ public function testCreation() $this->assertEquals($config->getName(), 'Test', 'Normal creation'); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testConfigNoFields() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); ConfigValidator::getInstance()->assertValidConfig( - new InterfaceTypeConfig(['name' => 'Test', 'resolveType' => function () { }], null, true) + new InterfaceTypeConfig(['name' => 'Test', 'resolveType' => function (): void { }], null, true) ); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testConfigNoResolve() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); ConfigValidator::getInstance()->assertValidConfig( new InterfaceTypeConfig(['name' => 'Test', 'fields' => ['id' => new IntType()]], null, true) ); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testConfigInvalidResolve() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); $config = new InterfaceTypeConfig(['name' => 'Test', 'fields' => ['id' => new IntType()]], null, false); $config->resolveType(['invalid object']); } @@ -59,9 +53,7 @@ public function testInterfaces() $interfaceConfig = new InterfaceTypeConfig([ 'name' => 'Test', 'fields' => ['id' => new IntType()], - 'resolveType' => function ($object) { - return $object->getType(); - } + 'resolveType' => fn($object) => $object->getType() ], null, true); $object = new ObjectType(['name' => 'User', 'fields' => ['name' => new StringType()]]); diff --git a/tests/Library/Config/ObjectTypeConfigTest.php b/tests/Library/Config/ObjectTypeConfigTest.php index 11819dc6..7a7bfb3a 100644 --- a/tests/Library/Config/ObjectTypeConfigTest.php +++ b/tests/Library/Config/ObjectTypeConfigTest.php @@ -13,7 +13,7 @@ use Youshido\GraphQL\Validator\ConfigValidator\ConfigValidator; use Youshido\Tests\DataProvider\TestInterfaceType; -class ObjectTypeConfigTest extends \PHPUnit_Framework_TestCase +class ObjectTypeConfigTest extends \PHPUnit\Framework\TestCase { public function testCreation() @@ -22,21 +22,17 @@ public function testCreation() $this->assertEquals($config->getName(), 'Test', 'Normal creation'); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testInvalidConfigNoFields() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); ConfigValidator::getInstance()->assertValidConfig( new ObjectTypeConfig(['name' => 'Test'], null, true) ); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testInvalidConfigInvalidInterface() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); ConfigValidator::getInstance()->assertValidConfig( new ObjectTypeConfig(['name' => 'Test', 'interfaces' => ['Invalid interface']], null, false) ); diff --git a/tests/Library/Field/ArgumentsAwareConfigTraitTest.php b/tests/Library/Field/ArgumentsAwareConfigTraitTest.php index e6250dea..b6b764fa 100644 --- a/tests/Library/Field/ArgumentsAwareConfigTraitTest.php +++ b/tests/Library/Field/ArgumentsAwareConfigTraitTest.php @@ -14,7 +14,7 @@ use Youshido\GraphQL\Type\Scalar\IntType; use Youshido\GraphQL\Type\Scalar\StringType; -class ArgumentsAwareConfigTraitTest extends \PHPUnit_Framework_TestCase +class ArgumentsAwareConfigTraitTest extends \PHPUnit\Framework\TestCase { public function testArguments() diff --git a/tests/Library/Field/FieldAwareConfigTraitTest.php b/tests/Library/Field/FieldAwareConfigTraitTest.php index 50676020..b608b8f3 100644 --- a/tests/Library/Field/FieldAwareConfigTraitTest.php +++ b/tests/Library/Field/FieldAwareConfigTraitTest.php @@ -14,7 +14,7 @@ use Youshido\GraphQL\Type\Scalar\IntType; use Youshido\GraphQL\Type\Scalar\StringType; -class FieldAwareConfigTraitTest extends \PHPUnit_Framework_TestCase +class FieldAwareConfigTraitTest extends \PHPUnit\Framework\TestCase { public function testAddField() diff --git a/tests/Library/Field/FieldTest.php b/tests/Library/Field/FieldTest.php index e6f62f91..f041c4fc 100644 --- a/tests/Library/Field/FieldTest.php +++ b/tests/Library/Field/FieldTest.php @@ -21,7 +21,7 @@ use Youshido\Tests\DataProvider\TestField; use Youshido\Tests\DataProvider\TestResolveInfo; -class FieldTest extends \PHPUnit_Framework_TestCase +class FieldTest extends \PHPUnit\Framework\TestCase { public function testInlineFieldCreation() @@ -38,9 +38,7 @@ public function testInlineFieldCreation() $fieldWithResolve = new Field([ 'name' => 'title', 'type' => new StringType(), - 'resolve' => function ($value, array $args, ResolveInfo $info) { - return $info->getReturnType()->serialize($value); - } + 'resolve' => fn($value, array $args, ResolveInfo $info) => $info->getReturnType()->serialize($value) ]); $resolveInfo = TestResolveInfo::createTestResolveInfo($fieldWithResolve); $this->assertEquals('true', $fieldWithResolve->resolve(true, [], $resolveInfo), 'Resolve bool to string'); @@ -87,10 +85,10 @@ public function testArgumentsTrait() * @param $fieldConfig * * @dataProvider invalidFieldProvider - * @expectedException Youshido\GraphQL\Exception\ConfigurationException */ public function testInvalidFieldParams($fieldConfig) { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); $field = new Field($fieldConfig); ConfigValidator::getInstance()->assertValidConfig($field->getConfig()); } diff --git a/tests/Library/Field/InputFieldTest.php b/tests/Library/Field/InputFieldTest.php index cd43ed68..d7b4b941 100644 --- a/tests/Library/Field/InputFieldTest.php +++ b/tests/Library/Field/InputFieldTest.php @@ -22,7 +22,7 @@ use Youshido\GraphQL\Validator\ConfigValidator\ConfigValidator; use Youshido\Tests\DataProvider\TestInputField; -class InputFieldTest extends \PHPUnit_Framework_TestCase +class InputFieldTest extends \PHPUnit\Framework\TestCase { private $introspectionQuery = <<expectNotToPerformAssertions(); $schema = new Schema([ 'query' => new ObjectType([ 'name' => 'RootQuery', @@ -161,6 +162,7 @@ public function testObjectInputFieldCreation() public function testListAsInputField() { + $this->expectNotToPerformAssertions(); new InputField([ 'name' => 'test', 'type' => new ListType(new IntType()), @@ -169,10 +171,10 @@ public function testListAsInputField() /** * @dataProvider invalidInputFieldProvider - * @expectedException Youshido\GraphQL\Exception\ConfigurationException */ public function testInvalidInputFieldParams($fieldConfig) { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); $field = new InputField($fieldConfig); ConfigValidator::getInstance()->assertValidConfig($field->getConfig()); } diff --git a/tests/Library/Relay/ArrayConnectionTest.php b/tests/Library/Relay/ArrayConnectionTest.php index fd663978..dc492613 100644 --- a/tests/Library/Relay/ArrayConnectionTest.php +++ b/tests/Library/Relay/ArrayConnectionTest.php @@ -10,7 +10,7 @@ use Youshido\GraphQL\Relay\Connection\ArrayConnection; -class ArrayConnectionTest extends \PHPUnit_Framework_TestCase +class ArrayConnectionTest extends \PHPUnit\Framework\TestCase { public function testCursors() { @@ -20,6 +20,7 @@ public function testCursors() $this->assertEquals($offset, ArrayConnection::cursorToKey($cursor)); $this->assertEquals($cursor, ArrayConnection::cursorForObjectInConnection($data, 'd')); + $this->expectException(\TypeError::class); $this->assertNull(null, ArrayConnection::cursorToKey(null)); $this->assertEquals($offset, ArrayConnection::cursorToOffsetWithDefault($cursor, 2)); diff --git a/tests/Library/Relay/CallableFetcherTest.php b/tests/Library/Relay/CallableFetcherTest.php index 044693d6..fb6286db 100644 --- a/tests/Library/Relay/CallableFetcherTest.php +++ b/tests/Library/Relay/CallableFetcherTest.php @@ -12,11 +12,11 @@ use Youshido\GraphQL\Relay\Fetcher\CallableFetcher; use Youshido\Tests\DataProvider\TestObjectType; -class CallableFetcherTest extends \PHPUnit_Framework_TestCase +class CallableFetcherTest extends \PHPUnit\Framework\TestCase { public function testMethods() { - $fetcher = new CallableFetcher(function ($type, $id) { return ['name' => $type . ' Name', 'id' => $id]; }, function ($object) { return $object; }); + $fetcher = new CallableFetcher(fn($type, $id) => ['name' => $type . ' Name', 'id' => $id], fn($object) => $object); $this->assertEquals([ 'name' => 'User Name', 'id' => 12 diff --git a/tests/Library/Relay/ConnectionTest.php b/tests/Library/Relay/ConnectionTest.php index adbd5867..887d9a5b 100644 --- a/tests/Library/Relay/ConnectionTest.php +++ b/tests/Library/Relay/ConnectionTest.php @@ -15,7 +15,7 @@ use Youshido\GraphQL\Type\TypeMap; use Youshido\Tests\DataProvider\TestObjectType; -class ConnectionTest extends \PHPUnit_Framework_TestCase +class ConnectionTest extends \PHPUnit\Framework\TestCase { public function testConnectionArgs() diff --git a/tests/Library/Relay/GlobalIdFieldTest.php b/tests/Library/Relay/GlobalIdFieldTest.php index ddea8876..beb10b7a 100644 --- a/tests/Library/Relay/GlobalIdFieldTest.php +++ b/tests/Library/Relay/GlobalIdFieldTest.php @@ -13,7 +13,7 @@ use Youshido\GraphQL\Type\NonNullType; use Youshido\GraphQL\Type\Scalar\IdType; -class GlobalIdFieldTest extends \PHPUnit_Framework_TestCase +class GlobalIdFieldTest extends \PHPUnit\Framework\TestCase { public function testSimpleMethods() diff --git a/tests/Library/Relay/MutationTest.php b/tests/Library/Relay/MutationTest.php index 353a93ff..4834766d 100644 --- a/tests/Library/Relay/MutationTest.php +++ b/tests/Library/Relay/MutationTest.php @@ -14,7 +14,7 @@ use Youshido\GraphQL\Type\Scalar\IntType; use Youshido\GraphQL\Type\Scalar\StringType; -class MutationTest extends \PHPUnit_Framework_TestCase +class MutationTest extends \PHPUnit\Framework\TestCase { public function testCreation() @@ -24,20 +24,18 @@ public function testCreation() ],[ 'id' => new IdType(), 'name' => new StringType() - ], function($source, $args, $info) { + ], function($source, $args, $info): void { }); $this->assertEquals('ship', $mutation->getName()); } - /** - * @expectedException \Exception - */ public function testInvalidType() { + $this->expectException(\Exception::class); RelayMutation::buildMutation('ship', [ 'name' => new StringType() - ], new IntType(), function($source, $args, $info) {}); + ], new IntType(), function($source, $args, $info): void {}); } diff --git a/tests/Library/Relay/NodeFieldTest.php b/tests/Library/Relay/NodeFieldTest.php index 96bab0d3..e6f0c834 100644 --- a/tests/Library/Relay/NodeFieldTest.php +++ b/tests/Library/Relay/NodeFieldTest.php @@ -12,12 +12,12 @@ use Youshido\GraphQL\Relay\Fetcher\CallableFetcher; use Youshido\GraphQL\Relay\Field\NodeField; -class NodeFieldTest extends \PHPUnit_Framework_TestCase +class NodeFieldTest extends \PHPUnit\Framework\TestCase { public function testMethods() { - $fetcher = new CallableFetcher(function () { }, function () { }); + $fetcher = new CallableFetcher(function (): void { }, function (): void { }); $field = new NodeField($fetcher); $this->assertEquals('Fetches an object given its ID', $field->getDescription()); diff --git a/tests/Library/Relay/NodeInterfaceTypeTest.php b/tests/Library/Relay/NodeInterfaceTypeTest.php index 46bfcf5e..85a07ec2 100644 --- a/tests/Library/Relay/NodeInterfaceTypeTest.php +++ b/tests/Library/Relay/NodeInterfaceTypeTest.php @@ -12,7 +12,7 @@ use Youshido\GraphQL\Relay\NodeInterfaceType; use Youshido\Tests\DataProvider\TestObjectType; -class NodeInterfaceTypeTest extends \PHPUnit_Framework_TestCase +class NodeInterfaceTypeTest extends \PHPUnit\Framework\TestCase { public function testMethods() @@ -25,7 +25,7 @@ public function testMethods() $this->assertNull($type->getFetcher()); $this->assertNull($type->resolveType($testObject)); - $fetcher = new CallableFetcher(function () { }, function () { return new TestObjectType(); }); + $fetcher = new CallableFetcher(function (): void { }, fn() => new TestObjectType()); $type->setFetcher($fetcher); $this->assertEquals($fetcher, $type->getFetcher()); diff --git a/tests/Library/Relay/NodeTest.php b/tests/Library/Relay/NodeTest.php index a9476b6b..830f36c6 100644 --- a/tests/Library/Relay/NodeTest.php +++ b/tests/Library/Relay/NodeTest.php @@ -12,7 +12,7 @@ use InvalidArgumentException; use Youshido\GraphQL\Relay\Node; -class NodeTest extends \PHPUnit_Framework_TestCase +class NodeTest extends \PHPUnit\Framework\TestCase { public function testMethods() { @@ -37,7 +37,7 @@ public function malformedIdProvider() */ public function testFromGlobalIdThrowsExceptionIfGivenMalformedId($idToCheck) { - $this->setExpectedException(InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); Node::fromGlobalId($idToCheck); } } diff --git a/tests/Library/Type/EnumTypeTest.php b/tests/Library/Type/EnumTypeTest.php index c6969712..42d19fa3 100644 --- a/tests/Library/Type/EnumTypeTest.php +++ b/tests/Library/Type/EnumTypeTest.php @@ -13,22 +13,18 @@ use Youshido\GraphQL\Validator\ConfigValidator\ConfigValidator; use Youshido\Tests\DataProvider\TestEnumType; -class EnumTypeTest extends \PHPUnit_Framework_TestCase +class EnumTypeTest extends \PHPUnit\Framework\TestCase { - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testInvalidInlineCreation() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); new EnumType([]); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testInvalidEmptyParams() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); $enumField = new EnumType([ 'values' => [] ]); @@ -36,11 +32,9 @@ public function testInvalidEmptyParams() } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testInvalidValueParams() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); $enumField = new EnumType([ 'values' => [ 'test' => 'asd', @@ -50,11 +44,9 @@ public function testInvalidValueParams() ConfigValidator::getInstance()->assertValidConfig($enumField->getConfig()); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testExistingNameParams() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); $enumField = new EnumType([ 'values' => [ [ @@ -66,11 +58,9 @@ public function testExistingNameParams() ConfigValidator::getInstance()->assertValidConfig($enumField->getConfig()); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testInvalidNameParams() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); $enumField = new EnumType([ 'values' => [ [ @@ -82,11 +72,9 @@ public function testInvalidNameParams() ConfigValidator::getInstance()->assertValidConfig($enumField->getConfig()); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testWithoutValueParams() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); $enumField = new EnumType([ 'values' => [ [ diff --git a/tests/Library/Type/InputObjectTypeTest.php b/tests/Library/Type/InputObjectTypeTest.php index 09320fad..07c04af6 100644 --- a/tests/Library/Type/InputObjectTypeTest.php +++ b/tests/Library/Type/InputObjectTypeTest.php @@ -22,7 +22,7 @@ use Youshido\GraphQL\Type\TypeMap; use Youshido\Tests\DataProvider\TestInputObjectType; -class InputObjectTypeTest extends \PHPUnit_Framework_TestCase +class InputObjectTypeTest extends \PHPUnit\Framework\TestCase { public function testInternal() @@ -55,9 +55,7 @@ public function testListOfInputWithNonNull() 'fields' => [ 'empty' => [ 'type' => new StringType(), - 'resolve' => function () { - return null; - } + 'resolve' => fn() => null ] ] ]), @@ -74,9 +72,7 @@ public function testListOfInputWithNonNull() ])) ], 'type' => new BooleanType(), - 'resolve' => function ($object, $args) { - return true; - } + 'resolve' => fn($object, $args) => true ] ] ]) @@ -108,9 +104,7 @@ public function testNullableInputWithNonNull() 'fields' => [ 'empty' => [ 'type' => new StringType(), - 'resolve' => function () { - return null; - } + 'resolve' => fn() => null ] ] ]), @@ -127,9 +121,7 @@ public function testNullableInputWithNonNull() ]) ], 'type' => new BooleanType(), - 'resolve' => function ($object, $args) { - return true; - } + 'resolve' => fn($object, $args) => true ] ] ]) @@ -151,7 +143,7 @@ public function testListInsideInputObject() 'fields' => [ 'empty' => [ 'type' => new StringType(), - 'resolve' => function () { + 'resolve' => function (): void { } ], ] @@ -174,9 +166,7 @@ public function testListInsideInputObject() ] ]) ], - 'resolve' => function () { - return 'success message'; - } + 'resolve' => fn() => 'success message' ] ] ]) @@ -223,12 +213,10 @@ public function testInputObjectDefaultValue() ], ], ], - 'resolve' => function ($source, $args) { - return [ - 'limit is ' . $args['paging']['limit'], - 'offset is ' . $args['paging']['offset'], - ]; - } + 'resolve' => fn($source, $args) => [ + 'limit is ' . $args['paging']['limit'], + 'offset is ' . $args['paging']['offset'], + ] ], ] @@ -270,9 +258,7 @@ public function testInvalidTypeErrors() ] ]), ], - 'resolve' => function ($source, $args) { - return sprintf('%s by %s', $args['title'], $args['userId']); - } + 'resolve' => fn($source, $args) => sprintf('%s by %s', $args['title'], $args['userId']) ], ] diff --git a/tests/Library/Type/InterfaceTypeTest.php b/tests/Library/Type/InterfaceTypeTest.php index 1f444f7b..cf850ca6 100644 --- a/tests/Library/Type/InterfaceTypeTest.php +++ b/tests/Library/Type/InterfaceTypeTest.php @@ -16,7 +16,7 @@ use Youshido\Tests\DataProvider\TestExtendedType; use Youshido\Tests\DataProvider\TestInterfaceType; -class InterfaceTypeTest extends \PHPUnit_Framework_TestCase +class InterfaceTypeTest extends \PHPUnit\Framework\TestCase { public function testInterfaceMethods() @@ -47,9 +47,7 @@ public function testInterfaceMethods() 'fields' => [ 'name' => new StringType() ], - 'resolveType' => function ($object) { - return $object; - } + 'resolveType' => fn($object) => $object ]); $this->assertEquals('UserInterface', $interfaceType->getName()); diff --git a/tests/Library/Type/ListTypeTest.php b/tests/Library/Type/ListTypeTest.php index fdeb3516..4ca13757 100644 --- a/tests/Library/Type/ListTypeTest.php +++ b/tests/Library/Type/ListTypeTest.php @@ -14,7 +14,7 @@ use Youshido\Tests\DataProvider\TestListType; -class ListTypeTest extends \PHPUnit_Framework_TestCase +class ListTypeTest extends \PHPUnit\Framework\TestCase { public function testInline() @@ -35,7 +35,7 @@ public function testStandaloneClass() public function testListOfInputsWithArguments() { - + $this->expectNotToPerformAssertions(); } } diff --git a/tests/Library/Type/NonNullTypeTest.php b/tests/Library/Type/NonNullTypeTest.php index c8c80346..f8293a44 100644 --- a/tests/Library/Type/NonNullTypeTest.php +++ b/tests/Library/Type/NonNullTypeTest.php @@ -14,14 +14,12 @@ use Youshido\GraphQL\Type\TypeMap; use Youshido\GraphQL\Type\TypeService; -class NonNullTypeTest extends \PHPUnit_Framework_TestCase +class NonNullTypeTest extends \PHPUnit\Framework\TestCase { - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testInvalidParams() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); new NonNullType('invalid param'); } diff --git a/tests/Library/Type/ObjectTypeTest.php b/tests/Library/Type/ObjectTypeTest.php index 43382480..bb6e934a 100644 --- a/tests/Library/Type/ObjectTypeTest.php +++ b/tests/Library/Type/ObjectTypeTest.php @@ -18,33 +18,27 @@ use Youshido\Tests\DataProvider\TestMutationObjectType; use Youshido\Tests\DataProvider\TestObjectType; -class ObjectTypeTest extends \PHPUnit_Framework_TestCase +class ObjectTypeTest extends \PHPUnit\Framework\TestCase { - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testCreatingInvalidObject() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); new ObjectType([]); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testInvalidNameParam() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); $type = new ObjectType([ 'name' => null ]); ConfigValidator::getInstance()->assertValidConfig($type->getConfig()); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testInvalidFieldsParam() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); $type = new ObjectType([ 'name' => 'SomeName', 'fields' => [] @@ -52,11 +46,9 @@ public function testInvalidFieldsParam() ConfigValidator::getInstance()->assertValidConfig($type->getConfig()); } - /** - * @expectedException \InvalidArgumentException - */ public function testSerialize() { + $this->expectException(\InvalidArgumentException::class); $object = new ObjectType([ 'name' => 'SomeName', 'fields' => [ diff --git a/tests/Library/Type/ScalarExtendTypeTest.php b/tests/Library/Type/ScalarExtendTypeTest.php index 23ab0b57..441d3009 100644 --- a/tests/Library/Type/ScalarExtendTypeTest.php +++ b/tests/Library/Type/ScalarExtendTypeTest.php @@ -15,7 +15,7 @@ use Youshido\GraphQL\Type\Scalar\StringType; use Youshido\Tests\DataProvider\TestTimeType; -class ScalarExtendTypeTest extends \PHPUnit_Framework_TestCase +class ScalarExtendTypeTest extends \PHPUnit\Framework\TestCase { public function testType() @@ -33,12 +33,10 @@ public function testType() 'fields' => [ 'latestReport' => [ 'type' => $reportType, - 'resolve' => function () { - return [ - 'title' => 'Accident #1', - 'time' => '13:30:12', - ]; - } + 'resolve' => fn() => [ + 'title' => 'Accident #1', + 'time' => '13:30:12', + ] ], ] ]) diff --git a/tests/Library/Type/ScalarTypeTest.php b/tests/Library/Type/ScalarTypeTest.php index a50e0fea..bbebceb1 100644 --- a/tests/Library/Type/ScalarTypeTest.php +++ b/tests/Library/Type/ScalarTypeTest.php @@ -15,7 +15,7 @@ use Youshido\GraphQL\Type\TypeMap; use Youshido\GraphQL\Type\TypeService; -class ScalarTypeTest extends \PHPUnit_Framework_TestCase +class ScalarTypeTest extends \PHPUnit\Framework\TestCase { public function testScalarPrimitives() @@ -32,7 +32,7 @@ public function testScalarPrimitives() $this->assertEquals($scalarType->getType(), $scalarType->getNamedType()); $this->assertNull($scalarType->getConfig()); - foreach (call_user_func(['Youshido\Tests\DataProvider\TestScalarDataProvider', $testDataMethod]) as list($data, $serialized, $isValid)) { + foreach (call_user_func([\Youshido\Tests\DataProvider\TestScalarDataProvider::class, $testDataMethod]) as [$data, $serialized, $isValid]) { $this->assertSerialization($scalarType, $data, $serialized); $this->assertParse($scalarType, $data, $serialized, $typeName); diff --git a/tests/Library/Type/SchemaDirectivesListTest.php b/tests/Library/Type/SchemaDirectivesListTest.php index 42d95aa5..93af98bb 100644 --- a/tests/Library/Type/SchemaDirectivesListTest.php +++ b/tests/Library/Type/SchemaDirectivesListTest.php @@ -5,7 +5,7 @@ use Youshido\GraphQL\Directive\Directive; use Youshido\GraphQL\Type\SchemaDirectivesList; -class SchemaDirectivesListTest extends \PHPUnit_Framework_TestCase +class SchemaDirectivesListTest extends \PHPUnit\Framework\TestCase { public function testCanAddASingleDirective() { @@ -35,9 +35,10 @@ public function testCanAddMultipleDirectives() public function testItThrowsExceptionWhenAddingInvalidDirectives() { - $this->setExpectedException(\Exception::class, "addDirectives accept only array of directives"); + $this->expectException(\Exception::class); + $this->expectExceptionMessage("addDirectives accept only array of directives"); $directiveList = new SchemaDirectivesList(); $directiveList->addDirectives("foobar"); } -} \ No newline at end of file +} diff --git a/tests/Library/Type/UnionTypeTest.php b/tests/Library/Type/UnionTypeTest.php index 00dbb300..0ae775e3 100644 --- a/tests/Library/Type/UnionTypeTest.php +++ b/tests/Library/Type/UnionTypeTest.php @@ -15,7 +15,7 @@ use Youshido\Tests\DataProvider\TestObjectType; use Youshido\Tests\DataProvider\TestUnionType; -class UnionTypeTest extends \PHPUnit_Framework_TestCase +class UnionTypeTest extends \PHPUnit\Framework\TestCase { public function testInlineCreation() @@ -32,9 +32,7 @@ public function testInlineCreation() new TestObjectType(), $object ], - 'resolveType' => function ($type) { - return $type; - } + 'resolveType' => fn($type) => $type ]); $this->assertEquals('Car', $type->getName()); @@ -56,38 +54,30 @@ public function testObjectCreation() $this->assertEquals('test', $type->resolveType('test')); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testInvalidTypesWithScalar() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); $type = new UnionType([ 'name' => 'Car', 'description' => 'Union collect cars types', 'types' => [ 'test', new IntType() ], - 'resolveType' => function ($type) { - return $type; - } + 'resolveType' => fn($type) => $type ]); ConfigValidator::getInstance()->assertValidConfig($type->getConfig()); } - /** - * @expectedException Youshido\GraphQL\Exception\ConfigurationException - */ public function testInvalidTypes() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); $type = new UnionType([ 'name' => 'Car', 'description' => 'Union collect cars types', 'types' => [ new IntType() ], - 'resolveType' => function ($type) { - return $type; - } + 'resolveType' => fn($type) => $type ]); ConfigValidator::getInstance()->assertValidConfig($type->getConfig()); } diff --git a/tests/Library/Utilities/ErrorContainerTraitTest.php b/tests/Library/Utilities/ErrorContainerTraitTest.php index 519fee3d..8e83e08b 100644 --- a/tests/Library/Utilities/ErrorContainerTraitTest.php +++ b/tests/Library/Utilities/ErrorContainerTraitTest.php @@ -15,12 +15,12 @@ use Youshido\GraphQL\Validator\ErrorContainer\ErrorContainerInterface; use Youshido\GraphQL\Validator\ErrorContainer\ErrorContainerTrait; -class ErrorContainerTraitTest extends \PHPUnit_Framework_TestCase implements ErrorContainerInterface +class ErrorContainerTraitTest extends \PHPUnit\Framework\TestCase implements ErrorContainerInterface { use ErrorContainerTrait; - protected function setUp() + protected function setUp(): void { $this->clearErrors(); } @@ -117,6 +117,7 @@ public function testGetErrorsAsArrayExceptionWithEverything() class ExtendedException extends \Exception implements ExtendedExceptionInterface { + #[\Override] public function getExtensions() { return [ @@ -128,6 +129,7 @@ public function getExtensions() class SuperException extends \Exception implements LocationableExceptionInterface, ExtendedExceptionInterface { + #[\Override] public function getExtensions() { return [ @@ -136,6 +138,7 @@ public function getExtensions() ]; } + #[\Override] public function getLocation() { return new Location(6, 10); diff --git a/tests/Library/Utilities/TypeUtilitiesTest.php b/tests/Library/Utilities/TypeUtilitiesTest.php index f0c33f07..65cdf980 100644 --- a/tests/Library/Utilities/TypeUtilitiesTest.php +++ b/tests/Library/Utilities/TypeUtilitiesTest.php @@ -15,7 +15,7 @@ use Youshido\Tests\DataProvider\TestInterfaceType; use Youshido\Tests\DataProvider\TestObjectType; -class TypeUtilitiesTest extends \PHPUnit_Framework_TestCase +class TypeUtilitiesTest extends \PHPUnit\Framework\TestCase { public function testTypeService() @@ -32,11 +32,9 @@ public function testTypeService() $this->assertEquals(TypeService::resolveNamedType(123), $stringType); } - /** - * @expectedException \Exception - */ public function testNamedTypeResolverException() { + $this->expectException(\Exception::class); TypeService::resolveNamedType(['name' => 'test']); } diff --git a/tests/Library/Validator/RequestValidatorTest.php b/tests/Library/Validator/RequestValidatorTest.php index bff813e1..568d6f7b 100644 --- a/tests/Library/Validator/RequestValidatorTest.php +++ b/tests/Library/Validator/RequestValidatorTest.php @@ -19,17 +19,17 @@ use Youshido\GraphQL\Parser\Location; use Youshido\GraphQL\Validator\RequestValidator\RequestValidator; -class RequestValidatorTest extends \PHPUnit_Framework_TestCase +class RequestValidatorTest extends \PHPUnit\Framework\TestCase { /** - * @expectedException \Youshido\GraphQL\Exception\Parser\InvalidRequestException * @dataProvider invalidRequestProvider * * @param Request $request */ public function testInvalidRequests(Request $request) { + $this->expectException(\Youshido\GraphQL\Exception\Parser\InvalidRequestException::class); (new RequestValidator())->validate($request); } @@ -86,11 +86,12 @@ public function invalidRequestProvider() ]) ], [ - new Request([ + new Request(data: [ 'queries' => [ new Query('test', null, [ - new Argument('test', new VariableReference('test', null, new Location(1, 1)), new Location(1, 1)) + new Argument('test', value: new VariableReference('test', variable: null, location: new Location(1, 1)), + location: new Location(1, 1)) ], [ new Field('test', null, [], [], new Location(1, 1)) @@ -100,9 +101,9 @@ public function invalidRequestProvider() ) ], 'variableReferences' => [ - new VariableReference('test', null, new Location(1, 1)) + new VariableReference('test', variable: null, location: new Location(1, 1)) ] - ], ['test' => 1]) + ], variables: ['test' => 1]) ], [ new Request([ diff --git a/tests/Library/Validator/SchemaValidatorTest.php b/tests/Library/Validator/SchemaValidatorTest.php index 220c3e03..16be3e59 100644 --- a/tests/Library/Validator/SchemaValidatorTest.php +++ b/tests/Library/Validator/SchemaValidatorTest.php @@ -18,23 +18,19 @@ use Youshido\Tests\DataProvider\TestEmptySchema; use Youshido\Tests\DataProvider\TestInterfaceType; -class SchemaValidatorTest extends \PHPUnit_Framework_TestCase +class SchemaValidatorTest extends \PHPUnit\Framework\TestCase { - /** - * @expectedException \Youshido\GraphQL\Exception\ConfigurationException - */ public function testInvalidSchema() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); $validator = new SchemaValidator(); $validator->validate(new TestEmptySchema()); } - /** - * @expectedException \Youshido\GraphQL\Exception\ConfigurationException - * @expectedExceptionMessage Implementation of TestInterface is invalid for the field name - */ public function testInvalidInterfacesSimpleType() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); + $this->expectExceptionMessage('Implementation of TestInterface is invalid for the field name'); $schema = new Schema([ 'query' => new ObjectType([ 'name' => 'RootQuery', @@ -54,12 +50,10 @@ public function testInvalidInterfacesSimpleType() $validator->validate($schema); } - /** - * @expectedException \Youshido\GraphQL\Exception\ConfigurationException - * @expectedExceptionMessage Implementation of TestInterface is invalid for the field name - */ public function testInvalidInterfacesCompositeType() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); + $this->expectExceptionMessage('Implementation of TestInterface is invalid for the field name'); $schema = new Schema([ 'query' => new ObjectType([ 'name' => 'RootQuery', @@ -79,12 +73,10 @@ public function testInvalidInterfacesCompositeType() $validator->validate($schema); } - /** - * @expectedException \Youshido\GraphQL\Exception\ConfigurationException - * @expectedExceptionMessage Implementation of TestInterface is invalid for the field name - */ public function testInvalidInterfaces() { + $this->expectException(\Youshido\GraphQL\Exception\ConfigurationException::class); + $this->expectExceptionMessage('Implementation of TestInterface is invalid for the field name'); $schema = new Schema([ 'query' => new ObjectType([ 'name' => 'RootQuery', @@ -126,7 +118,7 @@ public function testValidSchema() try { $validator->validate($schema); $this->assertTrue(true); - } catch (\Exception $e) { + } catch (\Exception) { $this->assertTrue(false); } } diff --git a/tests/Library/Validator/TypeValidationRuleTest.php b/tests/Library/Validator/TypeValidationRuleTest.php index 57e368e1..0a7ebb09 100644 --- a/tests/Library/Validator/TypeValidationRuleTest.php +++ b/tests/Library/Validator/TypeValidationRuleTest.php @@ -19,7 +19,7 @@ use Youshido\Tests\DataProvider\TestInputObjectType; use Youshido\Tests\DataProvider\TestObjectType; -class TypeValidationRuleTest extends \PHPUnit_Framework_TestCase +class TypeValidationRuleTest extends \PHPUnit\Framework\TestCase { /** @@ -27,7 +27,7 @@ class TypeValidationRuleTest extends \PHPUnit_Framework_TestCase */ protected $rule; - protected function setUp() + protected function setUp(): void { $this->rule = new TypeValidationRule(ConfigValidator::getInstance()); } @@ -55,7 +55,7 @@ public function simpleRulesProvider() [TypeService::TYPE_ANY_OBJECT, new StringType()], [TypeService::TYPE_ANY_OBJECT, null, false], - [TypeService::TYPE_CALLABLE, function () { }], + [TypeService::TYPE_CALLABLE, function (): void { }], [TypeService::TYPE_CALLABLE, null, false], [TypeService::TYPE_BOOLEAN, true], diff --git a/tests/Parser/AstTest.php b/tests/Parser/AstTest.php index 49a8ae92..1f17d9ed 100644 --- a/tests/Parser/AstTest.php +++ b/tests/Parser/AstTest.php @@ -20,7 +20,7 @@ use Youshido\GraphQL\Parser\Ast\TypedFragmentReference; use Youshido\GraphQL\Parser\Location; -class AstTest extends \PHPUnit_Framework_TestCase +class AstTest extends \PHPUnit\Framework\TestCase { public function testArgument() @@ -194,11 +194,9 @@ public function testVariable() $this->assertEquals(new Literal('text', new Location(1,1)), $variable->getValue()); } - /** - * @expectedException \LogicException - */ public function testVariableLogicException() { + $this->expectException(\LogicException::class); $variable = new Variable('id', 'int', false, false, true, new Location(1,1)); $variable->getValue(); } diff --git a/tests/Parser/ParserTest.php b/tests/Parser/ParserTest.php index 0263d169..981c3912 100644 --- a/tests/Parser/ParserTest.php +++ b/tests/Parser/ParserTest.php @@ -33,7 +33,7 @@ public function getTokenForTesting() { } } -class ParserTest extends \PHPUnit_Framework_TestCase +class ParserTest extends \PHPUnit\Framework\TestCase { public function testEmptyParser() @@ -50,11 +50,9 @@ public function testEmptyParser() ], $parser->parse()); } - /** - * @expectedException Youshido\GraphQL\Exception\Parser\SyntaxErrorException - */ public function testInvalidSelection() { + $this->expectException(\Youshido\GraphQL\Exception\Parser\SyntaxErrorException::class); $parser = new Parser(); $data = $parser->parse(' { @@ -141,10 +139,10 @@ public function testEscapedStrings() * @param $query string * * @dataProvider wrongQueriesProvider - * @expectedException Youshido\GraphQL\Exception\Parser\SyntaxErrorException */ public function testWrongQueries($query) { + $this->expectException(\Youshido\GraphQL\Exception\Parser\SyntaxErrorException::class); $parser = new Parser(); $parser->parse($query); @@ -470,7 +468,7 @@ public function mutationProvider() 'queries' => [ new Query('query', null, [ - new Argument('teas', new VariableReference('variable', (new Variable('variable', 'Int', false, false, true, new Location(1, 8)))->setUsed(true), new Location(1, 39)), new Location(1, 33)), + new Argument('teas', new VariableReference('variable', location: new Location(1, 39), variable: (new Variable('variable', 'Int', false, false, true, new Location(1, 8)))->setUsed(true)), new Location(1, 33)), ], [ new Field('name', 'alias', [], [], new Location(1, 60)), diff --git a/tests/Parser/RequestTest.php b/tests/Parser/RequestTest.php index 49409484..6c042bd5 100644 --- a/tests/Parser/RequestTest.php +++ b/tests/Parser/RequestTest.php @@ -13,7 +13,7 @@ use Youshido\GraphQL\Parser\Ast\Fragment; use Youshido\GraphQL\Parser\Location; -class RequestTest extends \PHPUnit_Framework_TestCase +class RequestTest extends \PHPUnit\Framework\TestCase { public function testMethods() diff --git a/tests/Parser/VariableTest.php b/tests/Parser/VariableTest.php index 5ff0da38..d9441e1e 100644 --- a/tests/Parser/VariableTest.php +++ b/tests/Parser/VariableTest.php @@ -5,7 +5,7 @@ use Youshido\GraphQL\Parser\Ast\ArgumentValue\Variable; use Youshido\GraphQL\Parser\Location; -class VariableTest extends \PHPUnit_Framework_TestCase +class VariableTest extends \PHPUnit\Framework\TestCase { /** * Test if variable value equals expected value @@ -19,12 +19,10 @@ public function testGetValue($actual, $expected) $this->assertEquals($var->getValue(), $expected); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Value is not set for variable "foo" - */ public function testGetNullValueException() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Value is not set for variable "foo"'); $var = new Variable('foo', 'bar', false, false, true, new Location(1,1)); $var->getValue(); } diff --git a/tests/Performance/LoadTest.php b/tests/Performance/LoadTest.php index e110f93c..7f29a100 100644 --- a/tests/Performance/LoadTest.php +++ b/tests/Performance/LoadTest.php @@ -16,11 +16,12 @@ use Youshido\GraphQL\Type\Scalar\IdType; use Youshido\GraphQL\Type\Scalar\StringType; -class LoadTest extends \PHPUnit_Framework_TestCase +class LoadTest extends \PHPUnit\Framework\TestCase { public function testLoad10k() { + $this->expectNotToPerformAssertions(); $time = microtime(true); $postType = new ObjectType([ 'name' => 'Post', @@ -74,4 +75,4 @@ public function testLoad10k() printf("Test Time: %04f\n", microtime(true) - $time); } -} \ No newline at end of file +} diff --git a/tests/Performance/NPlusOneTest.php b/tests/Performance/NPlusOneTest.php index 5832d331..3de541cc 100644 --- a/tests/Performance/NPlusOneTest.php +++ b/tests/Performance/NPlusOneTest.php @@ -17,7 +17,7 @@ use Youshido\GraphQL\Type\Scalar\IntType; use Youshido\GraphQL\Type\Scalar\StringType; -class NPlusOneTest extends \PHPUnit_Framework_TestCase +class NPlusOneTest extends \PHPUnit\Framework\TestCase { private function getDataForPosts() @@ -67,9 +67,7 @@ public function testHigherResolver() 'fields' => [ 'posts' => [ 'type' => new ListType($postType), - 'resolve' => function ($source, $args, $info) { - return $this->getDataForPosts(); - } + 'resolve' => fn($source, $args, $info) => $this->getDataForPosts() ] ] ]) diff --git a/tests/Schema/DeferredTest.php b/tests/Schema/DeferredTest.php index a1eb764d..37b5b677 100644 --- a/tests/Schema/DeferredTest.php +++ b/tests/Schema/DeferredTest.php @@ -58,9 +58,7 @@ public function add(array $ids) $key = md5(serialize($ids)); $this->buffer[$key] = $ids; - return function () use ($key) { - return $this->fetch($key); - }; + return fn() => $this->fetch($key); } protected function fetch($resultId) @@ -98,6 +96,7 @@ public function __construct(DeferredQueryBuffer $database) } + #[\Override] public function build($config) { $config->addField( @@ -105,9 +104,7 @@ public function build($config) [ 'name' => 'name', 'type' => new StringType(), - 'resolve' => function ($value) { - return $value['name']; - }, + 'resolve' => fn($value) => $value['name'], ] ) ); @@ -117,11 +114,9 @@ public function build($config) [ 'name' => 'friends', 'type' => new ListType(new DeferredUserType($this->database)), - 'resolve' => function ($value) { - return new DeferredResolver( - $this->database->add($value['friends']) - ); - }, + 'resolve' => fn($value) => new DeferredResolver( + $this->database->add($value['friends']) + ), ] ) ); @@ -131,11 +126,9 @@ public function build($config) [ 'name' => 'foes', 'type' => new ListType(new DeferredUserType($this->database)), - 'resolve' => function ($value) { - return new DeferredResolver( - $this->database->add($value['foes']) - ); - }, + 'resolve' => fn($value) => new DeferredResolver( + $this->database->add($value['foes']) + ), ] ) ); @@ -151,9 +144,7 @@ public function __construct(DeferredQueryBuffer $buffer) [ 'name' => 'users', 'type' => new ListType(new DeferredUserType($buffer)), - 'resolve' => function ($value, $args) use ($buffer) { - return new DeferredResolver($buffer->add($args['ids'])); - }, + 'resolve' => fn($value, $args) => new DeferredResolver($buffer->add($args['ids'])), ] ); @@ -176,6 +167,7 @@ public function __construct(DeferredQueryBuffer $buffer) } + #[\Override] public function build(SchemaConfig $config) { } @@ -186,7 +178,7 @@ public function build(SchemaConfig $config) /** * Test the deferred resolving under different circumstances. */ -class DeferredTest extends \PHPUnit_Framework_TestCase +class DeferredTest extends \PHPUnit\Framework\TestCase { /** diff --git a/tests/Schema/FragmentsTest.php b/tests/Schema/FragmentsTest.php index 72bcbd7b..3e7ea791 100644 --- a/tests/Schema/FragmentsTest.php +++ b/tests/Schema/FragmentsTest.php @@ -19,6 +19,7 @@ class UserType extends AbstractObjectType { + #[\Override] public function build($config) { $config->addFields([ @@ -32,6 +33,7 @@ public function build($config) class CourtReservation extends AbstractObjectType { + #[\Override] public function build($config) { $config->addFields([ @@ -46,6 +48,7 @@ public function build($config) ]); } + #[\Override] public function getInterfaces() { return [new ReservationInterface()]; @@ -55,6 +58,7 @@ public function getInterfaces() class ClassReservation extends AbstractObjectType { + #[\Override] public function build($config) { $config->addFields([ @@ -63,6 +67,7 @@ public function build($config) ]); } + #[\Override] public function getInterfaces() { return [new ReservationInterface()]; @@ -71,11 +76,13 @@ public function getInterfaces() class ReservationInterface extends AbstractInterfaceType { + #[\Override] public function resolveType($object) { - return strpos($object['id'], 'cl') === false ? new CourtReservation() : new ClassReservation(); + return !str_contains((string) $object['id'], 'cl') ? new CourtReservation() : new ClassReservation(); } + #[\Override] public function build($config) { $config->addFields([ @@ -85,7 +92,7 @@ public function build($config) } -class FragmentsTest extends \PHPUnit_Framework_TestCase +class FragmentsTest extends \PHPUnit\Framework\TestCase { /** @@ -103,33 +110,31 @@ public function testVariables($query, $expected, $variables) 'fields' => [ 'user' => [ 'type' => new UserType(), - 'resolve' => function ($args) { - return [ - 'id' => 'user-id-1', - 'fullName' => 'Alex', - 'reservations' => [ - [ - 'id' => 'cl-1', - 'user' => [ - 'id' => 'user-id-2', - 'fullName' => 'User class1' - ], + 'resolve' => fn($args) => [ + 'id' => 'user-id-1', + 'fullName' => 'Alex', + 'reservations' => [ + [ + 'id' => 'cl-1', + 'user' => [ + 'id' => 'user-id-2', + 'fullName' => 'User class1' ], - [ - 'id' => 'court-1', - 'players' => [ - [ - 'id' => 'player-id-1', - 'user' => [ - 'id' => 'user-id-3', - 'fullName' => 'User court1' - ] + ], + [ + 'id' => 'court-1', + 'players' => [ + [ + 'id' => 'player-id-1', + 'user' => [ + 'id' => 'user-id-3', + 'fullName' => 'User court1' ] ] - ], - ] - ]; - }, + ] + ], + ] + ], ], ] ]) @@ -217,12 +222,10 @@ public function testSimpleFragment() 'fields' => [ 'user' => [ 'type' => new UserType(), - 'resolve' => function ($args) { - return [ - 'id' => 'user-id-1', - 'fullName' => 'Alex', - ]; - }, + 'resolve' => fn($args) => [ + 'id' => 'user-id-1', + 'fullName' => 'Alex', + ], 'args' => [ 'id' => new IntType(), ] diff --git a/tests/Schema/InputObjectDefaultValuesTest.php b/tests/Schema/InputObjectDefaultValuesTest.php index a13c60d3..274158ce 100644 --- a/tests/Schema/InputObjectDefaultValuesTest.php +++ b/tests/Schema/InputObjectDefaultValuesTest.php @@ -13,7 +13,7 @@ use Youshido\GraphQL\Type\Scalar\IntType; use Youshido\GraphQL\Type\Scalar\StringType; -class InputObjectDefaultValuesTest extends \PHPUnit_Framework_TestCase +class InputObjectDefaultValuesTest extends \PHPUnit\Framework\TestCase { public function testDefaultEnum() @@ -49,11 +49,9 @@ public function testDefaultEnum() ] ]) ], - 'resolve' => function ($source, $args) { - return sprintf('Result with level %s and status %s', - $args['statObject']['level'], $args['statObject']['status'] - ); - }, + 'resolve' => fn($source, $args) => sprintf('Result with level %s and status %s', + $args['statObject']['level'], $args['statObject']['status'] + ), ], 'enumObject' => [ 'type' => new ObjectType([ @@ -62,11 +60,9 @@ public function testDefaultEnum() 'status' => $enumType ] ]), - 'resolve' => function() { - return [ - 'status' => null - ]; - } + 'resolve' => fn() => [ + 'status' => null + ] ], ] diff --git a/tests/Schema/InputParseTest.php b/tests/Schema/InputParseTest.php index d3bc3b86..473ee0a2 100644 --- a/tests/Schema/InputParseTest.php +++ b/tests/Schema/InputParseTest.php @@ -9,7 +9,7 @@ use Youshido\GraphQL\Type\Scalar\DateTimeTzType; use Youshido\GraphQL\Type\Scalar\StringType; -class InputParseTest extends \PHPUnit_Framework_TestCase +class InputParseTest extends \PHPUnit\Framework\TestCase { /** @@ -30,12 +30,10 @@ public function testDateInput($query, $expected) 'from' => new DateTimeType('Y-m-d H:i:s'), 'fromtz' => new DateTimeTzType(), ], - 'resolve' => function ($source, $args) { - return sprintf('Result with %s date and %s tz', - empty($args['from']) ? 'default' : $args['from']->format('Y-m-d H:i:s'), - empty($args['fromtz']) ? 'default' : $args['fromtz']->format('r') - ); - }, + 'resolve' => fn($source, $args) => sprintf('Result with %s date and %s tz', + empty($args['from']) ? 'default' : $args['from']->format('Y-m-d H:i:s'), + empty($args['fromtz']) ? 'default' : $args['fromtz']->format('r') + ), ], ] ]) diff --git a/tests/Schema/IntrospectionTest.php b/tests/Schema/IntrospectionTest.php index 7bdafee0..29913885 100644 --- a/tests/Schema/IntrospectionTest.php +++ b/tests/Schema/IntrospectionTest.php @@ -25,7 +25,7 @@ use Youshido\Tests\DataProvider\TestEmptySchema; use Youshido\Tests\DataProvider\TestSchema; -class IntrospectionTest extends \PHPUnit_Framework_TestCase +class IntrospectionTest extends \PHPUnit\Framework\TestCase { private $introspectionQuery = << 'latest description', 'deprecationReason' => 'for test', 'isDeprecated' => true, - 'resolve' => function () { - return [ - 'id' => 1, - 'name' => 'Alex' - ]; - } + 'resolve' => fn() => [ + 'id' => 1, + 'name' => 'Alex' + ] ])); $processor = new Processor($schema); @@ -295,7 +293,7 @@ public function testCombinedFields() 'id' => ['type' => new IntType()], 'name' => ['type' => new IntType()], ], - 'resolveType' => function ($type) { + 'resolveType' => function ($type): void { } ]); @@ -323,7 +321,7 @@ public function testCombinedFields() $unionType = new UnionType([ 'name' => 'UnionType', 'types' => [$object1, $object2], - 'resolveType' => function () { + 'resolveType' => function (): void { } ]); @@ -334,12 +332,10 @@ public function testCombinedFields() 'args' => [ 'id' => ['type' => TypeMap::TYPE_INT] ], - 'resolve' => function () { - return [ - 'id' => 1, - 'name' => 'Alex' - ]; - } + 'resolve' => fn() => [ + 'id' => 1, + 'name' => 'Alex' + ] ])); $schema->addMutationField(new Field([ @@ -360,9 +356,7 @@ public function testCombinedFields() ] ]) ], - 'resolve' => function () { - return null; - } + 'resolve' => fn() => null ])); $processor = new Processor($schema); diff --git a/tests/Schema/NonNullableTest.php b/tests/Schema/NonNullableTest.php index 8069cc35..15aff390 100644 --- a/tests/Schema/NonNullableTest.php +++ b/tests/Schema/NonNullableTest.php @@ -16,22 +16,20 @@ use Youshido\GraphQL\Type\Scalar\IntType; use Youshido\GraphQL\Type\Scalar\StringType; -class uid +class uid implements \Stringable { - private $uid; - - public function __construct($uid) + public function __construct(private $uid) { - $this->uid = $uid; } - public function __toString() + #[\Override] + public function __toString(): string { - return $this->uid; + return (string) $this->uid; } } -class NonNullableTest extends \PHPUnit_Framework_TestCase +class NonNullableTest extends \PHPUnit\Framework\TestCase { /** @@ -48,15 +46,11 @@ public function testNullableResolving($query, $expected) 'fields' => [ 'nonNullScalar' => [ 'type' => new NonNullType(new IntType()), - 'resolve' => function () { - return null; - }, + 'resolve' => fn() => null, ], 'nonNullList' => [ 'type' => new NonNullType(new ListType(new IntType())), - 'resolve' => function () { - return null; - } + 'resolve' => fn() => null ], 'user' => [ 'type' => new NonNullType(new ObjectType([ @@ -66,36 +60,28 @@ public function testNullableResolving($query, $expected) 'name' => new StringType(), ] ])), - 'resolve' => function () { - return [ - 'id' => new uid('6cfb044c-9c0a-4ddd-9ef8-a0b940818db3'), - 'name' => 'Alex' - ]; - } + 'resolve' => fn() => [ + 'id' => new uid('6cfb044c-9c0a-4ddd-9ef8-a0b940818db3'), + 'name' => 'Alex' + ] ], 'nonNullListOfNpnNull' => [ 'type' => new NonNullType(new ListType(new NonNullType(new IntType()))), - 'resolve' => function () { - return [1, null]; - } + 'resolve' => fn() => [1, null] ], 'nonNullArgument' => [ 'args' => [ 'ids' => new NonNullType(new ListType(new IntType())) ], 'type' => new IntType(), - 'resolve' => function () { - return 1; - } + 'resolve' => fn() => 1 ], 'nonNullArgument2' => [ 'args' => [ 'ids' => new NonNullType(new ListType(new NonNullType(new IntType()))) ], 'type' => new IntType(), - 'resolve' => function () { - return 1; - } + 'resolve' => fn() => 1 ], ] ]) diff --git a/tests/Schema/ProcessorTest.php b/tests/Schema/ProcessorTest.php index 545416c7..6c6051e6 100644 --- a/tests/Schema/ProcessorTest.php +++ b/tests/Schema/ProcessorTest.php @@ -31,7 +31,7 @@ use Youshido\Tests\DataProvider\TestObjectType; use Youshido\Tests\DataProvider\TestSchema; -class ProcessorTest extends \PHPUnit_Framework_TestCase +class ProcessorTest extends \PHPUnit\Framework\TestCase { private $_counter = 0; @@ -110,9 +110,7 @@ public function testListNullResponse() 'fields' => [ 'list' => [ 'type' => new ListType(new StringType()), - 'resolve' => function () { - return null; - } + 'resolve' => fn() => null ] ] ]) @@ -130,9 +128,7 @@ public function testSubscriptionNullResponse() 'fields' => [ 'list' => [ 'type' => new ListType(new StringType()), - 'resolve' => function () { - return null; - } + 'resolve' => fn() => null ] ] ]) @@ -156,15 +152,11 @@ public function testSchemaOperations() 'args' => [ 'shorten' => new BooleanType() ], - 'resolve' => function ($value, $args) { - return empty($args['shorten']) ? $value['firstName'] : $value['firstName']; - } + 'resolve' => fn($value, $args) => empty($args['shorten']) ? $value['firstName'] : $value['firstName'] ], 'id_alias' => [ 'type' => new IdType(), - 'resolve' => function ($value) { - return $value['id']; - } + 'resolve' => fn($value) => $value['id'] ], 'lastName' => new StringType(), 'code' => new StringType(), @@ -189,21 +181,15 @@ public function testSchemaOperations() ], 'randomUser' => [ 'type' => new TestObjectType(), - 'resolve' => function () { - return ['invalidField' => 'John']; - } + 'resolve' => fn() => ['invalidField' => 'John'] ], 'invalidValueQuery' => [ 'type' => new TestObjectType(), - 'resolve' => function () { - return 'stringValue'; - } + 'resolve' => fn() => 'stringValue' ], 'labels' => [ 'type' => new ListType(new StringType()), - 'resolve' => function () { - return ['one', 'two']; - } + 'resolve' => fn() => ['one', 'two'] ] ], ]) @@ -238,9 +224,7 @@ public function testSchemaOperations() ->addField(new Field([ 'name' => 'increaseCounter', 'type' => new IntType(), - 'resolve' => function ($value, $args, ResolveInfo $info) { - return $this->_counter += $args['amount']; - }, + 'resolve' => fn($value, $args, ResolveInfo $info) => $this->_counter += $args['amount'], 'args' => [ 'amount' => [ 'type' => new IntType(), @@ -250,15 +234,11 @@ public function testSchemaOperations() ]))->addField(new Field([ 'name' => 'invalidResolveTypeMutation', 'type' => new NonNullType(new IntType()), - 'resolve' => function () { - return null; - } + 'resolve' => fn() => null ]))->addField(new Field([ 'name' => 'interfacedMutation', 'type' => new TestInterfaceType(), - 'resolve' => function () { - return ['name' => 'John']; - } + 'resolve' => fn() => ['name' => 'John'] ])); $processor->processPayload('mutation { increaseCounter }'); $this->assertEquals(['data' => ['increaseCounter' => 1]], $processor->getResponseData()); @@ -385,9 +365,7 @@ public function testEnumType() ])) ], 'type' => new StringType(), - 'resolve' => function ($value, $args) { - return $args['argument1']; - } + 'resolve' => fn($value, $args) => $args['argument1'] ] ] ]) @@ -438,45 +416,31 @@ public function testListEnumsSchemaOperations() 'fields' => [ 'listQuery' => [ 'type' => new ListType(new TestEnumType()), - 'resolve' => function () { - return 'invalid list'; - } + 'resolve' => fn() => 'invalid list' ], 'listEnumQuery' => [ 'type' => new ListType(new TestEnumType()), - 'resolve' => function () { - return ['invalid enum']; - } + 'resolve' => fn() => ['invalid enum'] ], 'invalidEnumQuery' => [ 'type' => new TestEnumType(), - 'resolve' => function () { - return 'invalid enum'; - } + 'resolve' => fn() => 'invalid enum' ], 'enumQuery' => [ 'type' => new TestEnumType(), - 'resolve' => function () { - return 1; - } + 'resolve' => fn() => 1 ], 'invalidNonNullQuery' => [ 'type' => new NonNullType(new IntType()), - 'resolve' => function () { - return null; - } + 'resolve' => fn() => null ], 'invalidNonNullInsideQuery' => [ 'type' => new NonNullType(new IntType()), - 'resolve' => function () { - return 'hello'; - } + 'resolve' => fn() => 'hello' ], 'objectQuery' => [ 'type' => new TestObjectType(), - 'resolve' => function () { - return ['name' => 'John']; - } + 'resolve' => fn() => ['name' => 'John'] ], 'deepObjectQuery' => [ 'type' => new ObjectType([ @@ -486,14 +450,12 @@ public function testListEnumsSchemaOperations() 'enum' => new TestEnumType(), ], ]), - 'resolve' => function () { - return [ - 'object' => [ - 'name' => 'John' - ], - 'enum' => 1 - ]; - }, + 'resolve' => fn() => [ + 'object' => [ + 'name' => 'John' + ], + 'enum' => 1 + ], ], ] ]) @@ -579,9 +541,7 @@ public function testTypedFragment() $invalidUnion = new UnionType([ 'name' => 'TestUnion', 'types' => [$object1, $object2], - 'resolveType' => function ($object) use ($object3) { - return $object3; - } + 'resolveType' => fn($object) => $object3 ]); $processor = new Processor(new Schema([ 'query' => new ObjectType([ @@ -607,9 +567,7 @@ public function testTypedFragment() ], 'invalidUnion' => [ 'type' => $invalidUnion, - 'resolve' => function () { - return ['name' => 'name resolved']; - } + 'resolve' => fn() => ['name' => 'name resolved'] ], ] ]) @@ -677,9 +635,7 @@ public function testContainer() 'fields' => [ 'currentUser' => [ 'type' => new StringType(), - 'resolve' => function ($source, $args, ResolveInfo $info) { - return $info->getContainer()->get('user')['name']; - } + 'resolve' => fn($source, $args, ResolveInfo $info) => $info->getContainer()->get('user')['name'] ] ] ]) @@ -710,24 +666,20 @@ public function testComplexityReducer() 'args' => [ 'shorten' => new BooleanType() ], - 'resolve' => function ($value, $args) { - return empty($args['shorten']) ? $value['firstName'] : $value['firstName']; - } + 'resolve' => fn($value, $args) => empty($args['shorten']) ? $value['firstName'] : $value['firstName'] ], 'lastName' => new StringType(), 'code' => new StringType(), 'likes' => [ 'type' => new IntType(), 'cost' => 10, - 'resolve' => function () { - return 42; - } + 'resolve' => fn() => 42 ] ] ] ), 'cost' => function ($args, $context, $childCost) { - $argsCost = isset($args['cost']) ? $args['cost'] : 1; + $argsCost = $args['cost'] ?? 1; return 1 + $argsCost * $childCost; }, @@ -774,7 +726,19 @@ public function testComplexityReducer() // don't let complexity reducer affect query errors $processor->processPayload('{ me { badfield } }'); - $this->assertArraySubset(['errors' => [['message' => 'Field "badfield" not found in type "User". Available fields are: "firstName", "lastName", "code", "likes"']]], $processor->getResponseData()); + + foreach ([ + 'errors' => [ + [ + 'message' => 'Field "badfield" not found in type "User". Available fields are: "firstName", "lastName", "code", "likes"', + 'locations' => [['line'=>1, 'column'=>8]] + ] + ] + ] as $key => $value) { + $this->assertArrayHasKey($key, $processor->getResponseData()); + $this->assertSame($value, $processor->getResponseData()[$key]); + } + $processor->getExecutionContext()->clearErrors(); foreach (range(1, 5) as $cost_multiplier) { diff --git a/tests/Schema/ResolveInfoTest.php b/tests/Schema/ResolveInfoTest.php index af903980..26651edb 100644 --- a/tests/Schema/ResolveInfoTest.php +++ b/tests/Schema/ResolveInfoTest.php @@ -17,7 +17,7 @@ use Youshido\GraphQL\Type\Scalar\IntType; use Youshido\Tests\DataProvider\TestSchema; -class ResolveInfoTest extends \PHPUnit_Framework_TestCase +class ResolveInfoTest extends \PHPUnit\Framework\TestCase { public function testMethods() { diff --git a/tests/Schema/SchemaTest.php b/tests/Schema/SchemaTest.php index 5c1c75fe..953fe020 100644 --- a/tests/Schema/SchemaTest.php +++ b/tests/Schema/SchemaTest.php @@ -19,7 +19,7 @@ use Youshido\Tests\DataProvider\TestObjectType; use Youshido\Tests\DataProvider\TestSchema; -class SchemaTest extends \PHPUnit_Framework_TestCase +class SchemaTest extends \PHPUnit\Framework\TestCase { public function testStandaloneEmptySchema() @@ -36,7 +36,7 @@ public function testStandaloneSchema() $this->assertEquals(1, count($schema->getMutationType()->getFields())); - $schema->addMutationField('changeUser', ['type' => new TestObjectType(), 'resolve' => function () { + $schema->addMutationField('changeUser', ['type' => new TestObjectType(), 'resolve' => function (): void { }]); $this->assertEquals(2, count($schema->getMutationType()->getFields())); @@ -68,9 +68,7 @@ public function testCustomTypes() 'fields' => [ 'name' => new StringType(), ], - 'resolveType' => function () use ($authorType) { - return $authorType; - } + 'resolveType' => fn() => $authorType ]); $authorType = new ObjectType([ @@ -87,11 +85,9 @@ public function testCustomTypes() 'fields' => [ 'user' => [ 'type' => $userInterface, - 'resolve' => function () { - return [ - 'name' => 'Alex' - ]; - } + 'resolve' => fn() => [ + 'name' => 'Alex' + ] ] ] ]) @@ -109,7 +105,11 @@ public function testCustomTypes() } }'); $data = $processor->getResponseData(); - $this->assertArraySubset([11 => ['name' => 'Author']], $data['data']['__schema']['types']); + + foreach ([11 => ['name' => 'Author']] as $key => $value) { + $this->assertArrayHasKey($key, $data['data']['__schema']['types']); + $this->assertSame($value, $data['data']['__schema']['types'][$key]); + } $processor->processPayload('{ user { name { } } }'); $result = $processor->getResponseData(); diff --git a/tests/Schema/VariablesTest.php b/tests/Schema/VariablesTest.php index c04ab334..7619f158 100644 --- a/tests/Schema/VariablesTest.php +++ b/tests/Schema/VariablesTest.php @@ -10,7 +10,7 @@ use Youshido\GraphQL\Type\Scalar\IdType; use Youshido\GraphQL\Type\Scalar\StringType; -class VariablesTest extends \PHPUnit_Framework_TestCase +class VariablesTest extends \PHPUnit\Framework\TestCase { public function testInvalidNullableList() { @@ -23,9 +23,7 @@ public function testInvalidNullableList() 'args' => [ 'ids' => new ListType(new NonNullType(new IdType())), ], - 'resolve' => function () { - return 'item'; - }, + 'resolve' => fn() => 'item', ], ], ]), @@ -100,9 +98,7 @@ public function testVariables($query, $expected, $variables) 'args' => [ 'sortOrder' => new StringType(), ], - 'resolve' => function ($args) { - return sprintf('Result with %s order', empty($args['sortOrder']) ? 'default' : $args['sortOrder']); - }, + 'resolve' => fn($args) => sprintf('Result with %s order', empty($args['sortOrder']) ? 'default' : $args['sortOrder']), ], ], ]), diff --git a/tests/StarWars/Schema/CharacterInterface.php b/tests/StarWars/Schema/CharacterInterface.php index 273aaf14..63826b20 100644 --- a/tests/StarWars/Schema/CharacterInterface.php +++ b/tests/StarWars/Schema/CharacterInterface.php @@ -16,6 +16,7 @@ class CharacterInterface extends AbstractInterfaceType { + #[\Override] public function build($config) { $config @@ -23,29 +24,30 @@ public function build($config) ->addField('name', new NonNullType(new StringType())) ->addField('friends', [ 'type' => new ListType(new CharacterInterface()), - 'resolve' => function ($value) { - return $value['friends']; - } + 'resolve' => fn($value) => $value['friends'] ]) ->addField('appearsIn', new ListType(new EpisodeEnum())); } + #[\Override] public function getDescription() { return 'A character in the Star Wars Trilogy'; } + #[\Override] public function getName() { return 'Character'; } + #[\Override] public function resolveType($object) { $humans = StarWarsData::humans(); $droids = StarWarsData::droids(); - $id = isset($object['id']) ? $object['id'] : $object; + $id = $object['id'] ?? $object; if (isset($humans[$id])) { return new HumanType(); diff --git a/tests/StarWars/Schema/DroidType.php b/tests/StarWars/Schema/DroidType.php index 7b4101df..e2dadf59 100644 --- a/tests/StarWars/Schema/DroidType.php +++ b/tests/StarWars/Schema/DroidType.php @@ -16,23 +16,24 @@ class DroidType extends HumanType /** * @return String type name */ + #[\Override] public function getName() { return 'Droid'; } + #[\Override] public function build($config) { parent::build($config); - $config->getField('friends')->getConfig()->set('resolve', function ($droid) { - return StarWarsData::getFriends($droid); - }); + $config->getField('friends')->getConfig()->set('resolve', fn($droid) => StarWarsData::getFriends($droid)); $config ->addField('primaryFunction', TypeMap::TYPE_STRING); } + #[\Override] public function getInterfaces() { return [new CharacterInterface()]; diff --git a/tests/StarWars/Schema/EpisodeEnum.php b/tests/StarWars/Schema/EpisodeEnum.php index 2c4c4436..fcdf28eb 100644 --- a/tests/StarWars/Schema/EpisodeEnum.php +++ b/tests/StarWars/Schema/EpisodeEnum.php @@ -13,6 +13,7 @@ class EpisodeEnum extends AbstractEnumType { + #[\Override] public function getValues() { return [ @@ -37,6 +38,7 @@ public function getValues() /** * @return String type name */ + #[\Override] public function getName() { return 'Episode'; diff --git a/tests/StarWars/Schema/HumanType.php b/tests/StarWars/Schema/HumanType.php index 8d02d346..e3adea61 100644 --- a/tests/StarWars/Schema/HumanType.php +++ b/tests/StarWars/Schema/HumanType.php @@ -18,6 +18,7 @@ class HumanType extends AbstractObjectType { + #[\Override] public function build($config) { $config @@ -25,14 +26,13 @@ public function build($config) ->addField('name', new NonNullType(new StringType())) ->addField('friends', [ 'type' => new ListType(new CharacterInterface()), - 'resolve' => function ($droid) { - return StarWarsData::getFriends($droid); - }, + 'resolve' => fn($droid) => StarWarsData::getFriends($droid), ]) ->addField('appearsIn', new ListType(new EpisodeEnum())) ->addField('homePlanet', TypeMap::TYPE_STRING); } + #[\Override] public function getInterfaces() { return [new CharacterInterface()]; diff --git a/tests/StarWars/Schema/StarWarsData.php b/tests/StarWars/Schema/StarWarsData.php index d2d28607..15b01b13 100644 --- a/tests/StarWars/Schema/StarWarsData.php +++ b/tests/StarWars/Schema/StarWarsData.php @@ -119,11 +119,8 @@ static function getCharacter($id) if (isset($humans[$id])) { return $humans[$id]; } - if (isset($droids[$id])) { - return $droids[$id]; - } - return null; + return $droids[$id] ?? null; } /** @@ -146,6 +143,6 @@ static function getHero($episode) */ static function getFriends($character) { - return array_map([__CLASS__, 'getCharacter'], $character['friends']); + return array_map(self::getCharacter(...), $character['friends']); } } diff --git a/tests/StarWars/Schema/StarWarsQueryType.php b/tests/StarWars/Schema/StarWarsQueryType.php index e54f072d..4f8c5589 100644 --- a/tests/StarWars/Schema/StarWarsQueryType.php +++ b/tests/StarWars/Schema/StarWarsQueryType.php @@ -19,11 +19,13 @@ class StarWarsQueryType extends AbstractObjectType /** * @return String type name */ + #[\Override] public function getName() { return 'Query'; } + #[\Override] public function build($config) { $config @@ -32,9 +34,7 @@ public function build($config) 'args' => [ 'episode' => ['type' => new EpisodeEnum()] ], - 'resolve' => function ($root, $args) { - return StarWarsData::getHero(isset($args['episode']) ? $args['episode'] : null); - }, + 'resolve' => fn($root, $args) => StarWarsData::getHero($args['episode'] ?? null), ]) ->addField(new Field([ 'name' => 'human', @@ -45,7 +45,7 @@ public function build($config) 'resolve' => function ($value = null, $args = []) { $humans = StarWarsData::humans(); - return isset($humans[$args['id']]) ? $humans[$args['id']] : null; + return $humans[$args['id']] ?? null; } ])) ->addField(new Field([ @@ -57,7 +57,7 @@ public function build($config) 'resolve' => function ($value = null, $args = []) { $droids = StarWarsData::droids(); - return isset($droids[$args['id']]) ? $droids[$args['id']] : null; + return $droids[$args['id']] ?? null; } ])); } diff --git a/tests/StarWars/Schema/StarWarsSchema.php b/tests/StarWars/Schema/StarWarsSchema.php index 1ed58262..b1a59b46 100644 --- a/tests/StarWars/Schema/StarWarsSchema.php +++ b/tests/StarWars/Schema/StarWarsSchema.php @@ -14,6 +14,7 @@ class StarWarsSchema extends AbstractSchema { + #[\Override] public function build(SchemaConfig $config) { $config->setQuery(new StarWarsQueryType()); diff --git a/tests/StarWars/StarWarsTest.php b/tests/StarWars/StarWarsTest.php index 7f69a4b2..a6a63b33 100644 --- a/tests/StarWars/StarWarsTest.php +++ b/tests/StarWars/StarWarsTest.php @@ -11,7 +11,7 @@ use Youshido\GraphQL\Execution\Processor; use Youshido\Tests\StarWars\Schema\StarWarsSchema; -class StarWarsTest extends \PHPUnit_Framework_TestCase +class StarWarsTest extends \PHPUnit\Framework\TestCase { /**