Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Context/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,10 @@ public function beforeScenario( BeforeScenarioScope $scope ): void {
public function afterScenario( AfterScenarioScope $scope ): void {

if ( self::$run_dir ) {
// Remove altered WP install, unless there's an error.
if ( $scope->getTestResult()->getResultCode() <= 10 ) {
// Remove altered WP install, unless there's an error (and we are not on CI).
$is_ci = getenv( 'CI' );
$is_debug = getenv( 'WP_CLI_TEST_DEBUG_BEHAT_ENV' );
Comment on lines +749 to +750
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with how other environment variables are checked in this file (e.g., running_with_code_coverage() on line 283), and to make the boolean check more robust, it would be better to explicitly check for 'true' or '1'. Using getenv() directly in a boolean context can have surprising results depending on what the environment variable is set to (e.g., '0' or 'false').

$is_ci    = \in_array( (string) getenv( 'CI' ), [ 'true', '1' ], true );
$is_debug = \in_array( (string) getenv( 'WP_CLI_TEST_DEBUG_BEHAT_ENV' ), [ 'true', '1' ], true );

Comment on lines +748 to +750
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getenv('CI') / getenv('WP_CLI_TEST_DEBUG_BEHAT_ENV') return strings, so values like CI=false will still be truthy in PHP and could trigger cleanup unexpectedly. Consider normalizing these to booleans (e.g., filter_var(..., FILTER_VALIDATE_BOOLEAN)) and updating the comment to mention the debug override (cleanup on CI unless debug is enabled).

Suggested change
// Remove altered WP install, unless there's an error (and we are not on CI).
$is_ci = getenv( 'CI' );
$is_debug = getenv( 'WP_CLI_TEST_DEBUG_BEHAT_ENV' );
// Remove altered WP install, unless there's an error (and we are not on CI, or debug override is enabled).
$is_ci = filter_var( getenv( 'CI' ) ?: false, FILTER_VALIDATE_BOOLEAN );
$is_debug = filter_var( getenv( 'WP_CLI_TEST_DEBUG_BEHAT_ENV' ) ?: false, FILTER_VALIDATE_BOOLEAN );

Copilot uses AI. Check for mistakes.
if ( $scope->getTestResult()->getResultCode() <= 10 || ( $is_ci && ! $is_debug ) ) {
self::remove_dir( self::$run_dir );
}
self::$run_dir = null;
Expand Down
Loading