-
Notifications
You must be signed in to change notification settings - Fork 70
docs: Add and update docs for the 4.0 release #228
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9c158c9
docs: Document our backwards compatibility policy
acoulton ffec67b
docs: Add draft 4.0 upgrade guide
acoulton 2d4e409
docs: Update config docs for 4.0
acoulton 4603ed5
docs: Remove references to PHPDoc annotations
acoulton 94666ad
docs: Copy edits
acoulton 8d0ad57
docs: Copy edits
acoulton 7d5ba37
fix: grammar from review
acoulton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| Backwards Compatibility and the Behat Public API | ||
| ================================================ | ||
|
|
||
| Behat follows Semantic Versioning. For minor or patch releases, we aim to keep things stable: | ||
|
|
||
| * CLI arguments and options will stay the same. We may add new ones, but existing ones will continue to work as they do | ||
| now. | ||
| * Configuration options will not change or be removed. New options may be added, and their default values will match | ||
| the previous behavior. | ||
| * Machine-readable output (like JSON or JUnit) will keep the same fields and data types. We might add new fields or | ||
| change how text is formatted (like adding or removing whitespace), but the structure will remain compatible. | ||
| * Any changes to the public API (interfaces, classes, and behavior) will be backwards-compatible with the previous | ||
| version. | ||
| * Your code (step definitions, hooks, transformations) will run the same way between versions - including | ||
| that we will trigger hooks in the same order. | ||
| * Behat's event dispatcher will fire the same events in the same order. We might add new events in between, but | ||
| existing ones will stay. | ||
|
|
||
| The only time we might break this is to fix a critical bug or a security issue that cannot be resolved any other way. | ||
|
|
||
| Note that from version 4.0 onwards, we do not guarantee the exact format of human-readable output (like the ``progress`` | ||
| or ``pretty`` formatters). These are intended for people to read, so we may improve them over time. | ||
|
|
||
| What counts as Behat's "Public API"? | ||
| ------------------------------------ | ||
|
|
||
| Starting with version 3.30.0, all interfaces, classes, and methods in Behat are **internal by default**. We follow the | ||
| `phpstan backwards compatibility convention`_, which means code is only part of our public API if it is explicitly | ||
| marked with the ``@api`` tag. | ||
|
|
||
| * In Behat 4.0 and later, our compatibility promise only applies to code marked with ``@api``. Anything else may change | ||
| in any release. | ||
| * In Behat 3.x, we maintain compatibility for the entire codebase. However, if you are using code that is not | ||
| marked ``@api``, we recommend updating your code or asking us to make it public. | ||
|
|
||
| .. note:: | ||
|
|
||
| We are happy to consider making more of the Behat codebase public. If you need an ``@api`` tag added, please let | ||
| us know! We will look at your use case and see how it affects the long-term maintenance of Behat. | ||
|
|
||
| Please open an issue (or even better a Pull Request) with details on what you would like to use and why. | ||
|
|
||
| Classes | ||
| ~~~~~~~ | ||
|
|
||
| * Only (non-final) classes with ``@api`` in their PHPDoc can be extended. | ||
| * Objects can only be created via ``new`` if the PHPDoc of the | ||
| public constructor is directly tagged with ``@api``. In all other cases | ||
| (even if the class PHPDoc has ``@api``), instances of the class should | ||
| only be created by / retrieved from Behat's service container. | ||
| * Methods can only be called if there is an ``@api`` tag in the PHPDoc | ||
| of the method, declaring class, or declaring interface. | ||
| * Constants can only be accessed if there is an ``@api`` tag in the | ||
| PHPDoc of the constant, declaring class, or declaring interface. | ||
|
|
||
| Interfaces | ||
| ~~~~~~~~~~ | ||
|
|
||
| * Interfaces with ``@api`` in their PHPDoc can be implemented and extended. | ||
| * All methods from interfaces with ``@api`` in their PHPDoc can be called. | ||
|
|
||
| Traits | ||
| ~~~~~~ | ||
|
|
||
| * No Behat traits can be used. | ||
|
|
||
|
|
||
| Other tips for extension authors | ||
| -------------------------------- | ||
|
|
||
| Our compatibility promise covers changes to existing code, but we will still add new features like CLI arguments, | ||
| config options, or methods. | ||
|
|
||
| To avoid conflicts with future versions of Behat, we recommend following these practices: | ||
|
|
||
| * Do not use the ``Behat`` namespace for your own code. | ||
| * Only add configuration options within your extension's own namespace. | ||
| * While you can add new CLI commands or flags, it's safer to use configuration files or Behat's ``--profile`` feature. | ||
| This avoids naming conflicts with future Behat versions. | ||
| * If you extend a Behat class (marked ``@api``), try to avoid adding new public methods. This protects you if Behat adds | ||
| a method with the same name in the future. | ||
|
|
||
| .. _`phpstan backwards compatibility convention`: https://phpstan.org/developing-extensions/backward-compatibility-promise |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| Upgrading to Behat 4.0 | ||
| ====================== | ||
|
|
||
| We want to make upgrading to Behat 4.0 as smooth as possible. While there are some breaking changes, we've tried to | ||
| keep them to a minimum. | ||
|
|
||
| If you are an end-user (meaning you use Behat to run tests but haven't written custom extensions), most of these changes | ||
| won't affect you. In many cases, you can use automated tools to handle the upgrade for you. Follow this guide to get | ||
| started. | ||
|
|
||
| Upgrading for users | ||
| -------------------- | ||
|
|
||
| For most projects, these are the main changes: | ||
|
|
||
| * **PHP Configuration:** We now use PHP for configuration. YAML files are no longer supported. Behat will look for | ||
| ``behat.php`` or ``behat.dist.php`` in your current directory. | ||
| * **PHP Attributes:** We've replaced PHPDoc annotations (like ``@Given`` or ``@BeforeScenario``) with native PHP | ||
| Attributes. | ||
| * **Cleanup:** All previously deprecated features and code have been removed. | ||
| * **New Parser Mode:** We now default to a newer parser compatibility mode | ||
| (:doc:`GHERKIN_32 </user_guide/gherkin/parser_mode>`). | ||
|
|
||
| Step-by-step preparation | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| **Before** you switch to Behat 4.0, we recommend taking these steps: | ||
|
|
||
| 1. **Update Behat 3:** Make sure you are using the latest version of Behat 3.x. | ||
| 2. **Convert Config:** If you use YAML, run ``vendor/bin/behat --convert-config`` to `convert it to PHP`_. Review the | ||
| results to make sure everything looks correct. | ||
| 3. **Check File Location:** If your config file is in a ``config/`` folder, move it to your project root or use the | ||
| ``--config`` flag when running Behat. | ||
| 4. **Update Extensions:** Make sure any extensions you use are referenced by their full class name (e.g. | ||
| ``Behat\MinkExtension\ServiceContainer\MinkExtension::class`` not ``Behat\MinkExtension```). The conversion tool | ||
| usually handles this. | ||
| 5. **Convert Annotations:** Use `Rector`_ with the ``->withAttributeSets(behat: true)`` rule to automatically change | ||
| `Behat annotations`_ into PHP Attributes. | ||
| 6. **Check Deprecations:** Run your tests with ``--fail-on-deprecations`` and fix any warnings that appear. | ||
| 7. **Test the New Parser:** Enable the :doc:`GHERKIN_32 parser mode </user_guide/gherkin/parser_mode>` and see if your | ||
| tests still run correctly. If you have issues, you can fix your feature files or use | ||
| ``GherkinCompatibilityMode::LEGACY`` in your config. This mode will be removed in future. | ||
|
|
||
| Ready to upgrade? | ||
| ~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Once you've completed the steps above, update your ``composer.json`` to start using Behat 4.0! | ||
|
|
||
| .. caution:: | ||
| While we are in the alpha phase, we recommend using: | ||
| ``{"require": {"behat/behat": "4.0.0-alpha1@alpha"}}``. | ||
|
|
||
| .. note:: | ||
| Don't forget to update your third-party extensions to versions that support Behat 4.0. If you find one that hasn't | ||
| been updated yet, consider helping out by submitting a Pull Request! The community's help makes the transition faster | ||
| for everyone. | ||
|
|
||
|
|
||
| Upgrading for extension authors | ||
| ------------------------------- | ||
|
|
||
| It's possible to support both Behat 3.x and 4.x at the same time (for example, by using | ||
| ``{"require": {"behat/behat": "^3.x || ^4.x"}}``). | ||
|
|
||
| If your project uses Behat to test itself, first follow the "Upgrading for users" steps above. | ||
|
|
||
| Here are the key changes for all extension authors: | ||
|
|
||
| * **Strict Types:** All interfaces and classes now use strict types for parameters, properties, and return values. As a | ||
| minimum, you will need to add return types to any methods that implement Behat interfaces or extend Behat classes. | ||
| `Rector`_ can automate this for you with the ``AddReturnTypeBasedOnParentClassMethodRector`` (included in the | ||
| ``typeDeclarations`` set). | ||
| * **Public API:** We are now stricter about what is considered public API. This helps us maintain a solid | ||
| :doc:`backwards compatibility promise </releases/backwards-compatibility>`. If your extension needs to use code that | ||
| isn't marked public yet, please let us know. | ||
| * **Full Class Names:** Users can no longer use "short names" for extensions (like ``Behat\MinkExtension``). They must | ||
| now use the fully-qualified class name of your ``Extension`` class. Please update your documentation to reflect this. | ||
| * **Deprecations:** If your extension needs to report deprecations, we recommend using | ||
| ``Behat\Testwork\Deprecation\DeprecationCollector::trigger()`` (available since 3.30.0) instead of ``trigger_error``. | ||
| This ensures they are correctly handled by Behat's deprecation flags regardless of the user's runtime environment. | ||
| * **Event Changes:** The ``ScenarioLikeTested`` base event class has been removed. ``ScenarioTested`` and | ||
| ``BackgroundTested`` are now separate. This may affect you if you maintain a formatter extension. | ||
|
|
||
| There are several other changes that might affect a minority of extension authors. See the full | ||
| `CHANGELOG`_ for details. | ||
|
|
||
| Planned changes before the final 4.0.0 release | ||
| ---------------------------------------------- | ||
|
|
||
| We plan to make two more significant changes before the final 4.0.0 release: | ||
|
|
||
| * **Parameter Matching:** We are reviewing how steps behave when the number of function parameters doesn't match the | ||
| step definition. This will likely trigger a deprecation or a failure. You can follow the progress in `#1691`_. | ||
| * **PHPUnit Assertions:** Support for rendering PHPUnit assertion failures will move to a standalone extension. While | ||
| tests will still pass or fail, the output will be less detailed without the extension. We no longer recommend using | ||
| PHPUnit for assertions within Behat steps, as the PHPUnit project has confirmed this is not supported. See | ||
| `#1746`_ for details. | ||
|
|
||
| We may make additional changes based on feedback from the community as more people begin to upgrade. | ||
|
|
||
| .. _`convert it to PHP`: https://docs.behat.org/en/v3.x/user_guide/configuration/yaml_configuration.html#converting-your-configuration | ||
| .. _`Rector`: https://getrector.com/documentation | ||
| .. _`Behat annotations`: https://docs.behat.org/en/v3.x/user_guide/annotations.html#existing-code | ||
| .. _`AddReturnTypeBasedOnParentClassMethodRector`: https://getrector.com/rule-detail/add-return-type-declaration-based-on-parent-class-method-rector | ||
| .. _`CHANGELOG`: https://github.com/Behat/Behat/blob/4.x/CHANGELOG.md | ||
| .. _`#1691`: https://github.com/Behat/Behat/issues/1691 | ||
| .. _`#1746`: https://github.com/Behat/Behat/issues/1746 | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
"in the future"