return array();
}
- public function replace_variables( &$str )
+ public function replace_variables( $str )
{
- $str = preg_replace_callback( '/\{(\w+)\}/', array( $this, '_replace_var' ), $str );
+ return preg_replace_callback( '/\{([A-Z_]+)\}/', array( $this, '_replace_var' ), $str );
}
private function _replace_var( $matches )
$steps->When( '/^I run `wp (.+)`$/',
function ( $world, $cmd ) {
- $world->replace_variables( $cmd );
-
- $world->result = $world->run( $cmd );
+ $world->result = $world->run( $world->replace_variables( $cmd ) );
}
);
}
);
-$steps->Then( '/^(STDOUT|STDERR) should be:$/',
- function ( $world, $stream, PyStringNode $output ) {
- $world->replace_variables( $output );
+$steps->Then( '/^(STDOUT|STDERR) should (be|contain|not contain):$/',
+ function ( $world, $stream, $action, PyStringNode $expected ) {
+ $output = $world->replace_variables( $world->result->$stream );
- $result = rtrim( $world->result->$stream, "\n" );
+ $expected = (string) $expected;
- if ( (string) $output != $result ) {
- throw new \Exception( $world->result->$stream );
+ switch ( $action ) {
+
+ case 'be':
+ $r = $expected === rtrim( $output, "\n" );
+ break;
+
+ case 'contain':
+ $r = false !== strpos( $output, $expected );
+ break;
+
+ case 'not contain':
+ $r = false === strpos( $output, $expected );
+ break;
+
+ default:
+ throw new PendingException();
}
- }
-);
-$steps->Then( '/^(STDOUT|STDERR) should contain:$/',
- function ( $world, $stream, PyStringNode $output ) {
- if ( false === strpos( $world->result->$stream, (string) $output ) ) {
- throw new \Exception( $world->result->$stream );
+ if ( !$r ) {
+ throw new \Exception( $output );
}
}
);