Skip to content

Convert Behat annotations to PHP attributes in Domain contexts#18811

Merged
TheMilek merged 2 commits intoSylius:2.3from
loic425:behat-annotations-to-attributes/domain
Feb 11, 2026
Merged

Convert Behat annotations to PHP attributes in Domain contexts#18811
TheMilek merged 2 commits intoSylius:2.3from
loic425:behat-annotations-to-attributes/domain

Conversation

@loic425
Copy link
Copy Markdown
Member

@loic425 loic425 commented Feb 11, 2026

Q A
Branch? 2.3
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Related tickets
License MIT

Smaller version of #18810 only applied on Domain contexts.

Summary by CodeRabbit

  • Refactor
    • Modernized Behat test integration by converting step-definition annotations from docblock style to native PHP 8 attributes across test contexts.
    • Updated tooling configuration to enable Behat-style attribute handling during automated code transformations.

@loic425 loic425 requested review from a team as code owners February 11, 2026 08:23
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

Migrates Behat step registrations from PHPDoc annotations to PHP 8 attributes across multiple Behat context files and updates rector.php to enable Behat-style attribute sets (withAttributesSets(behat: true)). One behavioral assertion was added in CartContext to assert the cart still exists.

Changes

Cohort / File(s) Summary
Rector configuration
rector.php
Appended withAttributesSets(behat: true) to Rector configuration to enable Behat attribute sets.
Domain context files (bulk annotation → attributes)
src/Sylius/Behat/Context/Domain/CartContext.php, src/Sylius/Behat/Context/Domain/ManagingOrdersContext.php, src/Sylius/Behat/Context/Domain/ManagingPaymentsContext.php, src/Sylius/Behat/Context/Domain/ManagingPriceHistoryContext.php, src/Sylius/Behat/Context/Domain/ManagingShipmentsContext.php, src/Sylius/Behat/Context/Domain/ManagingShippingMethodsContext.php, src/Sylius/Behat/Context/Domain/NotificationContext.php, src/Sylius/Behat/Context/Domain/SecurityContext.php
Replaced PHPDoc @Given/@When/@Then step annotations with PHP 8 attributes (#[Given], #[When], #[Then]) and added corresponding Behat\Step\* imports. No signature changes.
Domain context files (complex / exception adjustments)
src/Sylius/Behat/Context/Domain/ManagingProductsContext.php, src/Sylius/Behat/Context/Domain/ManagingPromotionCouponsContext.php, src/Sylius/Behat/Context/Domain/ManagingPromotionsContext.php
Converted docblock step annotations to PHP 8 attributes, added Behat\Step imports, and adjusted exception references/aliasing (e.g., DBALException alias). No public API signature changes.
CartContext behavioral change
src/Sylius/Behat/Context/Domain/CartContext.php
In addition to attribute migration, added Assert::notNull($cart->getId()) in thisCartShouldNotBeDeleted to ensure the cart remains present after expired-cart cleanup.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

DX, Maintenance

Suggested reviewers

  • Rafikooo
  • GSadee
  • Wojdylak

Poem

🐰 I hopped through docblocks, one by one,
Swapped old annotations for attributes fun,
Steps now gleam in PHP 8 light,
Tests keep dancing through day and night,
A carrot for modern syntax — hop delight! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: converting Behat annotations to PHP attributes specifically in Domain contexts.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
src/Sylius/Behat/Context/Domain/ManagingProductsContext.php (1)

16-17: Import order: Then should precede When alphabetically.

As per coding guidelines, use imports should be sorted alphabetically. Behat\Step\Then should come before Behat\Step\When.

Suggested fix
-use Behat\Step\When;
-use Behat\Step\Then;
+use Behat\Step\Then;
+use Behat\Step\When;

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 11, 2026

❌ Preview Environment deleted from Bunnyshell

Available commands:

  • 🚀 /bns:deploy to redeploy the environment

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@rector.php`:
- Around line 8-15: The config uses the removed
SetList::BEHAT_ANNOTATIONS_TO_ATTRIBUTES constant; update the RectorConfig setup
to stop passing that set to withSets and instead call withAttributesSets(behat:
true) (or withAttributesSets() to enable all) after your withSets call — modify
the RectorConfig::configure() chain (remove
SetList::BEHAT_ANNOTATIONS_TO_ATTRIBUTES from the array passed to withSets and
append ->withAttributesSets(behat: true)) to use the Rector 2.0.0 attributes
API.

In `@src/Sylius/Behat/Context/Domain/ManagingProductsContext.php`:
- Line 17: Remove the obsolete Doctrine\DBAL\DBALException import and branch and
update the catch to use only the current DBAL exception: delete the use
Doctrine\DBAL\DBALException; import and remove the
class_exists('\Doctrine\DBAL\DBALException') branch, then change the catch in
ManagingProductsContext (currently catch (DBALException|\Doctrine\DBAL\Exception
$exception)) to catch (\Doctrine\DBAL\Exception $exception) so only the DBAL 3.x
exception class is referenced.
🧹 Nitpick comments (11)
src/Sylius/Behat/Context/Domain/ManagingShippingMethodsContext.php (1)

16-18: Imports are not sorted alphabetically.

Per coding guidelines, use imports should be sorted alphabetically. Behat\Behat\Context\Context should come before Behat\Step\*, and Then before When.

Proposed fix
-use Behat\Step\When;
-use Behat\Step\Then;
 use Behat\Behat\Context\Context;
+use Behat\Step\Then;
+use Behat\Step\When;

This same import ordering issue applies to the other context files in this PR (ManagingOrdersContext.php, ManagingPriceHistoryContext.php, ManagingPromotionCouponsContext.php, ManagingPromotionsContext.php). As per coding guidelines: "Sort PHP use imports alphabetically and group by type."

src/Sylius/Behat/Context/Domain/ManagingOrdersContext.php (1)

16-19: Imports are not sorted alphabetically.

Same issue as in ManagingShippingMethodsContext.php. The Behat\Step\* imports should come after Behat\Behat\Context\Context, and should be ordered Given, Then, When.

Proposed fix
-use Behat\Step\When;
-use Behat\Step\Then;
-use Behat\Step\Given;
 use Behat\Behat\Context\Context;
+use Behat\Step\Given;
+use Behat\Step\Then;
+use Behat\Step\When;

As per coding guidelines: "Sort PHP use imports alphabetically and group by type."

src/Sylius/Behat/Context/Domain/ManagingShipmentsContext.php (1)

16-17: Imports are not sorted alphabetically.

Behat\Behat\Context\Context should precede Behat\Step\Then.

Proposed fix
-use Behat\Step\Then;
 use Behat\Behat\Context\Context;
+use Behat\Step\Then;

As per coding guidelines: "Sort PHP use imports alphabetically and group by type."

src/Sylius/Behat/Context/Domain/ManagingPaymentsContext.php (1)

16-17: Imports are not sorted alphabetically.

Same issue — Behat\Behat\Context\Context should come before Behat\Step\Then. As per coding guidelines: "Sort PHP use imports alphabetically and group by type."

src/Sylius/Behat/Context/Domain/ManagingPriceHistoryContext.php (1)

16-18: Imports are not sorted alphabetically.

Same issue. Should be Behat\Behat\Context\Context, Behat\Step\Then, Behat\Step\When. As per coding guidelines: "Sort PHP use imports alphabetically and group by type."

src/Sylius/Behat/Context/Domain/ManagingPromotionCouponsContext.php (1)

16-18: Imports are not sorted alphabetically.

Same issue. Should be Behat\Behat\Context\Context, Behat\Step\Then, Behat\Step\When. As per coding guidelines: "Sort PHP use imports alphabetically and group by type."

src/Sylius/Behat/Context/Domain/ManagingPromotionsContext.php (1)

16-18: Imports are not sorted alphabetically.

Same issue. Should be Behat\Behat\Context\Context, Behat\Step\Then, Behat\Step\When. As per coding guidelines: "Sort PHP use imports alphabetically and group by type."

src/Sylius/Behat/Context/Domain/SecurityContext.php (1)

16-17: Imports are not sorted alphabetically.

Behat\Behat\Context\Context should precede Behat\Step\Given lexicographically.

Proposed fix
-use Behat\Step\Given;
 use Behat\Behat\Context\Context;
+use Behat\Step\Given;

As per coding guidelines: "Sort PHP use imports alphabetically and group by type (classes, functions, constants)".

src/Sylius/Behat/Context/Domain/NotificationContext.php (1)

16-17: Imports are not sorted alphabetically.

Same as SecurityContext.phpBehat\Behat\Context\Context should come before Behat\Step\Then.

Proposed fix
-use Behat\Step\Then;
 use Behat\Behat\Context\Context;
+use Behat\Step\Then;

As per coding guidelines: "Sort PHP use imports alphabetically and group by type (classes, functions, constants)".

src/Sylius/Behat/Context/Domain/CartContext.php (1)

16-18: Imports are not sorted alphabetically.

Behat\Behat\Context\Context should be listed before Behat\Step\Given and Behat\Step\Then.

Proposed fix
-use Behat\Step\Given;
-use Behat\Step\Then;
 use Behat\Behat\Context\Context;
+use Behat\Step\Given;
+use Behat\Step\Then;

As per coding guidelines: "Sort PHP use imports alphabetically and group by type (classes, functions, constants)".

src/Sylius/Behat/Context/Domain/ManagingProductsContext.php (1)

16-19: Imports are not sorted alphabetically and Behat/Doctrine imports are interleaved.

The four import statements are in a jumbled order. They should be sorted lexicographically.

Proposed fix
-use Behat\Step\When;
-use Doctrine\DBAL\DBALException;
-use Behat\Step\Then;
 use Behat\Behat\Context\Context;
+use Behat\Step\Then;
+use Behat\Step\When;
+use Doctrine\DBAL\DBALException;

As per coding guidelines: "Sort PHP use imports alphabetically and group by type (classes, functions, constants)".

@loic425 loic425 force-pushed the behat-annotations-to-attributes/domain branch from 8ca5186 to 0921823 Compare February 11, 2026 08:49
$this->productVariantRepository->remove($productVariant);
/** @phpstan-ignore-next-line */
} catch (\Doctrine\DBAL\DBALException|\Doctrine\DBAL\Exception $exception) {
} catch (DBALException $exception) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\Doctrine\DBAL\DBALException does not exist anymore in minimal doctrine requirements we have now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants