Skip to content

Commit

Permalink
Closes #5321
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 25, 2024
1 parent 024c278 commit 8d3aaa8
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 105 deletions.

This file was deleted.

49 changes: 0 additions & 49 deletions src/Framework/MockObject/MockBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,55 +158,6 @@ public function onlyMethods(array $methods): self
return $this;
}

/**
* Specifies methods that don't exist in the class which you want to mock.
*
* @psalm-param list<non-empty-string> $methods
*
* @throws CannotUseAddMethodsException
* @throws ReflectionException
* @throws RuntimeException
*
* @return $this
*
* @deprecated https://github.com/sebastianbergmann/phpunit/issues/5320
*/
public function addMethods(array $methods): self
{
EventFacade::emitter()->testTriggeredPhpunitDeprecation(
$this->testCase->valueObjectForEvents(),
'MockBuilder::addMethods() is deprecated and will be removed in PHPUnit 12 without replacement.',
);

if (empty($methods)) {
$this->emptyMethodsArray = true;

return $this;
}

try {
$reflector = new ReflectionClass($this->type);
// @codeCoverageIgnoreStart
} catch (\ReflectionException $e) {
throw new ReflectionException(
$e->getMessage(),
$e->getCode(),
$e,
);
// @codeCoverageIgnoreEnd
}

foreach ($methods as $method) {
if ($reflector->hasMethod($method)) {
throw new CannotUseAddMethodsException($this->type, $method);
}
}

$this->methods = array_merge($this->methods, $methods);

return $this;
}

/**
* Specifies the arguments for the constructor.
*
Expand Down
27 changes: 0 additions & 27 deletions tests/unit/Framework/MockObject/Creation/MockBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@
use function mt_rand;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations;
use PHPUnit\Framework\Attributes\Medium;
use PHPUnit\Framework\TestCase;
use PHPUnit\TestFixture\MockObject\ExtendableClass;
use PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration;

#[CoversClass(MockBuilder::class)]
#[CoversClass(CannotUseAddMethodsException::class)]
#[Group('test-doubles')]
#[Group('test-doubles/creation')]
#[Group('test-doubles/mock-object')]
Expand All @@ -37,28 +34,4 @@ public function testCanCreateMockObjectWithSpecifiedClassName(): void

$this->assertSame($className, $double::class);
}

#[IgnorePhpunitDeprecations]
public function testCanCreateMockObjectForExtendableClassWhileAddingMethodsToIt(): void
{
$double = $this->getMockBuilder(ExtendableClass::class)
->addMethods(['additionalMethod'])
->getMock();

$value = 'value';

$double->method('additionalMethod')->willReturn($value);

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

#[IgnorePhpunitDeprecations]
public function testCannotCreateMockObjectForExtendableClassAddingMethodsToItThatItAlreadyHas(): void
{
$this->expectException(CannotUseAddMethodsException::class);

$this->getMockBuilder(ExtendableClass::class)
->addMethods(['doSomething'])
->getMock();
}
}

0 comments on commit 8d3aaa8

Please sign in to comment.