Skip to content

Commit 9ed5cd4

Browse files
authored
Merge pull request #399 from wp-cli/perf/measure-run-times
Make the run time report work again
2 parents dbcbdc2 + 1765639 commit 9ed5cd4

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
@@ -1442,11 +1442,16 @@ private static function get_event_file( $scope, &$line ): ?string {
14421442

14431443
$line = $scenario_feature->getLine();
14441444

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

1449-
return $scenario_feature->getFile();
1454+
return null;
14501455
}
14511456

14521457
/**
@@ -2705,7 +2710,9 @@ private static function log_run_times_after_suite( AfterSuiteScope $scope ): voi
27052710
if ( 'error_log' === self::$output_to ) {
27062711
error_log( $log );
27072712
} else {
2708-
echo PHP_EOL . $log;
2713+
// Behat buffers what hooks echo and only prints it for failed scenarios,
2714+
// so write to the stream directly to get the report in every run.
2715+
fwrite( STDOUT, PHP_EOL . $log . PHP_EOL );
27092716
}
27102717
}
27112718

0 commit comments

Comments
 (0)