From fedc71802971f1da832fb99ba3e5322bc5bad838 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sat, 4 Aug 2018 16:40:20 +0200 Subject: [PATCH] Remove left-over Behat step definitions --- features/steps/given.php | 219 ------------------------------------ features/steps/then.php | 237 --------------------------------------- features/steps/when.php | 54 --------- 3 files changed, 510 deletions(-) delete mode 100644 features/steps/given.php delete mode 100644 features/steps/then.php delete mode 100644 features/steps/when.php diff --git a/features/steps/given.php b/features/steps/given.php deleted file mode 100644 index 3e501c2c7..000000000 --- a/features/steps/given.php +++ /dev/null @@ -1,219 +0,0 @@ -Given( '/^an empty directory$/', - function ( $world ) { - $world->create_run_dir(); - } -); - -$steps->Given( '/^an? (empty|non-existent) ([^\s]+) directory$/', - function ( $world, $empty_or_nonexistent, $dir ) { - $dir = $world->replace_variables( $dir ); - if ( ! WP_CLI\Utils\is_path_absolute( $dir ) ) { - $dir = $world->variables['RUN_DIR'] . "/$dir"; - } - if ( 0 !== strpos( $dir, sys_get_temp_dir() ) ) { - throw new RuntimeException( sprintf( "Attempted to delete directory '%s' that is not in the temp directory '%s'. " . __FILE__ . ':' . __LINE__, $dir, sys_get_temp_dir() ) ); - } - $world->remove_dir( $dir ); - if ( 'empty' === $empty_or_nonexistent ) { - mkdir( $dir, 0777, true /*recursive*/ ); - } - } -); - -$steps->Given( '/^an empty cache/', - function ( $world ) { - $world->variables['SUITE_CACHE_DIR'] = FeatureContext::create_cache_dir(); - } -); - -$steps->Given( '/^an? ([^\s]+) file:$/', - function ( $world, $path, PyStringNode $content ) { - $content = (string) $content . "\n"; - $full_path = $world->variables['RUN_DIR'] . "/$path"; - $dir = dirname( $full_path ); - if ( ! file_exists( $dir ) ) { - mkdir( $dir, 0777, true /*recursive*/ ); - } - file_put_contents( $full_path, $content ); - } -); - -$steps->Given( '/^"([^"]+)" replaced with "([^"]+)" in the ([^\s]+) file$/', function( $world, $search, $replace, $path ) { - $full_path = $world->variables['RUN_DIR'] . "/$path"; - $contents = file_get_contents( $full_path ); - $contents = str_replace( $search, $replace, $contents ); - file_put_contents( $full_path, $contents ); -}); - -$steps->Given( '/^WP files$/', - function ( $world ) { - $world->download_wp(); - } -); - -$steps->Given( '/^wp-config\.php$/', - function ( $world ) { - $world->create_config(); - } -); - -$steps->Given( '/^a database$/', - function ( $world ) { - $world->create_db(); - } -); - -$steps->Given( '/^a WP (install|installation)$/', - function ( $world ) { - $world->install_wp(); - } -); - -$steps->Given( "/^a WP (install|installation) in '([^\s]+)'$/", - function ( $world, $_, $subdir ) { - $world->install_wp( $subdir ); - } -); - -$steps->Given( '/^a WP (install|installation) with Composer$/', - function ( $world ) { - $world->install_wp_with_composer(); - } -); - -$steps->Given( "/^a WP (install|installation) with Composer and a custom vendor directory '([^\s]+)'$/", - function ( $world, $_, $vendor_directory ) { - $world->install_wp_with_composer( $vendor_directory ); - } -); - -$steps->Given( '/^a WP multisite (subdirectory|subdomain)?\s?(install|installation)$/', - function ( $world, $type = 'subdirectory' ) { - $world->install_wp(); - $subdomains = ! empty( $type ) && 'subdomain' === $type ? 1 : 0; - $world->proc( 'wp core install-network', array( 'title' => 'WP CLI Network', 'subdomains' => $subdomains ) )->run_check(); - } -); - -$steps->Given( '/^these installed and active plugins:$/', - function( $world, $stream ) { - $plugins = implode( ' ', array_map( 'trim', explode( PHP_EOL, (string)$stream ) ) ); - $world->proc( "wp plugin install $plugins --activate" )->run_check(); - } -); - -$steps->Given( '/^a custom wp-content directory$/', - function ( $world ) { - $wp_config_path = $world->variables['RUN_DIR'] . "/wp-config.php"; - - $wp_config_code = file_get_contents( $wp_config_path ); - - $world->move_files( 'wp-content', 'my-content' ); - $world->add_line_to_wp_config( $wp_config_code, - "define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/my-content' );" ); - - $world->move_files( 'my-content/plugins', 'my-plugins' ); - $world->add_line_to_wp_config( $wp_config_code, - "define( 'WP_PLUGIN_DIR', __DIR__ . '/my-plugins' );" ); - - file_put_contents( $wp_config_path, $wp_config_code ); - } -); - -$steps->Given( '/^download:$/', - function ( $world, TableNode $table ) { - foreach ( $table->getHash() as $row ) { - $path = $world->replace_variables( $row['path'] ); - if ( file_exists( $path ) ) { - // assume it's the same file and skip re-download - continue; - } - - Process::create( \WP_CLI\Utils\esc_cmd( 'curl -sSL %s > %s', $row['url'], $path ) )->run_check(); - } - } -); - -$steps->Given( '/^save (STDOUT|STDERR) ([\'].+[^\'])?\s?as \{(\w+)\}$/', - function ( $world, $stream, $output_filter, $key ) { - - $stream = strtolower( $stream ); - - if ( $output_filter ) { - $output_filter = '/' . trim( str_replace( '%s', '(.+[^\b])', $output_filter ), "' " ) . '/'; - if ( false !== preg_match( $output_filter, $world->result->$stream, $matches ) ) - $output = array_pop( $matches ); - else - $output = ''; - } else { - $output = $world->result->$stream; - } - $world->variables[ $key ] = trim( $output, "\n" ); - } -); - -$steps->Given( '/^a new Phar with (?:the same version|version "([^"]+)")$/', - function ( $world, $version = 'same' ) { - $world->build_phar( $version ); - } -); - -$steps->Given( '/^a downloaded Phar with (?:the same version|version "([^"]+)")$/', - function ( $world, $version = 'same' ) { - $world->download_phar( $version ); - } -); - -$steps->Given( '/^save the (.+) file ([\'].+[^\'])?as \{(\w+)\}$/', - function ( $world, $filepath, $output_filter, $key ) { - $full_file = file_get_contents( $world->replace_variables( $filepath ) ); - - if ( $output_filter ) { - $output_filter = '/' . trim( str_replace( '%s', '(.+[^\b])', $output_filter ), "' " ) . '/'; - if ( false !== preg_match( $output_filter, $full_file, $matches ) ) - $output = array_pop( $matches ); - else - $output = ''; - } else { - $output = $full_file; - } - $world->variables[ $key ] = trim( $output, "\n" ); - } -); - -$steps->Given('/^a misconfigured WP_CONTENT_DIR constant directory$/', - function($world) { - $wp_config_path = $world->variables['RUN_DIR'] . "/wp-config.php"; - - $wp_config_code = file_get_contents( $wp_config_path ); - - $world->add_line_to_wp_config( $wp_config_code, - "define( 'WP_CONTENT_DIR', '' );" ); - - file_put_contents( $wp_config_path, $wp_config_code ); - } -); - -$steps->Given( '/^a dependency on current wp-cli$/', - function ( $world ) { - $world->composer_require_current_wp_cli(); - } -); - -$steps->Given( '/^a PHP built-in web server$/', - function ( $world ) { - $world->start_php_server(); - } -); - -$steps->Given( "/^a PHP built-in web server to serve '([^\s]+)'$/", - function ( $world, $subdir ) { - $world->start_php_server( $subdir ); - } -); diff --git a/features/steps/then.php b/features/steps/then.php deleted file mode 100644 index 21589e737..000000000 --- a/features/steps/then.php +++ /dev/null @@ -1,237 +0,0 @@ -Then( '/^the return code should( not)? be (\d+)$/', - function ( $world, $not, $return_code ) { - if ( ( ! $not && $return_code != $world->result->return_code ) || ( $not && $return_code == $world->result->return_code ) ) { - throw new RuntimeException( $world->result ); - } - } -); - -$steps->Then( '/^(STDOUT|STDERR) should (be|contain|not contain):$/', - function ( $world, $stream, $action, PyStringNode $expected ) { - - $stream = strtolower( $stream ); - - $expected = $world->replace_variables( (string) $expected ); - - checkString( $world->result->$stream, $expected, $action, $world->result ); - } -); - -$steps->Then( '/^(STDOUT|STDERR) should be a number$/', - function ( $world, $stream ) { - - $stream = strtolower( $stream ); - - assertNumeric( trim( $world->result->$stream, "\n" ) ); - } -); - -$steps->Then( '/^(STDOUT|STDERR) should not be a number$/', - function ( $world, $stream ) { - - $stream = strtolower( $stream ); - - assertNotNumeric( trim( $world->result->$stream, "\n" ) ); - } -); - -$steps->Then( '/^STDOUT should be a table containing rows:$/', - function ( $world, TableNode $expected ) { - $output = $world->result->stdout; - $actual_rows = explode( "\n", rtrim( $output, "\n" ) ); - - $expected_rows = array(); - foreach ( $expected->getRows() as $row ) { - $expected_rows[] = $world->replace_variables( implode( "\t", $row ) ); - } - - compareTables( $expected_rows, $actual_rows, $output ); - } -); - -$steps->Then( '/^STDOUT should end with a table containing rows:$/', - function ( $world, TableNode $expected ) { - $output = $world->result->stdout; - $actual_rows = explode( "\n", rtrim( $output, "\n" ) ); - - $expected_rows = array(); - foreach ( $expected->getRows() as $row ) { - $expected_rows[] = $world->replace_variables( implode( "\t", $row ) ); - } - - $start = array_search( $expected_rows[0], $actual_rows ); - - if ( false === $start ) - throw new \Exception( $world->result ); - - compareTables( $expected_rows, array_slice( $actual_rows, $start ), $output ); - } -); - -$steps->Then( '/^STDOUT should be JSON containing:$/', - function ( $world, PyStringNode $expected ) { - $output = $world->result->stdout; - $expected = $world->replace_variables( (string) $expected ); - - if ( !checkThatJsonStringContainsJsonString( $output, $expected ) ) { - throw new \Exception( $world->result ); - } -}); - -$steps->Then( '/^STDOUT should be a JSON array containing:$/', - function ( $world, PyStringNode $expected ) { - $output = $world->result->stdout; - $expected = $world->replace_variables( (string) $expected ); - - $actualValues = json_decode( $output ); - $expectedValues = json_decode( $expected ); - - $missing = array_diff( $expectedValues, $actualValues ); - if ( !empty( $missing ) ) { - throw new \Exception( $world->result ); - } -}); - -$steps->Then( '/^STDOUT should be CSV containing:$/', - function ( $world, TableNode $expected ) { - $output = $world->result->stdout; - - $expected_rows = $expected->getRows(); - foreach ( $expected as &$row ) { - foreach ( $row as &$value ) { - $value = $world->replace_variables( $value ); - } - } - - if ( ! checkThatCsvStringContainsValues( $output, $expected_rows ) ) - throw new \Exception( $world->result ); - } -); - -$steps->Then( '/^STDOUT should be YAML containing:$/', - function ( $world, PyStringNode $expected ) { - $output = $world->result->stdout; - $expected = $world->replace_variables( (string) $expected ); - - if ( !checkThatYamlStringContainsYamlString( $output, $expected ) ) { - throw new \Exception( $world->result ); - } -}); - -$steps->Then( '/^(STDOUT|STDERR) should be empty$/', - function ( $world, $stream ) { - - $stream = strtolower( $stream ); - - if ( !empty( $world->result->$stream ) ) { - throw new \Exception( $world->result ); - } - } -); - -$steps->Then( '/^(STDOUT|STDERR) should not be empty$/', - function ( $world, $stream ) { - - $stream = strtolower( $stream ); - - if ( '' === rtrim( $world->result->$stream, "\n" ) ) { - throw new Exception( $world->result ); - } - } -); - -$steps->Then( '/^(STDOUT|STDERR) should be a version string (<|<=|>|>=|==|=|!=|<>) ([+\w.{}-]+)$/', - function ( $world, $stream, $operator, $goal_ver ) { - $goal_ver = $world->replace_variables( $goal_ver ); - $stream = strtolower( $stream ); - if ( false === version_compare( trim( $world->result->$stream, "\n" ), $goal_ver, $operator ) ) { - throw new Exception( $world->result ); - } - } -); - -$steps->Then( '/^the (.+) (file|directory) should (exist|not exist|be:|contain:|not contain:)$/', - function ( $world, $path, $type, $action, $expected = null ) { - $path = $world->replace_variables( $path ); - - // If it's a relative path, make it relative to the current test dir - if ( '/' !== $path[0] ) - $path = $world->variables['RUN_DIR'] . "/$path"; - - if ( 'file' == $type ) { - $test = 'file_exists'; - } else if ( 'directory' == $type ) { - $test = 'is_dir'; - } - - switch ( $action ) { - case 'exist': - if ( ! $test( $path ) ) { - throw new Exception( "$path doesn't exist." ); - } - break; - case 'not exist': - if ( $test( $path ) ) { - throw new Exception( "$path exists." ); - } - break; - default: - if ( ! $test( $path ) ) { - throw new Exception( "$path doesn't exist." ); - } - $action = substr( $action, 0, -1 ); - $expected = $world->replace_variables( (string) $expected ); - if ( 'file' == $type ) { - $contents = file_get_contents( $path ); - } else if ( 'directory' == $type ) { - $files = glob( rtrim( $path, '/' ) . '/*' ); - foreach( $files as &$file ) { - $file = str_replace( $path . '/', '', $file ); - } - $contents = implode( PHP_EOL, $files ); - } - checkString( $contents, $expected, $action ); - } - } -); - -$steps->Then( '/^the contents of the (.+) file should match (((\/.+\/)|(#.+#))([a-z]+)?)$/', - function ( $world, $path, $expected ) { - $path = $world->replace_variables( $path ); - // If it's a relative path, make it relative to the current test dir - if ( '/' !== $path[0] ) { - $path = $world->variables['RUN_DIR'] . "/$path"; - } - $contents = file_get_contents( $path ); - assertRegExp( $expected, $contents ); - } -); - -$steps->Then( '/^(STDOUT|STDERR) should match (((\/.+\/)|(#.+#))([a-z]+)?)$/', - function ( $world, $stream, $expected ) { - $stream = strtolower( $stream ); - assertRegExp( $expected, $world->result->$stream ); - } -); - -$steps->Then( '/^an email should (be sent|not be sent)$/', function( $world, $expected ) { - if ( 'be sent' === $expected ) { - assertNotEquals( 0, $world->email_sends ); - } else if ( 'not be sent' === $expected ) { - assertEquals( 0, $world->email_sends ); - } else { - throw new Exception( 'Invalid expectation' ); - } -}); - -$steps->Then( '/^the HTTP status code should be (\d+)$/', - function ( $world, $return_code ) { - $response = \Requests::request( 'http://localhost:8080' ); - assertEquals( $return_code, $response->status_code ); - } -); diff --git a/features/steps/when.php b/features/steps/when.php deleted file mode 100644 index d23aa0e66..000000000 --- a/features/steps/when.php +++ /dev/null @@ -1,54 +0,0 @@ - 'run_check_stderr', - 'try' => 'run' - ); - $method = $map[ $mode ]; - - return $proc->$method(); -} - -function capture_email_sends( $stdout ) { - $stdout = preg_replace( '#WP-CLI test suite: Sent email to.+\n?#', '', $stdout, -1, $email_sends ); - return array( $stdout, $email_sends ); -} - -$steps->When( '/^I launch in the background `([^`]+)`$/', - function ( $world, $cmd ) { - $world->background_proc( $cmd ); - } -); - -$steps->When( '/^I (run|try) `([^`]+)`$/', - function ( $world, $mode, $cmd ) { - $cmd = $world->replace_variables( $cmd ); - $world->result = invoke_proc( $world->proc( $cmd ), $mode ); - list( $world->result->stdout, $world->email_sends ) = capture_email_sends( $world->result->stdout ); - } -); - -$steps->When( "/^I (run|try) `([^`]+)` from '([^\s]+)'$/", - function ( $world, $mode, $cmd, $subdir ) { - $cmd = $world->replace_variables( $cmd ); - $world->result = invoke_proc( $world->proc( $cmd, array(), $subdir ), $mode ); - list( $world->result->stdout, $world->email_sends ) = capture_email_sends( $world->result->stdout ); - } -); - -$steps->When( '/^I (run|try) the previous command again$/', - function ( $world, $mode ) { - if ( !isset( $world->result ) ) - throw new \Exception( 'No previous command.' ); - - $proc = Process::create( $world->result->command, $world->result->cwd, $world->result->env ); - $world->result = invoke_proc( $proc, $mode ); - list( $world->result->stdout, $world->email_sends ) = capture_email_sends( $world->result->stdout ); - } -); -