Repository navigation
Support Behat 4 alongside Behat 3 #428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,13 @@ | |
| use Behat\Behat\Hook\Scope\AfterFeatureScope; | ||
| use Behat\Behat\Hook\Scope\BeforeFeatureScope; | ||
| use Behat\Behat\Hook\Scope\BeforeStepScope; | ||
| use Behat\Hook\AfterFeature; | ||
| use Behat\Hook\AfterScenario; | ||
| use Behat\Hook\AfterSuite; | ||
| use Behat\Hook\BeforeFeature; | ||
| use Behat\Hook\BeforeScenario; | ||
| use Behat\Hook\BeforeStep; | ||
| use Behat\Hook\BeforeSuite; | ||
| use SebastianBergmann\CodeCoverage\Report\Clover; | ||
| use SebastianBergmann\CodeCoverage\Driver\Selector; | ||
| use SebastianBergmann\CodeCoverage\Driver\Xdebug; | ||
|
|
@@ -31,7 +38,7 @@ | |
| /** | ||
| * Features context. | ||
| */ | ||
| class FeatureContext implements Context { | ||
| class FeatureContext implements Context, LegacyAnnotations { | ||
|
|
||
| use GivenStepDefinitions; | ||
| use ThenStepDefinitions; | ||
|
|
@@ -261,38 +268,28 @@ class FeatureContext implements Context { | |
| */ | ||
| private $step_line = 0; | ||
|
|
||
| /** | ||
| * @BeforeFeature | ||
| */ | ||
| #[BeforeFeature] | ||
| public static function store_feature( BeforeFeatureScope $scope ): void { | ||
| self::$feature = $scope->getFeature(); | ||
| } | ||
|
|
||
| /** | ||
| * @BeforeScenario | ||
| */ | ||
| #[BeforeScenario] | ||
| public function store_scenario( BeforeScenarioScope $scope ): void { | ||
| $this->scenario = $scope->getScenario(); | ||
| } | ||
|
|
||
| /** | ||
| * @BeforeStep | ||
| */ | ||
| #[BeforeStep] | ||
| public function store_step( BeforeStepScope $scope ): void { | ||
| $this->step_line = $scope->getStep()->getLine(); | ||
| } | ||
|
|
||
| /** | ||
| * @AfterScenario | ||
| */ | ||
| #[AfterScenario] | ||
| public function forget_scenario( AfterScenarioScope $scope ): void { | ||
| $this->step_line = 0; | ||
| $this->scenario = null; | ||
| } | ||
|
|
||
| /** | ||
| * @AfterFeature | ||
| */ | ||
| #[AfterFeature] | ||
| public static function forget_feature( AfterFeatureScope $scope ): void { | ||
| self::$feature = null; | ||
| } | ||
|
|
@@ -1105,9 +1102,7 @@ private static function cache_wp_files( $version = '' ): void { | |
| self::$cache_dir = $cache_dir; | ||
| } | ||
|
|
||
| /** | ||
| * @BeforeSuite | ||
| */ | ||
| #[BeforeSuite] | ||
| public static function prepare( BeforeSuiteScope $scope ): void { | ||
| self::bootstrap_feature_context(); | ||
|
|
||
|
|
@@ -1141,9 +1136,7 @@ public static function prepare( BeforeSuiteScope $scope ): void { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * @AfterSuite | ||
| */ | ||
| #[AfterSuite] | ||
| public static function afterSuite( AfterSuiteScope $scope ): void { | ||
| if ( self::$composer_local_repository ) { | ||
| self::remove_dir( self::$composer_local_repository ); | ||
|
|
@@ -1157,9 +1150,7 @@ public static function afterSuite( AfterSuiteScope $scope ): void { | |
| self::merge_coverage_reports(); | ||
| } | ||
|
|
||
| /** | ||
| * @BeforeScenario | ||
| */ | ||
| #[BeforeScenario] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the On Behat 4.0.0, Before this PR, the method carried a docblock annotation that prototype traversal could reach. Subclass overrides kept their hook. The attribute-based path removes that behavior. Require that an override without its own attribute still registers the hook on Behat 4.0. The fix approach is open. Add a regression test with an unannotated override that calls
|
||
| public function beforeScenario( BeforeScenarioScope $scope ): void { | ||
| if ( self::$log_run_times ) { | ||
| self::log_run_times_before_scenario( $scope ); | ||
|
|
@@ -1182,9 +1173,7 @@ public function beforeScenario( BeforeScenarioScope $scope ): void { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * @AfterScenario | ||
| */ | ||
| #[AfterScenario] | ||
| public function afterScenario( AfterScenarioScope $scope ): void { | ||
|
|
||
| if ( self::$run_dir ) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarify that PHP 8.0 needs a separate suite-hook interface.
The guidance says the annotation interface is implemented only on PHP 7, but then says the interface must carry the
BeforeSuiteandAfterSuiteannotations on PHP 8.0 with Behat 3.15. A package that follows the first statement has no interface on PHP 8.0, so its suite hooks do not run. Name the separate interface for that case, and state that the full interface must not be implemented there because Behat 3 then defines each step twice. Apply the same change to.readme-partials/USING.md, because the README section is generated from that partial.Suggested README wording
Committable suggestion