OSDN Git Service

add function test for wp user create
authorscribu <mail@scribu.net>
Sat, 16 Feb 2013 23:38:45 +0000 (01:38 +0200)
committerscribu <mail@scribu.net>
Sun, 17 Feb 2013 02:10:14 +0000 (04:10 +0200)
features/bootstrap/CommandRunner.php
features/bootstrap/FeatureContext.php
features/user.feature [new file with mode: 0644]

index 15da72f..b81d5e5 100644 (file)
@@ -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;
 
index dda8354..4a077a2 100644 (file)
@@ -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 (file)
index 0000000..2523ef5
--- /dev/null
@@ -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