Skip to content

Commit

Permalink
Add test for setConstructorArgs()
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 26, 2024
1 parent d3706a9 commit ba52e57
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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;

class ExtendableClassWithConstructorArguments
{
private string $value;

public function __construct(string $value)
{
$this->value = $value;
}

public function value(): string
{
return $this->value;
}
}
15 changes: 15 additions & 0 deletions tests/unit/Framework/MockObject/Creation/MockBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use PHPUnit\TestFixture\MockObject\AbstractClass;
use PHPUnit\TestFixture\MockObject\ExtendableClass;
use PHPUnit\TestFixture\MockObject\ExtendableClassCallingMethodInConstructor;
use PHPUnit\TestFixture\MockObject\ExtendableClassWithConstructorArguments;
use PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration;
use PHPUnit\TestFixture\MockObject\TraitWithConcreteAndAbstractMethod;

Expand Down Expand Up @@ -65,6 +66,20 @@ public function testCannotCreateMockObjectWithSpecifiedClassNameWhenClassWithTha
->getMock();
}

#[TestDox('setConstructorArgs() can be used to configure constructor arguments for a partially mocked class')]
public function testConstructorArgumentsCanBeConfiguredForPartiallyMockedClass(): void
{
$value = 'string';

$double = $this->getMockBuilder(ExtendableClassWithConstructorArguments::class)
->enableOriginalConstructor()
->setConstructorArgs([$value])
->onlyMethods([])
->getMock();

$this->assertSame($value, $double->value());
}

#[IgnorePhpunitDeprecations]
#[TestDox('addMethods() can be used to configure an additional method for the mock object class when the original class does not have a method of the same name')]
public function testCanCreateMockObjectForExtendableClassWhileAddingMethodsToIt(): void
Expand Down

0 comments on commit ba52e57

Please sign in to comment.