Skip to content

Commit

Permalink
Add a test for expected exception when misusing a function that has e…
Browse files Browse the repository at this point in the history
…xisting expectations
  • Loading branch information
John P Bloch authored and johnpbloch committed Sep 20, 2016
1 parent d57aa8b commit a6e4e80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions features/bootstrap/FunctionsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\TableNode;
use Mockery\Exception\NoMatchingExpectationException;

class FunctionsContext implements Context
{
Expand Down Expand Up @@ -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...
}
}

}
6 changes: 6 additions & 0 deletions features/function-mocks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

0 comments on commit a6e4e80

Please sign in to comment.