From e53168ec555660594682d4955b224c6bded1ef3e Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Tue, 8 Oct 2024 17:12:42 +0200 Subject: [PATCH 1/4] Add PHP 8.4 to jobs. --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 57ea4a4f4..ca371fd54 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -17,6 +17,6 @@ jobs: name: "PHPUnit" uses: "doctrine/.github/.github/workflows/continuous-integration.yml@5.1.0" with: - php-versions: '["7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3"]' + php-versions: '["7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4"]' secrets: CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}" From ba6c17cf193cf1bb0e1e5ed25435681308884a05 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Tue, 8 Oct 2024 17:31:52 +0200 Subject: [PATCH 2/4] Fix deprecation about implicit null when generating proxies. --- src/Proxy/ProxyGenerator.php | 1 - tests/Common/Proxy/Php8UnionTypes.php | 6 ++++++ tests/Common/Proxy/ProxyGeneratorTest.php | 11 ++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Proxy/ProxyGenerator.php b/src/Proxy/ProxyGenerator.php index ec6fb1004..9f35fd5a2 100644 --- a/src/Proxy/ProxyGenerator.php +++ b/src/Proxy/ProxyGenerator.php @@ -1282,7 +1282,6 @@ function (ReflectionType $intersectedType) use ($method, $parameter) { if ( $type->allowsNull() && ! in_array($name, ['mixed', 'null'], true) - && ($parameter === null || ! $parameter->isDefaultValueAvailable() || $parameter->getDefaultValue() !== null) ) { $name = '?' . $name; } diff --git a/tests/Common/Proxy/Php8UnionTypes.php b/tests/Common/Proxy/Php8UnionTypes.php index ab5c391c8..c95412746 100644 --- a/tests/Common/Proxy/Php8UnionTypes.php +++ b/tests/Common/Proxy/Php8UnionTypes.php @@ -12,10 +12,16 @@ class Php8UnionTypes public function setValue(stdClass|array $value) : bool|float { + return true; } public function setNullableValue(stdClass|array|null $value) : bool|float|null { + return true; } + public function setNullableValueDefaultNull(stdClass|array|null $value = null) : bool|float|null + { + return true; + } } diff --git a/tests/Common/Proxy/ProxyGeneratorTest.php b/tests/Common/Proxy/ProxyGeneratorTest.php index 59c1eb3ef..59b796eda 100644 --- a/tests/Common/Proxy/ProxyGeneratorTest.php +++ b/tests/Common/Proxy/ProxyGeneratorTest.php @@ -180,7 +180,7 @@ public function testClassWithScalarTypeHintsOnProxiedMethods() self::assertEquals(1, substr_count($classCode, 'function combinationOfTypeHintsAndNormal(\stdClass $a, \Countable $b, $c, int $d)')); self::assertEquals(1, substr_count($classCode, 'function typeHintsWithVariadic(int ...$foo)')); self::assertEquals(1, substr_count($classCode, 'function withDefaultValue(int $foo = 123)')); - self::assertEquals(1, substr_count($classCode, 'function withDefaultValueNull(int $foo = NULL)')); + self::assertEquals(1, substr_count($classCode, 'function withDefaultValueNull(?int $foo = NULL)')); } public function testClassWithReturnTypesOnProxiedMethods() @@ -220,8 +220,8 @@ public function testClassWithNullableTypeHintsOnProxiedMethods() self::assertEquals(1, substr_count($classCode, 'function nullableTypeHintObject(?\stdClass $param)')); self::assertEquals(1, substr_count($classCode, 'function nullableTypeHintSelf(?\\' . $className . ' $param)')); self::assertEquals(1, substr_count($classCode, 'function nullableTypeHintWithDefault(?int $param = 123)')); - self::assertEquals(1, substr_count($classCode, 'function nullableTypeHintWithDefaultNull(int $param = NULL)')); - self::assertEquals(1, substr_count($classCode, 'function notNullableTypeHintWithDefaultNull(int $param = NULL)')); + self::assertEquals(1, substr_count($classCode, 'function nullableTypeHintWithDefaultNull(?int $param = NULL)')); + self::assertEquals(1, substr_count($classCode, 'function notNullableTypeHintWithDefaultNull(?int $param = NULL)')); } public function testClassWithNullableReturnTypesOnProxiedMethods() @@ -460,6 +460,11 @@ public function testPhp8UnionTypes() 'setNullableValue(\stdClass|array|null $value): float|bool|null', file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp8UnionTypes.php') ); + + self::assertStringContainsString( + 'setNullableValueDefaultNull(\stdClass|array|null $value = NULL): float|bool|null', + file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp8UnionTypes.php') + ); } /** From 3611650873d901b23cad5677046a2dd445b0110b Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Tue, 8 Oct 2024 17:35:10 +0200 Subject: [PATCH 3/4] PHP 7.* related changes --- tests/Common/Proxy/ProxyGeneratorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Common/Proxy/ProxyGeneratorTest.php b/tests/Common/Proxy/ProxyGeneratorTest.php index 59b796eda..6187c9e0d 100644 --- a/tests/Common/Proxy/ProxyGeneratorTest.php +++ b/tests/Common/Proxy/ProxyGeneratorTest.php @@ -259,7 +259,7 @@ public function testClassWithNullableOptionalNonLastParameterOnProxiedMethods() } self::assertStringContainsString( - 'public function midSignatureNullableParameter(\stdClass $param = NULL, $secondParam)', + 'public function midSignatureNullableParameter(?\stdClass $param = NULL, $secondParam)', file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyNullableNonOptionalHintClass.php') ); From b3974272b7e9fe96ef266d6a206b8a401754b20a Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Tue, 8 Oct 2024 17:38:51 +0200 Subject: [PATCH 4/4] PHP 7.* related changes --- tests/Common/Proxy/ProxyGeneratorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Common/Proxy/ProxyGeneratorTest.php b/tests/Common/Proxy/ProxyGeneratorTest.php index 6187c9e0d..168b3254b 100644 --- a/tests/Common/Proxy/ProxyGeneratorTest.php +++ b/tests/Common/Proxy/ProxyGeneratorTest.php @@ -287,7 +287,7 @@ public function testClassWithPhp71NullableOptionalNonLastParameterOnProxiedMetho } self::assertStringContainsString( - 'public function midSignatureNullableParameter(string $param = NULL, $secondParam)', + 'public function midSignatureNullableParameter(?string $param = NULL, $secondParam)', file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp71NullableDefaultedNonOptionalHintClass.php'), 'Signature allows nullable type, although explicit "?" marker isn\'t used in the proxy' );