diff --git a/features/behat-steps.feature b/features/behat-steps.feature index 1620e011..c8f14937 100644 --- a/features/behat-steps.feature +++ b/features/behat-steps.feature @@ -19,6 +19,12 @@ Feature: Test that WP-CLI Behat steps work as expected Given an empty directory Then the {RUN_DIR} directory should exist + Scenario: Name the run directory after the scenario it belongs to + Given an empty directory + + When I run `echo {RUN_DIR}` + Then STDOUT should match /wp-cli-test-run-behat-steps\.feature\.\d+-/ + Scenario: Test "Given a specific directory" steps Given an empty directory And an empty test-dir directory diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index ba8ae9f5..8996437a 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -1440,11 +1440,16 @@ private static function get_event_file( $scope, &$line ): ?string { $line = $scenario_feature->getLine(); - if ( ! method_exists( $scenario_feature, 'getFile' ) ) { - return null; + if ( method_exists( $scenario_feature, 'getFile' ) ) { + return $scenario_feature->getFile(); + } + + // Scenario nodes do not know their file, but the feature they belong to does. + if ( method_exists( $scope, 'getFeature' ) ) { + return $scope->getFeature()->getFile(); } - return $scenario_feature->getFile(); + return null; } /** @@ -2393,7 +2398,9 @@ private static function log_run_times_after_suite( AfterSuiteScope $scope ): voi if ( 'error_log' === self::$output_to ) { error_log( $log ); } else { - echo PHP_EOL . $log; + // Behat buffers what hooks echo and only prints it for failed scenarios, + // so write to the stream directly to get the report in every run. + fwrite( STDOUT, PHP_EOL . $log . PHP_EOL ); } }