From 3fd2cf11609afc1867e9bd6c809032b77a812f69 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Fri, 5 Jun 2020 14:29:24 +0200 Subject: [PATCH] Use correct exception type --- src/Framework/MockObject/InvocationHandler.php | 13 +++++++------ .../Framework/MockObject/InvocationHandlerTest.php | 3 +-- tests/unit/Framework/MockObject/MockObjectTest.php | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Framework/MockObject/InvocationHandler.php b/src/Framework/MockObject/InvocationHandler.php index ffad6c0c881..165ee147640 100644 --- a/src/Framework/MockObject/InvocationHandler.php +++ b/src/Framework/MockObject/InvocationHandler.php @@ -9,7 +9,6 @@ */ namespace PHPUnit\Framework\MockObject; -use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\Builder\InvocationMocker; use PHPUnit\Framework\MockObject\Rule\InvocationOrder; @@ -107,8 +106,8 @@ public function expects(InvocationOrder $rule): InvocationMocker } /** - * @throws Exception - * @throws \Throwable + * @throws RuntimeException + * @throws \Exception */ public function invoke(Invocation $invocation) { @@ -121,7 +120,7 @@ public function invoke(Invocation $invocation) } if (!$this->returnValueGeneration) { - $exception = new ExpectationFailedException( + $exception = new RuntimeException( \sprintf( 'Return value inference disabled and no expectation set up for %s::%s()', $invocation->getClassName(), @@ -153,7 +152,6 @@ public function matches(Invocation $invocation): bool } /** - * @throws ExpectationFailedException * @throws \Throwable */ public function verify(): void @@ -167,6 +165,9 @@ public function verify(): void } } + /** + * @throws RuntimeException + */ private function findMatcher(Invocation $invocation): ?Matcher { $result = []; @@ -178,7 +179,7 @@ private function findMatcher(Invocation $invocation): ?Matcher } if (\count($result) > 1) { - throw new ExpectationFailedException( + throw new RuntimeException( \sprintf( 'Non unique mocked method invocation: %s::%s', $invocation->getClassName(), diff --git a/tests/unit/Framework/MockObject/InvocationHandlerTest.php b/tests/unit/Framework/MockObject/InvocationHandlerTest.php index 4842f541b5a..9b8a36374e9 100644 --- a/tests/unit/Framework/MockObject/InvocationHandlerTest.php +++ b/tests/unit/Framework/MockObject/InvocationHandlerTest.php @@ -9,7 +9,6 @@ */ namespace PHPUnit\Framework\MockObject; -use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; class InvocationHandlerTest extends TestCase @@ -53,7 +52,7 @@ public function testNonUniqueMatchThrowsException(): void ->with('bar') ->willReturn('result'); - $this->expectException(ExpectationFailedException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Non unique mocked method invocation: stdClass::foo'); $mock->foo(); diff --git a/tests/unit/Framework/MockObject/MockObjectTest.php b/tests/unit/Framework/MockObject/MockObjectTest.php index 48ed800158e..ec347293e16 100644 --- a/tests/unit/Framework/MockObject/MockObjectTest.php +++ b/tests/unit/Framework/MockObject/MockObjectTest.php @@ -1059,7 +1059,7 @@ public function testDisableAutomaticReturnValueGeneration(): void ->disableAutoReturnValueGeneration() ->getMock(); - $this->expectException(ExpectationFailedException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage( 'Return value inference disabled and no expectation set up for SomeClass::doSomethingElse()' ); @@ -1079,7 +1079,7 @@ public function testDisableAutomaticReturnValueGenerationWithToString(): void try { $mock->__phpunit_verify(); $this->fail('Exception expected'); - } catch (ExpectationFailedException $e) { + } catch (RuntimeException $e) { $this->assertSame( 'Return value inference disabled and no expectation set up for StringableClass::__toString()', $e->getMessage()