diff --git a/features/behat-steps.feature b/features/behat-steps.feature index 1620e011..2d5e6599 100644 --- a/features/behat-steps.feature +++ b/features/behat-steps.feature @@ -27,6 +27,30 @@ Feature: Test that WP-CLI Behat steps work as expected Given a non-existent test-dir directory Then the test-dir directory should not exist + Scenario: Always run the current version of files created by a scenario + Given an empty directory + And a script.php file: + """ + + */ + private static function get_php_tuning_env_variables(): array { + if ( 'off' === getenv( 'WP_CLI_TEST_PHP_TUNING' ) || self::running_with_code_coverage() ) { + return []; + } + + $env = []; + + if ( false === getenv( 'XDEBUG_MODE' ) && false === getenv( 'XDEBUG_SESSION' ) && false === getenv( 'XDEBUG_CONFIG' ) ) { + $env['XDEBUG_MODE'] = 'off'; + } + + // The file cache cannot be used on its own on Windows. + if ( Utils\is_windows() ) { + return $env; + } + + $temp_dir = rtrim( sys_get_temp_dir(), '/' ); + $config_dir = "{$temp_dir}/wp-cli-test-php-config"; + $cache_dir = "{$temp_dir}/wp-cli-test-opcache"; + + foreach ( [ $config_dir, $cache_dir ] as $dir ) { + if ( ! is_dir( $dir ) && ! @mkdir( $dir, 0777, true ) && ! is_dir( $dir ) ) { + return $env; + } + } + + $excluded = array_unique( array_filter( [ $temp_dir, realpath( $temp_dir ) ] ) ); + file_put_contents( "{$config_dir}/opcache-blacklist.txt", implode( "/\n", $excluded ) . "/\n" ); + + $ini = [ + 'opcache.enable_cli=1', + "opcache.file_cache={$cache_dir}", + 'opcache.file_cache_only=1', + "opcache.blacklist_filename={$config_dir}/opcache-blacklist.txt", + ]; + file_put_contents( "{$config_dir}/wp-cli-tests.ini", implode( "\n", $ini ) . "\n" ); + + // Add to the directories PHP scans for configuration files rather than replacing them. + $scan_dirs = getenv( 'PHP_INI_SCAN_DIR' ); + if ( false === $scan_dirs ) { + $scan_dirs = PHP_CONFIG_FILE_SCAN_DIR; + } + $env['PHP_INI_SCAN_DIR'] = ( '' !== $scan_dirs ? $scan_dirs . PATH_SEPARATOR : '' ) . $config_dir; + + return $env; + } + /** * Get the internal variables to use within tests. *