OSDN Git Service

transparently add additional assoc params to special commands, instead of having...
authorscribu <mail@scribu.net>
Wed, 13 Mar 2013 15:41:35 +0000 (17:41 +0200)
committerscribu <mail@scribu.net>
Wed, 13 Mar 2013 15:41:35 +0000 (17:41 +0200)
features/bootstrap/FeatureContext.php
features/steps/basic_steps.php

index af3e7c4..4a9e952 100644 (file)
@@ -20,6 +20,7 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface
        );
 
        private $install_dir;
+       private $additional_args;
 
        public $variables = array();
 
@@ -32,6 +33,21 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface
        public function __construct( array $parameters )
        {
                $this->drop_db();
+
+               $this->additional_args = array(
+                       'core config' => self::$db_settings,
+
+                       'core install' => array(
+                               'url' => 'http://example.com',
+                               'title' => 'WP CLI Site',
+                               'admin_email' => 'admin@example.com',
+                               'admin_password' => 'password1'
+                       ),
+
+                       'core install-network', array(
+                               'title' => 'WP CLI Network'
+                       )
+               );
        }
 
        public function getStepDefinitionResources()
@@ -129,22 +145,12 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface
        }
 
        public function run( $command, $assoc_args = array() ) {
-               switch ( $command ) {
-               case 'core install':
-                       return $this->run_install();
-                       break;
-
-               case 'core config':
-                       return $this->create_config();
-                       break;
-
-               default:
-                       return $this->_run( $command, $assoc_args );
+               if ( isset( $this->additional_args[ $command ] ) ) {
+                       $assoc_args = array_merge( $this->additional_args[ $command ],
+                               $assoc_args );
                }
-       }
 
-       public function create_config() {
-               return $this->_run( 'core config', self::$db_settings );
+               return $this->_run( $command, $assoc_args );
        }
 
        public function define_custom_wp_content_dir() {
@@ -178,21 +184,6 @@ class FeatureContext extends BehatContext implements ClosuredContextInterface
                $wp_config_code = str_replace( $token, "$line\n\n$token", $wp_config_code );
        }
 
-       public function run_install() {
-               return $this->_run( 'core install', array(
-                       'url' => 'http://example.com',
-                       'title' => 'WP CLI Site',
-                       'admin_email' => 'admin@example.com',
-                       'admin_password' => 'password1'
-               ) );
-       }
-
-       public function run_install_network() {
-               return $this->_run( 'core install-network', array(
-                       'title' => 'WP CLI Network'
-               ) );
-       }
-
        public function download_wordpress_files() {
                // We cache the results of "wp core download" to improve test performance
                // Ideally, we'd cache at the HTTP layer for more reliable tests
index c9c4070..270e9fa 100644 (file)
@@ -18,7 +18,7 @@ $steps->Given( '/^WP files$/',
 
 $steps->Given( '/^wp-config\.php$/',
        function ( $world ) {
-               $world->create_config();
+               $world->run( 'core config' );
        }
 );
 
@@ -33,11 +33,11 @@ $steps->Given( '/^a WP (install|multisite install)$/',
                $world->create_db();
                $world->create_empty_dir();
                $world->download_wordpress_files();
-               $world->create_config();
-               $world->run_install();
+               $world->run( 'core config' );
+               $world->run( 'core install' );
 
                if ( 'multisite install' == $type ) {
-                       $world->run_install_network();
+                       $world->run( 'core install-network' );
                }
        }
 );