Skip to content

Commit 1765639

Browse files
schlesseraclaude
andcommitted
Make the run time report work again
Scenario nodes no longer expose their feature file, so per-scenario run times and the scenario part of run directory names were empty. Take the file from the feature instead. The report is written from an after-suite hook, whose output Behat only prints for failed scenarios. Write it to the output stream directly so it shows up with the default progress formatter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9298472 commit 1765639

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎features/behat-steps.feature‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ Feature: Test that WP-CLI Behat steps work as expected
1919
Given an empty directory
2020
Then the {RUN_DIR} directory should exist
2121

22+
Scenario: Name the run directory after the scenario it belongs to
23+
Given an empty directory
24+
25+
When I run `echo {RUN_DIR}`
26+
Then STDOUT should match /wp-cli-test-run-behat-steps\.feature\.\d+-/
27+
2228
Scenario: Test "Given a specific directory" steps
2329
Given an empty directory
2430
And an empty test-dir directory

‎src/Context/FeatureContext.php‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,11 +1440,16 @@ private static function get_event_file( $scope, &$line ): ?string {
14401440

14411441
$line = $scenario_feature->getLine();
14421442

1443-
if ( ! method_exists( $scenario_feature, 'getFile' ) ) {
1444-
return null;
1443+
if ( method_exists( $scenario_feature, 'getFile' ) ) {
1444+
return $scenario_feature->getFile();
1445+
}
1446+
1447+
// Scenario nodes do not know their file, but the feature they belong to does.
1448+
if ( method_exists( $scope, 'getFeature' ) ) {
1449+
return $scope->getFeature()->getFile();
14451450
}
14461451

1447-
return $scenario_feature->getFile();
1452+
return null;
14481453
}
14491454

14501455
/**
@@ -2393,7 +2398,9 @@ private static function log_run_times_after_suite( AfterSuiteScope $scope ): voi
23932398
if ( 'error_log' === self::$output_to ) {
23942399
error_log( $log );
23952400
} else {
2396-
echo PHP_EOL . $log;
2401+
// Behat buffers what hooks echo and only prints it for failed scenarios,
2402+
// so write to the stream directly to get the report in every run.
2403+
fwrite( STDOUT, PHP_EOL . $log . PHP_EOL );
23972404
}
23982405
}
23992406

0 commit comments

Comments
 (0)