Skip to content

Commit

Permalink
Merge branch '11.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Dec 11, 2024
2 parents b887eed + 04bd064 commit 6d5dbaf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 44 deletions.
47 changes: 47 additions & 0 deletions tests/unit/Framework/MockObject/MockObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace PHPUnit\Framework\MockObject;

use function call_user_func_array;
use Exception;
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Medium;
Expand All @@ -19,7 +20,9 @@
use PHPUnit\Framework\MockObject\Runtime\PropertyHook;
use PHPUnit\Framework\TestCase;
use PHPUnit\TestFixture\MockObject\AnInterface;
use PHPUnit\TestFixture\MockObject\ExtendableClassWithCloneMethod;
use PHPUnit\TestFixture\MockObject\ExtendableClassWithPropertyWithSetHook;
use PHPUnit\TestFixture\MockObject\ExtendableReadonlyClassWithCloneMethod;
use PHPUnit\TestFixture\MockObject\InterfaceWithImplicitProtocol;
use PHPUnit\TestFixture\MockObject\InterfaceWithPropertyWithSetHook;
use PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration;
Expand Down Expand Up @@ -473,6 +476,50 @@ public function testExpectationCanBeConfiguredForSetHookForPropertyOfExtendableC
$double->property = 'value';
}

#[TestDox('__toString() method returns empty string when return value generation is disabled and no return value is configured')]
public function testToStringMethodReturnsEmptyStringWhenReturnValueGenerationIsDisabledAndNoReturnValueIsConfigured(): void
{
$double = $this->getMockBuilder(InterfaceWithReturnTypeDeclaration::class)
->disableAutoReturnValueGeneration()
->getMock();

$this->assertSame('', $double->__toString());
}

public function testMethodDoesNotReturnValueWhenReturnValueGenerationIsDisabledAndNoReturnValueIsConfigured(): void
{
$double = $this->getMockBuilder(InterfaceWithReturnTypeDeclaration::class)
->disableAutoReturnValueGeneration()
->getMock();

$this->expectException(ReturnValueNotConfiguredException::class);
$this->expectExceptionMessage('No return value is configured for ' . InterfaceWithReturnTypeDeclaration::class . '::doSomething() and return value generation is disabled');

$double->doSomething();
}

#[TestDox('Original __clone() method can optionally be called when test double object is cloned')]
public function testOriginalCloneMethodCanOptionallyBeCalledWhenTestDoubleObjectIsCloned(): void
{
$double = $this->getMockBuilder(ExtendableClassWithCloneMethod::class)->enableOriginalClone()->getMock();

$this->expectException(Exception::class);
$this->expectExceptionMessage(ExtendableClassWithCloneMethod::class . '::__clone');

clone $double;
}

#[TestDox('Original __clone() method can optionally be called when test double object is cloned (readonly class)')]
public function testOriginalCloneMethodCanOptionallyBeCalledWhenTestDoubleObjectOfReadonlyClassIsCloned(): void
{
$double = $this->getMockBuilder(ExtendableReadonlyClassWithCloneMethod::class)->enableOriginalClone()->getMock();

$this->expectException(Exception::class);
$this->expectExceptionMessage(ExtendableReadonlyClassWithCloneMethod::class . '::__clone');

clone $double;
}

/**
* @param class-string $type
*/
Expand Down
44 changes: 0 additions & 44 deletions tests/unit/Framework/MockObject/TestDoubleTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,6 @@ final public function testMethodReturnsGeneratedValueWhenReturnValueGenerationIs
$this->assertFalse($double->doSomething());
}

#[TestDox('__toString() method returns empty string when return value generation is disabled and no return value is configured')]
final public function testToStringMethodReturnsEmptyStringWhenReturnValueGenerationIsDisabledAndNoReturnValueIsConfigured(): void
{
$double = $this->getMockBuilder(InterfaceWithReturnTypeDeclaration::class)
->disableAutoReturnValueGeneration()
->getMock();

$this->assertSame('', $double->__toString());
}

final public function testMethodDoesNotReturnValueWhenReturnValueGenerationIsDisabledAndNoReturnValueIsConfigured(): void
{
$double = $this->getMockBuilder(InterfaceWithReturnTypeDeclaration::class)
->disableAutoReturnValueGeneration()
->getMock();

$this->expectException(ReturnValueNotConfiguredException::class);
$this->expectExceptionMessage('No return value is configured for ' . InterfaceWithReturnTypeDeclaration::class . '::doSomething() and return value generation is disabled');

$double->doSomething();
}

final public function testMethodReturnsConfiguredValueWhenReturnValueIsConfigured(): void
{
$double = $this->createTestDouble(InterfaceWithReturnTypeDeclaration::class);
Expand Down Expand Up @@ -252,17 +230,6 @@ final public function testOriginalCloneMethodIsNotCalledByDefaultWhenTestDoubleO
$this->assertFalse($double->doSomething());
}

#[TestDox('Original __clone() method can optionally be called when test double object is cloned')]
final public function testOriginalCloneMethodCanOptionallyBeCalledWhenTestDoubleObjectIsCloned(): void
{
$double = $this->getMockBuilder(ExtendableClassWithCloneMethod::class)->enableOriginalClone()->getMock();

$this->expectException(Exception::class);
$this->expectExceptionMessage(ExtendableClassWithCloneMethod::class . '::__clone');

clone $double;
}

#[TestDox('Original __clone() method is not called by default when test double object is cloned (readonly class)')]
final public function testOriginalCloneMethodIsNotCalledByDefaultWhenTestDoubleObjectOfReadonlyClassIsCloned(): void
{
Expand All @@ -271,17 +238,6 @@ final public function testOriginalCloneMethodIsNotCalledByDefaultWhenTestDoubleO
$this->assertFalse($double->doSomething());
}

#[TestDox('Original __clone() method can optionally be called when test double object is cloned (readonly class)')]
final public function testOriginalCloneMethodCanOptionallyBeCalledWhenTestDoubleObjectOfReadonlyClassIsCloned(): void
{
$double = $this->getMockBuilder(ExtendableReadonlyClassWithCloneMethod::class)->enableOriginalClone()->getMock();

$this->expectException(Exception::class);
$this->expectExceptionMessage(ExtendableReadonlyClassWithCloneMethod::class . '::__clone');

clone $double;
}

public function testMethodNameCanOnlyBeConfiguredOnce(): void
{
$double = $this->createTestDouble(InterfaceWithReturnTypeDeclaration::class);
Expand Down

0 comments on commit 6d5dbaf

Please sign in to comment.