diff --git a/src/Framework/MockObject/MockBuilder.php b/src/Framework/MockObject/MockBuilder.php index 3d26278caae..b083ba202e7 100644 --- a/src/Framework/MockObject/MockBuilder.php +++ b/src/Framework/MockObject/MockBuilder.php @@ -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 ) diff --git a/tests/unit/Framework/MockObject/MockBuilderTest.php b/tests/unit/Framework/MockObject/MockBuilderTest.php index 158dd117492..8b97496d835 100644 --- a/tests/unit/Framework/MockObject/MockBuilderTest.php +++ b/tests/unit/Framework/MockObject/MockBuilderTest.php @@ -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']) @@ -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']) @@ -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']) @@ -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']) @@ -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']) @@ -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'])