Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHP 8.4 support #1016

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
name: "PHPUnit"
uses: "doctrine/.github/.github/workflows/[email protected]"
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 }}"
1 change: 0 additions & 1 deletion src/Proxy/ProxyGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Common/Proxy/Php8UnionTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
15 changes: 10 additions & 5 deletions tests/Common/Proxy/ProxyGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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')
);

Expand Down Expand Up @@ -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'
);
Expand Down Expand Up @@ -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')
);
}

/**
Expand Down