diff --git a/src/Expectation/Exception/MissingFunctionExpectations.php b/src/Expectation/Exception/MissingFunctionExpectations.php new file mode 100644 index 0000000..89f5494 --- /dev/null +++ b/src/Expectation/Exception/MissingFunctionExpectations.php @@ -0,0 +1,21 @@ + + * @package BrainMonkey + * @license http://opensource.org/licenses/MIT MIT + */ +class MissingFunctionExpectations extends Exception +{ + +} diff --git a/src/Expectation/FunctionStub.php b/src/Expectation/FunctionStub.php index 2521e81..1cdce6e 100644 --- a/src/Expectation/FunctionStub.php +++ b/src/Expectation/FunctionStub.php @@ -42,9 +42,8 @@ public function __construct(FunctionName $function_name) $function = <<expectErrorException(); - Functions\when('since_i_am_not_defined_i_will_trigger_error'); - $this->expectExceptionMsgRegex('/since_i_am_not_defined_i_will_trigger_error.+not defined/'); + $this->expectException(MissingFunctionExpectations::class); + Functions\when('since_i_am_not_defined_i_will_throw_exception'); + $this->expectExceptionMsgRegex('/since_i_am_not_defined_i_will_throw_exception.+not defined/'); /** @noinspection PhpUndefinedFunctionInspection */ - since_i_am_not_defined_i_will_trigger_error(); + since_i_am_not_defined_i_will_throw_exception(); } /** - * @depends testUndefinedFunctionTriggerErrorRightAfterDefinition + * @depends testUndefinedFunctionThrowsExceptionRightAfterDefinition */ public function testUndefinedFunctionSurviveTests() { - static::assertTrue(function_exists('since_i_am_not_defined_i_will_trigger_error')); + static::assertTrue(function_exists('since_i_am_not_defined_i_will_throw_exception')); } /** * @depends testUndefinedFunctionSurviveTests */ - public function testSurvivedFunctionStillTriggerError() + public function testSurvivedFunctionStillThrowsException() { - $this->expectErrorException(); - $this->expectExceptionMsgRegex('/since_i_am_not_defined_i_will_trigger_error.+not defined/'); + $this->expectException(MissingFunctionExpectations::class); + $this->expectExceptionMsgRegex('/since_i_am_not_defined_i_will_throw_exception.+not defined/'); /** @noinspection PhpUndefinedFunctionInspection */ - since_i_am_not_defined_i_will_trigger_error(); + since_i_am_not_defined_i_will_throw_exception(); } /** - * @depends testSurvivedFunctionStillTriggerError + * @depends testSurvivedFunctionStillThrowsException */ public function testNothingJustMockASurvivedFunction() { - Functions\when('since_i_am_not_defined_i_will_trigger_error')->justReturn(1234567890); + Functions\when('since_i_am_not_defined_i_will_throw_exception')->justReturn(1234567890); /** @noinspection PhpUndefinedFunctionInspection */ - static::assertSame(1234567890, since_i_am_not_defined_i_will_trigger_error()); + static::assertSame(1234567890, since_i_am_not_defined_i_will_throw_exception()); } /** * @depends testNothingJustMockASurvivedFunction */ - public function testSurvivedFunctionStillTriggerErrorAfterBeingMocked() + public function testSurvivedFunctionStillThrowsExceptionAfterBeingMocked() { - $this->expectErrorException(); - $this->expectExceptionMsgRegex('/since_i_am_not_defined_i_will_trigger_error.+not defined/'); + $this->expectException(MissingFunctionExpectations::class); + $this->expectExceptionMsgRegex('/since_i_am_not_defined_i_will_throw_exception.+not defined/'); /** @noinspection PhpUndefinedFunctionInspection */ - since_i_am_not_defined_i_will_trigger_error(); + since_i_am_not_defined_i_will_throw_exception(); } public function testAndAlsoExpectIt()