3 use Behat\Gherkin\Node\PyStringNode,
4 Behat\Gherkin\Node\TableNode;
6 $steps->Given( '/^an empty directory$/',
8 $world->create_run_dir();
12 $steps->Given( '/^a ([^\s]+) file:$/',
13 function ( $world, $path, PyStringNode $content ) {
14 $content = (string) $content . "\n";
15 $full_path = $world->variables['RUN_DIR'] . "/$path";
16 Process::create( \WP_CLI\utils\esc_cmd( 'mkdir -p %s', dirname( $full_path ) ) )->run_check();
17 file_put_contents( $full_path, $content );
21 $steps->Given( '/^WP files$/',
23 $world->download_wp();
27 $steps->Given( '/^wp-config\.php$/',
29 $world->create_config();
33 $steps->Given( '/^a database$/',
39 $steps->Given( '/^a WP install$/',
45 $steps->Given( "/^a WP install in '([^\s]+)'$/",
46 function ( $world, $subdir ) {
47 $world->install_wp( $subdir );
51 $steps->Given( '/^a WP multisite install$/',
54 $world->proc( 'wp core install-network', array( 'title' => 'WP CLI Network' ) )->run_check();
58 $steps->Given( '/^a custom wp-content directory$/',
60 $wp_config_path = $world->variables['RUN_DIR'] . "/wp-config.php";
62 $wp_config_code = file_get_contents( $wp_config_path );
64 $world->move_files( 'wp-content', 'my-content' );
65 $world->add_line_to_wp_config( $wp_config_code,
66 "define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/my-content' );" );
68 $world->move_files( 'my-content/plugins', 'my-plugins' );
69 $world->add_line_to_wp_config( $wp_config_code,
70 "define( 'WP_PLUGIN_DIR', __DIR__ . '/my-plugins' );" );
72 file_put_contents( $wp_config_path, $wp_config_code );
76 $steps->Given( '/^download:$/',
77 function ( $world, TableNode $table ) {
78 foreach ( $table->getHash() as $row ) {
79 $path = $world->replace_variables( $row['path'] );
80 if ( file_exists( $path ) ) {
81 // assume it's the same file and skip re-download
85 \Process::create( \WP_CLI\Utils\esc_cmd( 'curl -sSL %s > %s', $row['url'], $path ) )->run_check();
90 $steps->Given( '/^save (STDOUT|STDERR) ([\'].+[^\'])?as \{(\w+)\}$/',
91 function ( $world, $stream, $output_filter, $key ) {
93 if ( $output_filter ) {
94 $output_filter = '/' . trim( str_replace( '%s', '(.+[^\b])', $output_filter ), "' " ) . '/';
95 if ( false !== preg_match( $output_filter, $world->result->$stream, $matches ) )
96 $output = array_pop( $matches );
100 $output = $world->result->$stream;
102 $world->variables[ $key ] = trim( $output, "\n" );