From 4c5b7e9d9569fd9f9bb4888c92136c486df23f2e Mon Sep 17 00:00:00 2001 From: scribu Date: Sun, 17 Feb 2013 01:38:45 +0200 Subject: [PATCH] add function test for wp user create --- features/bootstrap/CommandRunner.php | 15 +++++++++++++++ features/bootstrap/FeatureContext.php | 33 ++++++++++++++++++++------------- features/user.feature | 11 +++++++++++ 3 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 features/user.feature diff --git a/features/bootstrap/CommandRunner.php b/features/bootstrap/CommandRunner.php index 15da72f7..b81d5e54 100644 --- a/features/bootstrap/CommandRunner.php +++ b/features/bootstrap/CommandRunner.php @@ -41,6 +41,21 @@ class WP_CLI_Command_Runner { } public function run( $command, $cwd = false ) { + switch ( $command ) { + case 'core install': + return $this->run_install(); + break; + + case 'core config': + return $this->create_config(); + break; + + default: + return $this->_run( $command, $cwd ); + } + } + + private function _run( $command, $cwd ) { if ( !$cwd ) $cwd = $this->install_dir; diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index dda8354d..4a077a2a 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -87,19 +87,18 @@ class FeatureContext extends BehatContext { $cmd = ltrim( str_replace( 'wp', '', $cmd ) ); - switch ( $cmd ) - { - case 'core install': - $this->result = $this->runner->run_install(); - break; - - case 'core config': - $this->result = $this->runner->create_config(); - break; - - default: - $this->result = $this->runner->run( $cmd ); - } + $this->result = $this->runner->run( $cmd ); + } + + /** + * @When /^I run the previous command again$/ + */ + public function iRunThePreviousCommandAgain() + { + if ( !isset( $this->result ) ) + throw new \Exception( 'No previous command.' ); + + $this->result = $this->runner->run( $this->result->command ); } /** @@ -119,6 +118,14 @@ class FeatureContext extends BehatContext } /** + * @Then /^(STDOUT|STDERR) should match \'([^\']+)\'$/ + */ + public function outputShouldMatch( $stream, $format ) + { + assertStringMatchesFormat( $format, $this->result->$stream ); + } + + /** * @Then /^(STDOUT|STDERR) should not be empty$/ */ public function outputShouldNotBeEmpty( $stream ) diff --git a/features/user.feature b/features/user.feature new file mode 100644 index 00000000..2523ef55 --- /dev/null +++ b/features/user.feature @@ -0,0 +1,11 @@ +Feature: Manage WordPress users + + Scenario: Creating/deleting users + Given WP install + + When I run `wp user create testuser testuser@example.com --porcelain` + Then the return code should be 0 + And STDOUT should match '%d' + + When I run the previous command again + Then the return code should be 1 -- 2.11.0