Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match method name in MockBuilder exception message #3807

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Framework/MockObject/MockBuilder.php
Expand Up @@ -296,7 +296,7 @@ public function addMethods(array $methods): self
if ($reflector->hasMethod($method)) {
throw new RuntimeException(
\sprintf(
'Trying to set mock method "%s" with addMethod, but it exists in class "%s". Use onlyMethods() for methods that exist in the class.',
'Trying to set mock method "%s" with addMethods, but it exists in class "%s". Use onlyMethods() for methods that exist in the class.',
$method,
$this->type
)
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/Framework/MockObject/MockBuilderTest.php
Expand Up @@ -63,6 +63,7 @@ public function testSetMethodsAllowsNonExistentMethodNames(): void
public function testOnlyMethodsWithNonExistentMethodNames(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Trying to set mock method "mockableMethodWithCrazyName" with onlyMethods, but it does not exist in class "Mockable". Use addMethods() for methods that don\'t exist in the class.');

$this->getMockBuilder(Mockable::class)
->onlyMethods(['mockableMethodWithCrazyName'])
Expand Down Expand Up @@ -91,6 +92,7 @@ public function testOnlyMethodsWithEmptyArray(): void
public function testAddMethodsWithNonExistentMethodNames(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Trying to set mock method "mockableMethod" with addMethods, but it exists in class "Mockable". Use onlyMethods() for methods that exist in the class.');

$this->getMockBuilder(Mockable::class)
->addMethods(['mockableMethod'])
Expand Down Expand Up @@ -129,6 +131,7 @@ public function testEmptyMethodExceptionsToMockCanBeSpecified(): void
public function testNotAbleToUseAddMethodsAfterOnlyMethods(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Cannot use addMethods() on "Mockable" mock because mocked methods were already configured.');

$this->getMockBuilder(Mockable::class)
->onlyMethods(['mockableMethod'])
Expand All @@ -139,6 +142,7 @@ public function testNotAbleToUseAddMethodsAfterOnlyMethods(): void
public function testNotAbleToUseOnlyMethodsAfterAddMethods(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Cannot use onlyMethods() on "Mockable" mock because mocked methods were already configured.');

$this->getMockBuilder(Mockable::class)
->addMethods(['mockableMethodWithFakeMethod'])
Expand Down Expand Up @@ -169,6 +173,7 @@ public function testAbleToUseSetMethodsAfterAddMethods(): void
public function testNotAbleToUseAddMethodsAfterSetMethods(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Cannot use addMethods() on "Mockable" mock because mocked methods were already configured.');

$this->getMockBuilder(Mockable::class)
->setMethods(['mockableMethod'])
Expand All @@ -179,6 +184,7 @@ public function testNotAbleToUseAddMethodsAfterSetMethods(): void
public function testNotAbleToUseOnlyMethodsAfterSetMethods(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Cannot use onlyMethods() on "Mockable" mock because mocked methods were already configured.');

$this->getMockBuilder(Mockable::class)
->setMethods(['mockableMethodWithFakeMethod'])
Expand Down