Skip to content

Commit 72da881

Browse files
authored
Behat steps: support file names containing spaces (#342)
1 parent 7b76232 commit 72da881

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎features/behat-steps.feature‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ Feature: Test that WP-CLI Behat steps work as expected
4444
Hello World
4545
"""
4646

47+
Scenario: Test "Given a file" step with quoted path containing spaces
48+
Given an empty directory
49+
And a "test with spaces.txt" file:
50+
"""
51+
Hello World with Spaces
52+
"""
53+
Then the "test with spaces.txt" file should exist
54+
And the "test with spaces.txt" file should contain:
55+
"""
56+
Hello World with Spaces
57+
"""
58+
4759
Scenario: Test "Given a cache file" step
4860
Given a WP installation
4961
And an empty cache
@@ -57,6 +69,19 @@ Feature: Test that WP-CLI Behat steps work as expected
5769
Cached content
5870
"""
5971

72+
Scenario: Test "Given a cache file" step with quoted path containing spaces
73+
Given a WP installation
74+
And an empty cache
75+
And a "test cache with spaces.txt" cache file:
76+
"""
77+
Cached Content with Spaces
78+
"""
79+
Then the "{SUITE_CACHE_DIR}/test cache with spaces.txt" file should exist
80+
And the "{SUITE_CACHE_DIR}/test cache with spaces.txt" file should contain:
81+
"""
82+
Cached Content with Spaces
83+
"""
84+
6085
Scenario: Test string replacement in file
6186
Given an empty directory
6287
And a config.txt file:

‎src/Context/GivenStepDefinitions.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ public function given_an_empty_cache(): void {
120120
*
121121
* @access public
122122
*
123-
* @Given /^an? ([^\s]+) (file|cache file):$/
123+
* @Given /^an? ("[^"]+"|[^\s]+) (file|cache file):$/
124124
*
125125
* @param string $path
126126
* @param string $type
127127
* @param PyStringNode $content
128128
*/
129129
public function given_a_specific_file( $path, $type, PyStringNode $content ): void {
130-
$path = $this->replace_variables( (string) $path );
130+
$path = trim( $this->replace_variables( (string) $path ), '"' );
131131
$content = $this->replace_variables( (string) $content ) . "\n";
132132
$full_path = 'cache file' === $type
133133
? $this->variables['SUITE_CACHE_DIR'] . "/$path"

‎src/Context/ThenStepDefinitions.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public function then_stdout_stderr_should_be_a_specific_version_string( $stream,
458458
* @param string $expected Expected content.
459459
*/
460460
public function then_a_specific_file_folder_should_exist( $path, $type, $strictly, $action, $expected = null ): void {
461-
$path = $this->replace_variables( $path );
461+
$path = trim( $this->replace_variables( $path ), '"' );
462462

463463
// If it's a relative path, make it relative to the current test dir.
464464
if ( ! Path::is_absolute( $path ) ) {

0 commit comments

Comments
 (0)