Skip to content

Commit

Permalink
Use correct exception type
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 5, 2020
1 parent 7c8fecd commit 3fd2cf1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/Framework/MockObject/InvocationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
namespace PHPUnit\Framework\MockObject;

use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;

Expand Down Expand Up @@ -107,8 +106,8 @@ public function expects(InvocationOrder $rule): InvocationMocker
}

/**
* @throws Exception
* @throws \Throwable
* @throws RuntimeException
* @throws \Exception
*/
public function invoke(Invocation $invocation)
{
Expand All @@ -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(),
Expand Down Expand Up @@ -153,7 +152,6 @@ public function matches(Invocation $invocation): bool
}

/**
* @throws ExpectationFailedException
* @throws \Throwable
*/
public function verify(): void
Expand All @@ -167,6 +165,9 @@ public function verify(): void
}
}

/**
* @throws RuntimeException
*/
private function findMatcher(Invocation $invocation): ?Matcher
{
$result = [];
Expand All @@ -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(),
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/Framework/MockObject/InvocationHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
namespace PHPUnit\Framework\MockObject;

use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\TestCase;

class InvocationHandlerTest extends TestCase
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Framework/MockObject/MockObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()'
);
Expand All @@ -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()
Expand Down

0 comments on commit 3fd2cf1

Please sign in to comment.