From 44c75ebea4a3ff997e2e2bc10c2b1f77f6dff1c5 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 13 May 2024 10:55:25 +0900 Subject: [PATCH 1/2] Add red test for methods with mixed type argument A new file 'FakeMixedParamClass.php' has been created where a mixed parameter type in the 'returnSame' method has been introduced. In the 'CompilerTest.php', a unit test 'testMethodWithMixedArgument' has been added to test the method with mixed argument type. This test will only run on PHP 8.0 and above. --- tests/CompilerTest.php | 8 ++++++++ tests/Fake/FakeMixedParamClass.php | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/Fake/FakeMixedParamClass.php diff --git a/tests/CompilerTest.php b/tests/CompilerTest.php index 364b6a65..25e391e1 100644 --- a/tests/CompilerTest.php +++ b/tests/CompilerTest.php @@ -342,4 +342,12 @@ public function testNewInstanceWithAnonymousClass(): void $this->assertInstanceOf(FakeAnonymousClass::class, $mock); $this->assertInstanceOf(WeavedInterface::class, $mock); } + + /** @requires PHP 8.0 */ + public function testMethodWithMixedArgument(): void + { + $mock = $this->compiler->newInstance(FakeMixedParamClass::class, [], $this->bind); + $this->assertInstanceOf(FakeMixedParamClass::class, $mock); + $this->assertInstanceOf(WeavedInterface::class, $mock); + } } diff --git a/tests/Fake/FakeMixedParamClass.php b/tests/Fake/FakeMixedParamClass.php new file mode 100644 index 00000000..bafb9b9d --- /dev/null +++ b/tests/Fake/FakeMixedParamClass.php @@ -0,0 +1,12 @@ + Date: Mon, 13 May 2024 11:00:36 +0900 Subject: [PATCH 2/2] Update null checking condition in TypeString The null checking condition in the TypeString class has been updated. Previously, it would consider 'null' regardless of the actual type. Now, it will only consider 'null' for types other than 'mixed'. --- src/TypeString.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TypeString.php b/src/TypeString.php index 98290819..0bca78dd 100644 --- a/src/TypeString.php +++ b/src/TypeString.php @@ -39,7 +39,7 @@ public function __invoke(?ReflectionType $type): string if ($type instanceof ReflectionNamedType) { $typeStr = self::getFqnType($type); // Check for Nullable in single types - if ($type->allowsNull() && $type->getName() !== 'null') { + if ($typeStr !== 'mixed' && $type->allowsNull() && $type->getName() !== 'null') { $typeStr = $this->nullableStr . $typeStr; }