Skip to content

Commit 2b88987

Browse files
Add test for #5874
1 parent 819be58 commit 2b88987

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\MockObject;
11+
12+
class ExtendableClassCallingMethodInDestructor
13+
{
14+
public function __destruct()
15+
{
16+
$this->doSomethingElse();
17+
}
18+
19+
public function doSomething(): static
20+
{
21+
return $this;
22+
}
23+
24+
public function doSomethingElse(): void
25+
{
26+
}
27+
}

tests/unit/Framework/MockObject/Creation/MockBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
use PHPUnit\Framework\MockObject\Generator\NameAlreadyInUseException;
2828
use PHPUnit\Framework\TestCase;
2929
use PHPUnit\TestFixture\MockObject\AbstractClass;
30-
use PHPUnit\TestFixture\MockObject\ExtendableClassCallingMethodInConstructor;
3130
use PHPUnit\TestFixture\MockObject\ExtendableClass;
31+
use PHPUnit\TestFixture\MockObject\ExtendableClassCallingMethodInConstructor;
3232
use PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration;
3333
use PHPUnit\TestFixture\MockObject\TraitWithConcreteAndAbstractMethod;
3434

tests/unit/Framework/MockObject/TestDoubleTestCase.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations;
1414
use PHPUnit\Framework\Attributes\RequiresPhp;
1515
use PHPUnit\Framework\Attributes\TestDox;
16+
use PHPUnit\Framework\Attributes\Ticket;
1617
use PHPUnit\Framework\TestCase;
18+
use PHPUnit\TestFixture\MockObject\ExtendableClassCallingMethodInDestructor;
1719
use PHPUnit\TestFixture\MockObject\ExtendableClassWithCloneMethod;
1820
use PHPUnit\TestFixture\MockObject\ExtendableReadonlyClassWithCloneMethod;
1921
use PHPUnit\TestFixture\MockObject\InterfaceWithMethodThatExpectsObject;
@@ -293,6 +295,19 @@ public function testMethodNameCanOnlyBeConfiguredOnce(): void
293295
->willReturn(true);
294296
}
295297

298+
#[Ticket('https://github.com/sebastianbergmann/phpunit/issues/5874')]
299+
public function testDoubledMethodsCanBeCalledFromDestructorOnTestDoubleCreatedByTheReturnValueGenerator(): void
300+
{
301+
$this->markTestIncomplete('https://github.com/sebastianbergmann/phpunit/issues/5874');
302+
303+
$double = $this->createTestDouble(ExtendableClassCallingMethodInDestructor::class);
304+
305+
$this->assertInstanceOf(
306+
ExtendableClassCallingMethodInDestructor::class,
307+
$double->doSomething(),
308+
);
309+
}
310+
296311
/**
297312
* @psalm-template RealInstanceType of object
298313
*

0 commit comments

Comments
 (0)