OSDN Git Service

add run cmd from subdir step definition
authorscribu <mail@scribu.net>
Tue, 26 Mar 2013 17:48:21 +0000 (19:48 +0200)
committerscribu <mail@scribu.net>
Tue, 26 Mar 2013 18:08:22 +0000 (20:08 +0200)
features/bootstrap/FeatureContext.php
features/steps/basic_steps.php

index 9776e56..bf49338 100644 (file)
@@ -117,10 +117,12 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface {
                self::run_sql( "DROP DATABASE IF EXISTS $dbname" );
        }
 
-       private function _run( $command, $assoc_args ) {
+       private function _run( $command, $assoc_args, $subdir = '' ) {
                if ( !empty( $assoc_args ) )
                        $command .= \WP_CLI\Utils\assoc_args_to_str( $assoc_args );
 
+               $subdir = $this->get_path( $subdir );
+
                $cmd = __DIR__ . "/../../bin/wp $command";
 
                $descriptors = array(
@@ -129,7 +131,7 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface {
                        2 => array( 'pipe', 'w' ),
                );
 
-               $proc = proc_open( $cmd, $descriptors, $pipes, $this->install_dir );
+               $proc = proc_open( $cmd, $descriptors, $pipes, $subdir );
 
                $STDOUT = stream_get_contents( $pipes[1] );
                fclose( $pipes[1] );
@@ -148,13 +150,13 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface {
                return $r;
        }
 
-       public function run( $command, $assoc_args = array() ) {
+       public function run( $command, $assoc_args = array(), $subdir = '' ) {
                if ( isset( self::$additional_args[ $command ] ) ) {
                        $assoc_args = array_merge( self::$additional_args[ $command ],
                                $assoc_args );
                }
 
-               return $this->_run( $command, $assoc_args );
+               return $this->_run( $command, $assoc_args, $subdir );
        }
 
        public function move_files( $src, $dest ) {
@@ -189,8 +191,8 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface {
                $this->create_db();
                $this->create_empty_dir();
                $this->download_wordpress_files( $subdir );
-               $this->run( 'core config', array( 'path' => $subdir ) );
-               $this->run( 'core install', array( 'path' => $subdir ) );
+               $this->run( 'core config', array(), $subdir );
+               $this->run( 'core install', array(), $subdir );
        }
 }
 
index 7e9509e..352bdb7 100644 (file)
@@ -105,6 +105,12 @@ $steps->When( '/^I run `wp (.+)`$/',
        }
 );
 
+$steps->When( "/^I run `wp (.+)` from '([^\s]+)'$/",
+       function ( $world, $cmd, $subdir ) {
+               $world->result = $world->run( $world->replace_variables( $cmd ), array(), $subdir );
+       }
+);
+
 $steps->When( '/^I run the previous command again$/',
        function ( $world ) {
                if ( !isset( $world->result ) )