From a6e4e80a65056a4c94c07e0858592811c433b9e3 Mon Sep 17 00:00:00 2001 From: John P Bloch Date: Sun, 17 Jan 2016 16:20:04 -0600 Subject: [PATCH] Add a test for expected exception when misusing a function that has existing expectations --- features/bootstrap/FunctionsContext.php | 13 +++++++++++++ features/function-mocks.feature | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/features/bootstrap/FunctionsContext.php b/features/bootstrap/FunctionsContext.php index 45b30e26..0ef37f5a 100644 --- a/features/bootstrap/FunctionsContext.php +++ b/features/bootstrap/FunctionsContext.php @@ -2,6 +2,7 @@ use Behat\Behat\Context\Context; use Behat\Gherkin\Node\TableNode; +use Mockery\Exception\NoMatchingExpectationException; class FunctionsContext implements Context { @@ -64,4 +65,16 @@ public function iExcpectWhenIRun($return, $function) $this->iExpectWhenIRunWithArgs($return, $function, new TableNode(array(array()))); } + /** + * @Then I expect an error when I run :function with args: + */ + public function iExpectAnErrorWhenIRunWithArgs($function, TableNode $args) + { + try { + $this->iExpectWhenIRunWithArgs(null, $function, $args); + } catch (NoMatchingExpectationException $e) { + // Move along... + } + } + } diff --git a/features/function-mocks.feature b/features/function-mocks.feature index c5de0303..cfe1065c 100644 --- a/features/function-mocks.feature +++ b/features/function-mocks.feature @@ -17,3 +17,9 @@ Feature: Function mocking Scenario: return value works correctly Given I mock function wpMockTest to return "test value" Then I expect "test value" when I run wpMockTest + + Scenario: expectations cause error on unexpected use + Given I mock passthru function wpMockTest with args: + | bazbat | foobar | + Then I expect an error when I run wpMockTest with args: + | bimbam | bobeep |