From 7cd66058ce504a5a60bbda5f956002f3130986be Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 29 Jul 2026 12:04:08 +0200 Subject: [PATCH] Behat steps: support file names containing spaces --- features/behat-steps.feature | 25 +++++++++++++++++++++++++ src/Context/GivenStepDefinitions.php | 4 ++-- src/Context/ThenStepDefinitions.php | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/features/behat-steps.feature b/features/behat-steps.feature index 431f56e9..b38eac4c 100644 --- a/features/behat-steps.feature +++ b/features/behat-steps.feature @@ -44,6 +44,18 @@ Feature: Test that WP-CLI Behat steps work as expected Hello World """ + Scenario: Test "Given a file" step with quoted path containing spaces + Given an empty directory + And a "test with spaces.txt" file: + """ + Hello World with Spaces + """ + Then the "test with spaces.txt" file should exist + And the "test with spaces.txt" file should contain: + """ + Hello World with Spaces + """ + Scenario: Test "Given a cache file" step Given a WP installation And an empty cache @@ -57,6 +69,19 @@ Feature: Test that WP-CLI Behat steps work as expected Cached content """ + Scenario: Test "Given a cache file" step with quoted path containing spaces + Given a WP installation + And an empty cache + And a "test cache with spaces.txt" cache file: + """ + Cached Content with Spaces + """ + Then the "{SUITE_CACHE_DIR}/test cache with spaces.txt" file should exist + And the "{SUITE_CACHE_DIR}/test cache with spaces.txt" file should contain: + """ + Cached Content with Spaces + """ + Scenario: Test string replacement in file Given an empty directory And a config.txt file: diff --git a/src/Context/GivenStepDefinitions.php b/src/Context/GivenStepDefinitions.php index f12e1029..baf92cf9 100644 --- a/src/Context/GivenStepDefinitions.php +++ b/src/Context/GivenStepDefinitions.php @@ -120,14 +120,14 @@ public function given_an_empty_cache(): void { * * @access public * - * @Given /^an? ([^\s]+) (file|cache file):$/ + * @Given /^an? ("[^"]+"|[^\s]+) (file|cache file):$/ * * @param string $path * @param string $type * @param PyStringNode $content */ public function given_a_specific_file( $path, $type, PyStringNode $content ): void { - $path = $this->replace_variables( (string) $path ); + $path = trim( $this->replace_variables( (string) $path ), '"' ); $content = $this->replace_variables( (string) $content ) . "\n"; $full_path = 'cache file' === $type ? $this->variables['SUITE_CACHE_DIR'] . "/$path" diff --git a/src/Context/ThenStepDefinitions.php b/src/Context/ThenStepDefinitions.php index 0f5b4c41..294a20ed 100644 --- a/src/Context/ThenStepDefinitions.php +++ b/src/Context/ThenStepDefinitions.php @@ -458,7 +458,7 @@ public function then_stdout_stderr_should_be_a_specific_version_string( $stream, * @param string $expected Expected content. */ public function then_a_specific_file_folder_should_exist( $path, $type, $strictly, $action, $expected = null ): void { - $path = $this->replace_variables( $path ); + $path = trim( $this->replace_variables( $path ), '"' ); // If it's a relative path, make it relative to the current test dir. if ( ! Path::is_absolute( $path ) ) {