Skip to content

Commit

Permalink
Add test for #5593
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Dec 1, 2023
1 parent 23a9e6a commit 41861f1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/_files/mock-object/AnInterfaceForIssue5593.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* 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;
}
15 changes: 15 additions & 0 deletions tests/_files/mock-object/AnotherInterfaceForIssue5593.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* 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;
}
19 changes: 19 additions & 0 deletions tests/unit/Framework/MockObject/ReturnValueGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 41861f1

Please sign in to comment.