Skip to content

Commit

Permalink
Add test for #5874
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 19, 2024
1 parent 819be58 commit 2b88987
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TestFixture\MockObject;

class ExtendableClassCallingMethodInDestructor
{
public function __destruct()
{
$this->doSomethingElse();
}

public function doSomething(): static
{
return $this;
}

public function doSomethingElse(): void
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
use PHPUnit\Framework\MockObject\Generator\NameAlreadyInUseException;
use PHPUnit\Framework\TestCase;
use PHPUnit\TestFixture\MockObject\AbstractClass;
use PHPUnit\TestFixture\MockObject\ExtendableClassCallingMethodInConstructor;
use PHPUnit\TestFixture\MockObject\ExtendableClass;
use PHPUnit\TestFixture\MockObject\ExtendableClassCallingMethodInConstructor;
use PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration;
use PHPUnit\TestFixture\MockObject\TraitWithConcreteAndAbstractMethod;

Expand Down
15 changes: 15 additions & 0 deletions tests/unit/Framework/MockObject/TestDoubleTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations;
use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\Attributes\TestDox;
use PHPUnit\Framework\Attributes\Ticket;
use PHPUnit\Framework\TestCase;
use PHPUnit\TestFixture\MockObject\ExtendableClassCallingMethodInDestructor;
use PHPUnit\TestFixture\MockObject\ExtendableClassWithCloneMethod;
use PHPUnit\TestFixture\MockObject\ExtendableReadonlyClassWithCloneMethod;
use PHPUnit\TestFixture\MockObject\InterfaceWithMethodThatExpectsObject;
Expand Down Expand Up @@ -293,6 +295,19 @@ public function testMethodNameCanOnlyBeConfiguredOnce(): void
->willReturn(true);
}

#[Ticket('https://github.com/sebastianbergmann/phpunit/issues/5874')]
public function testDoubledMethodsCanBeCalledFromDestructorOnTestDoubleCreatedByTheReturnValueGenerator(): void
{
$this->markTestIncomplete('https://github.com/sebastianbergmann/phpunit/issues/5874');

$double = $this->createTestDouble(ExtendableClassCallingMethodInDestructor::class);

$this->assertInstanceOf(
ExtendableClassCallingMethodInDestructor::class,
$double->doSomething(),
);
}

/**
* @psalm-template RealInstanceType of object
*
Expand Down

0 comments on commit 2b88987

Please sign in to comment.