Skip to content

Commit

Permalink
Reformat behat test fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpbloch committed Oct 8, 2016
1 parent c7e182b commit c11f5b9
Show file tree
Hide file tree
Showing 3 changed files with 319 additions and 357 deletions.
97 changes: 45 additions & 52 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,54 @@
/**
* Defines application features from the specific context.
*/
class FeatureContext implements Context, SnippetAcceptingContext
{
/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*/
public function __construct()
{
}
class FeatureContext implements Context, SnippetAcceptingContext {
/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*/
public function __construct() {
}

/**
* @BeforeScenario
*/
public function setUpWpMock(BeforeScenarioScope $scope)
{
WP_Mock::setUp();
}
/**
* @BeforeScenario
*/
public function setUpWpMock( BeforeScenarioScope $scope ) {
WP_Mock::setUp();
}

/**
* @AfterScenario
*/
public function tearDownWpMock(AfterScenarioScope $scope)
{
WP_Mock::tearDown();
}
/**
* @AfterScenario
*/
public function tearDownWpMock( AfterScenarioScope $scope ) {
WP_Mock::tearDown();
}

/**
* @Then tearDown should not fail
*/
public function teardownShouldNotFail()
{
WP_Mock::tearDown();
}
/**
* @Then tearDown should not fail
*/
public function teardownShouldNotFail() {
WP_Mock::tearDown();
}

/**
* @When I do nothing
*/
public function iDoNothing()
{
// Move along...
}
/**
* @When I do nothing
*/
public function iDoNothing() {
// Move along...
}

/**
* @Then tearDown should fail
*/
public function teardownShouldFail()
{
try {
$this->teardownShouldNotFail();
throw new PHPUnit_Framework_ExpectationFailedException('WP_Mock Teardown should have failed!');
} catch (\Mockery\Exception\InvalidCountException $e) {
// Move along
}
}
/**
* @Then tearDown should fail
*/
public function teardownShouldFail() {
try {
$this->teardownShouldNotFail();
throw new PHPUnit_Framework_ExpectationFailedException( 'WP_Mock Teardown should have failed!' );
} catch ( \Mockery\Exception\InvalidCountException $e ) {
// Move along
}
}
}
164 changes: 76 additions & 88 deletions features/bootstrap/FunctionsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,104 +4,92 @@
use Behat\Gherkin\Node\TableNode;
use Mockery\Exception\NoMatchingExpectationException;

class FunctionsContext implements Context
{
class FunctionsContext implements Context {

/**
* @Given function :function does not exist
*/
public function functionDoesNotExist($function)
{
PHPUnit_Framework_Assert::assertFalse(function_exists($function));
}
/**
* @Given function :function does not exist
*/
public function functionDoesNotExist( $function ) {
PHPUnit_Framework_Assert::assertFalse( function_exists( $function ) );
}

/**
* @Given I mock passthru function :function with args:
*/
public function iMockPassthruFunctionWithArgs($function, TableNode $args)
{
WP_Mock::passthruFunction($function, array(
'args' => $args->getRow(0),
));
}
/**
* @Given I mock passthru function :function with args:
*/
public function iMockPassthruFunctionWithArgs( $function, TableNode $args ) {
WP_Mock::passthruFunction( $function, array(
'args' => $args->getRow( 0 ),
) );
}

/**
* @Given I mock function :function to return :value
*/
public function iMockFunctionToReturn($function, $value)
{
WP_Mock::userFunction($function, array('return' => $value));
}
/**
* @Given I mock function :function to return :value
*/
public function iMockFunctionToReturn( $function, $value ) {
WP_Mock::userFunction( $function, array( 'return' => $value ) );
}

/**
* @Given I alias :alias to :function
*/
public function iAliasTo($alias, $function)
{
WP_Mock::alias($alias, $function);
}
/**
* @Given I alias :alias to :function
*/
public function iAliasTo( $alias, $function ) {
WP_Mock::alias( $alias, $function );
}

/**
* @Given I mock function :function to echo input
*/
public function iMockFunctionWpMockTestToEcho($function)
{
WP_Mock::echoFunction($function);
}
/**
* @Given I mock function :function to echo input
*/
public function iMockFunctionWpMockTestToEcho( $function ) {
WP_Mock::echoFunction( $function );
}

/**
* @When I mock function :function
*/
public function iMockFunction($function)
{
WP_Mock::userFunction($function);
}
/**
* @When I mock function :function
*/
public function iMockFunction( $function ) {
WP_Mock::userFunction( $function );
}

/**
* @Then function :function should exist
*/
public function functionShouldExist($function)
{
PHPUnit_Framework_Assert::assertTrue(function_exists($function));
}
/**
* @Then function :function should exist
*/
public function functionShouldExist( $function ) {
PHPUnit_Framework_Assert::assertTrue( function_exists( $function ) );
}

/**
* @Then I expect :return when I run :function with args:
*/
public function iExpectWhenIRunWithArgs($return, $function, TableNode $args)
{
PHPUnit_Framework_Assert::assertEquals($return, call_user_func_array($function, $args->getRow(0)));
}
/**
* @Then I expect :return when I run :function with args:
*/
public function iExpectWhenIRunWithArgs( $return, $function, TableNode $args ) {
PHPUnit_Framework_Assert::assertEquals( $return, call_user_func_array( $function, $args->getRow( 0 ) ) );
}

/**
* @Then I expect :return when I run :function
*/
public function iExcpectWhenIRun($return, $function)
{
$this->iExpectWhenIRunWithArgs($return, $function, new TableNode(array(array())));
}
/**
* @Then I expect :return when I run :function
*/
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...
}
}
/**
* @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...
}
}

/**
* @Then I expect function :function to echo :input
*/
public function iExpectFunctionToEcho($function, $input)
{
ob_start();
$function($input);
$output = trim(ob_get_clean());
PHPUnit_Framework_Assert::assertEquals(trim($input), $output);
}
/**
* @Then I expect function :function to echo :input
*/
public function iExpectFunctionToEcho( $function, $input ) {
ob_start();
$function( $input );
$output = trim( ob_get_clean() );
PHPUnit_Framework_Assert::assertEquals( trim( $input ), $output );
}

}
Loading

0 comments on commit c11f5b9

Please sign in to comment.