diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index 228ca70fd1..4c56a8b465 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -19,6 +19,7 @@ jobs: - "7.2" - "7.3" - "7.4" + - "8.0" dependencies: - "highest" @@ -40,6 +41,9 @@ jobs: key: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.lock') }}" restore-keys: "php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-" + - name: "Install composer v1" + run: "composer selfupdate --1" + - name: "Install dependencies with composer" run: "composer install --no-interaction" diff --git a/composer.json b/composer.json index 92ccd88b49..e600e15c18 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "psr/http-factory": "^1" }, "require-dev": { - "phpunit/phpunit": "^8.2.4", + "phpunit/phpunit": "^8.2.4||^9.4", "php-coveralls/php-coveralls": "^2.1", "mouf/picotainer": "^1.1", "phpstan/phpstan": "^0.12.25", diff --git a/src/Mappers/RecursiveTypeMapper.php b/src/Mappers/RecursiveTypeMapper.php index a53d4d242e..1b5d6715cf 100644 --- a/src/Mappers/RecursiveTypeMapper.php +++ b/src/Mappers/RecursiveTypeMapper.php @@ -20,6 +20,7 @@ use TheCodingMachine\GraphQLite\Types\MutableObjectType; use TheCodingMachine\GraphQLite\Types\ObjectFromInterfaceType; use TheCodingMachine\GraphQLite\Types\ResolvableMutableInputInterface; +use TypeError; use Webmozart\Assert\Assert; use function array_flip; use function array_reverse; @@ -175,7 +176,11 @@ public function findClosestMatchingParent(string $className): ?string if ($this->typeMapper->canMapClassToType($className)) { return $className; } - $className = get_parent_class($className); + try { + $className = get_parent_class($className); + } catch (TypeError $exception) { + return null; + } } while ($className); return null; diff --git a/tests/Mappers/CannotMapTypeTraitTest.php b/tests/Mappers/CannotMapTypeTraitTest.php index 2a1641b175..3eda033f20 100644 --- a/tests/Mappers/CannotMapTypeTraitTest.php +++ b/tests/Mappers/CannotMapTypeTraitTest.php @@ -9,8 +9,10 @@ class CannotMapTypeTraitTest extends AbstractQueryProviderTest { - - public function testAddParamInfo() + /** + * @requires PHP <= 7.4 + */ + public function testAddParamInfoInfphp80() { $e = CannotMapTypeException::createForType('Foo'); $e->addParamInfo((new ReflectionClass('DateTime'))->getMethod('__construct')->getParameters()[0]); @@ -19,6 +21,18 @@ public function testAddParamInfo() $this->assertSame('For parameter $time, in DateTime::__construct, cannot map class "Foo" to a known GraphQL type. Check your TypeMapper configuration.', $e->getMessage()); } + /** + * @requires PHP >= 8.0 + */ + public function testAddParamInfoSupphp74() + { + $e = CannotMapTypeException::createForType('Foo'); + $e->addParamInfo((new ReflectionClass('DateTime'))->getMethod('__construct')->getParameters()[0]); + $e->addParamInfo((new ReflectionClass('DateTime'))->getMethod('__construct')->getParameters()[0]); + + $this->assertSame('For parameter $datetime, in DateTime::__construct, cannot map class "Foo" to a known GraphQL type. Check your TypeMapper configuration.', $e->getMessage()); + } + public function testAddSourceFieldInfo() { $class = new ReflectionClass(TestTypeId::class);