*
* @param array $parameters context parameters (set them up through behat.yml)
*/
- public function __construct(array $parameters)
+ public function __construct( array $parameters )
{
$this->runner = new WP_CLI_Command_Runner;
}
+ private function replace_variables( &$str )
+ {
+ $str = preg_replace_callback( '/\{(\w+)\}/', array( $this, '_replace_var' ), $str );
+ }
+
+ private function _replace_var( $matches )
+ {
+ $cmd = $matches[0];
+
+ foreach ( array_slice( $matches, 1 ) as $key ) {
+ $cmd = str_replace( '{' . $key . '}', $this->variables[ $key ], $cmd );
+ }
+
+ return $cmd;
+ }
+
/**
* @Given /^an empty directory$/
*/
{
$cmd = ltrim( str_replace( 'wp', '', $cmd ) );
- $cmd = preg_replace_callback( '/\{(\w+)\}/', array( $this, 'replace_var' ), $cmd );
+ $this->replace_variables( $cmd );
$this->result = $this->runner->run( $cmd );
}
- private function replace_var( $matches ) {
- $cmd = $matches[0];
-
- foreach ( array_slice( $matches, 1 ) as $key ) {
- $cmd = str_replace( '{' . $key . '}', $this->variables[ $key ], $cmd );
- }
-
- return $cmd;
- }
-
/**
* @When /^I run the previous command again$/
*/
*/
public function outputShouldBe( $stream, PyStringNode $output )
{
+ $this->replace_variables( $output );
+
$result = rtrim( $this->result->$stream, "\n" );
if ( (string) $output != $result ) {
Feature: Manage WordPress users
- Scenario: Creating/deleting users
+ Scenario: Creating/updating/deleting users
Given WP install
When I run `wp user create testuser testuser@example.com --porcelain`
When I run the previous command again
Then the return code should be 1
+ When I run `wp user update {USER_ID} --displayname=Foo`
+ Then it should run without errors
+ And STDOUT should be:
+ """
+ Success: Updated user {USER_ID}.
+ """
+
When I run `wp user delete {USER_ID}`
Then it should run without errors