From 41861f1cad99b895af9329c39794478aeba08763 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Fri, 1 Dec 2023 14:53:47 +0100 Subject: [PATCH] Add test for #5593 --- .../mock-object/AnInterfaceForIssue5593.php | 15 +++++++++++++++ .../AnotherInterfaceForIssue5593.php | 15 +++++++++++++++ .../MockObject/ReturnValueGeneratorTest.php | 19 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 tests/_files/mock-object/AnInterfaceForIssue5593.php create mode 100644 tests/_files/mock-object/AnotherInterfaceForIssue5593.php diff --git a/tests/_files/mock-object/AnInterfaceForIssue5593.php b/tests/_files/mock-object/AnInterfaceForIssue5593.php new file mode 100644 index 00000000000..e084154730c --- /dev/null +++ b/tests/_files/mock-object/AnInterfaceForIssue5593.php @@ -0,0 +1,15 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TestFixture\MockObject; + +interface AnInterfaceForIssue5593 +{ + public function doSomething(): AnotherInterfaceForIssue5593; +} diff --git a/tests/_files/mock-object/AnotherInterfaceForIssue5593.php b/tests/_files/mock-object/AnotherInterfaceForIssue5593.php new file mode 100644 index 00000000000..81f695a029f --- /dev/null +++ b/tests/_files/mock-object/AnotherInterfaceForIssue5593.php @@ -0,0 +1,15 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TestFixture\MockObject; + +interface AnotherInterfaceForIssue5593 +{ + public function doSomethingElse(): static; +} diff --git a/tests/unit/Framework/MockObject/ReturnValueGeneratorTest.php b/tests/unit/Framework/MockObject/ReturnValueGeneratorTest.php index 175c360fd44..86d43c19cec 100644 --- a/tests/unit/Framework/MockObject/ReturnValueGeneratorTest.php +++ b/tests/unit/Framework/MockObject/ReturnValueGeneratorTest.php @@ -18,9 +18,12 @@ use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\Small; use PHPUnit\Framework\Attributes\TestDox; +use PHPUnit\Framework\Attributes\Ticket; use PHPUnit\Framework\TestCase; use PHPUnit\TestFixture\MockObject\AnInterface; +use PHPUnit\TestFixture\MockObject\AnInterfaceForIssue5593; use PHPUnit\TestFixture\MockObject\AnotherInterface; +use PHPUnit\TestFixture\MockObject\AnotherInterfaceForIssue5593; use PHPUnit\TestFixture\MockObject\YetAnotherInterface; use stdClass; @@ -162,6 +165,22 @@ public function test_Generates_new_instance_of_test_stub_for_static(): void $this->assertInstanceOf($stubClassName, $this->generate('static', $stubClassName)); } + #[Ticket('https://github.com/sebastianbergmann/phpunit/issues/5593')] + public function test_Generates_new_instance_of_test_stub_for_static_when_used_recursively(): void + { + $a = $this->createStub(AnInterfaceForIssue5593::class); + + $this->assertInstanceOf(AnInterfaceForIssue5593::class, $a); + + $b = $a->doSomething(); + + $this->assertInstanceOf(AnotherInterfaceForIssue5593::class, $b); + + $c = $b->doSomethingElse(); + + $this->assertInstanceOf(AnotherInterfaceForIssue5593::class, $c); + } + #[DataProvider('unionProvider')] #[TestDox('Generates $expected for $union')] public function test_Generates_return_value_for_union(mixed $expected, string $union): void