diff --git a/features/bootstrap/FeatureContext.php b/features/bootstrap/FeatureContext.php index ed863a6271..76f84ad9d0 100644 --- a/features/bootstrap/FeatureContext.php +++ b/features/bootstrap/FeatureContext.php @@ -8,6 +8,9 @@ use \WP_CLI\Process; use \WP_CLI\Utils; +use Symfony\Component\Filesystem\Filesystem, + Symfony\Component\Filesystem\Exception\IOExceptionInterface; + // Inside a community package if ( file_exists( __DIR__ . '/utils.php' ) ) { require_once __DIR__ . '/utils.php'; @@ -44,7 +47,7 @@ */ class FeatureContext extends BehatContext implements ClosuredContextInterface { - private static $cache_dir, $suite_cache_dir; + private static $cache_dir, $suite_cache_dir, $fs; private static $db_settings = array( 'dbname' => 'wp_cli_test', @@ -110,7 +113,7 @@ public static function prepare( SuiteEvent $event ) { */ public static function afterSuite( SuiteEvent $event ) { if ( self::$suite_cache_dir ) { - Process::create( Utils\esc_cmd( 'rm -r %s', self::$suite_cache_dir ), null, self::get_process_env_variables() )->run(); + self::$fs->remove( self::$suite_cache_dir ); } } @@ -128,13 +131,13 @@ public function afterScenario( $event ) { if ( isset( $this->variables['RUN_DIR'] ) ) { // remove altered WP install, unless there's an error if ( $event->getResult() < 4 && 0 === strpos( $this->variables['RUN_DIR'], sys_get_temp_dir() ) ) { - $this->proc( Utils\esc_cmd( 'rm -rf %s', $this->variables['RUN_DIR'] ) )->run(); + self::$fs->remove( $this->variables['RUN_DIR'] ); } } // Remove WP-CLI package directory if ( isset( $this->variables['PACKAGE_PATH'] ) ) { - $this->proc( Utils\esc_cmd( 'rm -rf %s', $this->variables['PACKAGE_PATH'] ) )->run(); + self::$fs->remove( $this->variables['PACKAGE_PATH'] ); } foreach ( $this->running_procs as $proc ) { @@ -189,6 +192,9 @@ public function __construct( array $parameters ) { $this->drop_db(); $this->set_cache_dir(); $this->variables['CORE_CONFIG_SETTINGS'] = Utils\assoc_args_to_str( self::$db_settings ); + if ( ! self::$fs ) { + self::$fs = new FileSystem; + } } public function getStepDefinitionResources() {