Convert Behat annotations to PHP attributes in Setup contexts#18816
Convert Behat annotations to PHP attributes in Setup contexts#18816TheMilek merged 1 commit intoSylius:2.3from
Conversation
📝 WalkthroughWalkthroughThis pull request systematically migrates Behat step definitions across 32 Setup Context files from PHPDoc annotations ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Large-scale systematic refactoring affecting 32 files with consistent, homogeneous pattern changes (PHPDoc to attributes migration). While the pattern is repetitive and reduces per-file cognitive load, the sheer number of files, combined with the OrderContext parameter addition and minor logic adjustments in a few files, requires careful verification of annotation correctness and consistency across the codebase. Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
❌ Preview Environment deleted from BunnyshellAvailable commands:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/Sylius/Behat/Context/Setup/GeographicalContext.php`:
- Around line 53-58: The two legacy `@Given` patterns for the GeographicalContext
method theStoreOperatesIn were not converted to attributes and must be added as
#[Given(...)] above that method; update the method declaration in class
GeographicalContext to include attribute variants for the multi-country pattern
'/^the store operates in "([^"]*)" and "([^"]*)"$/', and for the single-country
/ also pattern '/^the store(?:| also) has country "([^"]*)"$/', so the method
theStoreOperatesIn(string ...$countriesNames): void is annotated with all three
#[Given(...)] attributes matching the original step patterns.
🧹 Nitpick comments (6)
src/Sylius/Behat/Context/Setup/PriceHistoryContext.php (1)
16-17: Imports are not sorted alphabetically.
Behat\Behat\Context\Contextshould precedeBehat\Step\Givenlexicographically. This same ordering issue appears in several other files in this PR (AdminSecurityContext,CartContext,PaymentRequestContext,AddressContext).Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/AdminSecurityContext.php (1)
16-17: Imports not sorted alphabetically — same issue as noted inPriceHistoryContext.php.Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/CartContext.php (1)
16-18: Imports not sorted alphabetically — same issue as noted in other files.Proposed fix
-use Behat\Step\When; use Behat\Behat\Context\Context; use Behat\Step\Given; +use Behat\Step\When;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/PaymentRequestContext.php (1)
16-17: Imports not sorted alphabetically — same issue as noted in other files.Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/AddressContext.php (1)
16-17: Imports not sorted alphabetically — same issue as noted in other files.Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/ChannelContext.php (1)
254-259: Stale/malformed docblock annotation left behind.Line 255 contains
@Whencustomer view shop on :channel channelwhich appears to be a leftover annotation from the migration. Since this PR converts all Behat annotations to PHP 8 attributes, this residual docblock should be cleaned up. It was never a functional annotation (@Whenis concatenated withcustomer), but it should still be removed for consistency.Suggested fix
- /** - * `@Whencustomer` view shop on :channel channel - */ #[Given('/^I changed my current (channel to "([^"]+)")$/')] #[Given('I am in the :channel channel')] #[When('/^I change (?:|back )my current (channel to "([^"]+)")$/')]
1ae7898 to
65ed4f1
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/Sylius/Behat/Context/Setup/ChannelContext.php`:
- Around line 254-259: Remove the stale/malformed docblock line containing
"@Whencustomer view shop on :channel channel" above the channel-switching method
in ChannelContext; the method already uses PHP 8 attributes (the Given/When
attributes shown) so delete that dead docblock entry to avoid confusion and keep
only the attribute-driven annotations for the channel-related method in
ChannelContext.
In `@src/Sylius/Behat/Context/Setup/ZoneContext.php`:
- Line 83: The turnip step pattern on the Given attribute in ZoneContext uses
the optional group with the space outside (`'the store has (also) a zone
:zoneName'`) which leaves a double space when "also" is absent; update the Given
attribute on the ZoneContext step (the attribute currently showing `'the store
has (also) a zone :zoneName'`) so the leading space is inside the optional group
(e.g. `'the store has( also) a zone :zoneName'`) to ensure both variants match
correctly.
🧹 Nitpick comments (5)
src/Sylius/Behat/Context/Setup/PriceHistoryContext.php (1)
16-17: Imports are not in alphabetical order.
Behat\Behat\Context\Contextshould come beforeBehat\Step\Givento satisfy alphabetical ordering.🔤 Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/CatalogPromotionContext.php (1)
16-18: Imports are not in alphabetical order.The
Behat\Step\*imports should followBehat\Behat\Context\Contextalphabetically.🔤 Proposed fix
-use Behat\Step\When; use Behat\Behat\Context\Context; use Behat\Step\Given; +use Behat\Step\When;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/AdminUserContext.php (1)
16-18: Imports are not in alphabetical order.Same pattern as the other files —
Behat\Behat\Context\Contextshould precedeBehat\Step\*.🔤 Proposed fix
-use Behat\Step\Given; -use Behat\Step\When; use Behat\Behat\Context\Context; +use Behat\Step\Given; +use Behat\Step\When;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/TaxationContext.php (1)
16-17: Imports are not in alphabetical order.🔤 Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/ProductAttributeContext.php (1)
16-18: Imports are not in alphabetical order.🔤 Proposed fix
-use Behat\Step\Given; -use Behat\Step\When; use Behat\Behat\Context\Context; +use Behat\Step\Given; +use Behat\Step\When;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".
| * @Given the store also has a zone :zoneName with code :code | ||
| * @Given the store has a zone :zoneName with code :code and priority :priority | ||
| */ | ||
| #[Given('the store has (also) a zone :zoneName')] |
There was a problem hiding this comment.
Incorrect optional-group spacing in turnip pattern — will fail to match the non-"also" variant.
The pattern 'the store has (also) a zone :zoneName' leaves a double space when the optional (also) is absent, producing the store has⎵⎵a zone. The leading space should be inside the parentheses so it is omitted together with the word.
Compare with ProductAttributeContext.php Line 56 which correctly uses 'the store has( also) a :type product attribute ...'.
🐛 Proposed fix
- #[Given('the store has (also) a zone :zoneName')]
+ #[Given('the store has( also) a zone :zoneName')]📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| #[Given('the store has (also) a zone :zoneName')] | |
| #[Given('the store has( also) a zone :zoneName')] |
🤖 Prompt for AI Agents
In `@src/Sylius/Behat/Context/Setup/ZoneContext.php` at line 83, The turnip step
pattern on the Given attribute in ZoneContext uses the optional group with the
space outside (`'the store has (also) a zone :zoneName'`) which leaves a double
space when "also" is absent; update the Given attribute on the ZoneContext step
(the attribute currently showing `'the store has (also) a zone :zoneName'`) so
the leading space is inside the optional group (e.g. `'the store has( also) a
zone :zoneName'`) to ensure both variants match correctly.
65ed4f1 to
78e2e04
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/Sylius/Behat/Context/Setup/OrderContext.php`:
- Around line 16-18: The import ordering is incorrect: move the use statement
for Behat\Step\When so imports are alphabetized and grouped by type — place
Behat\Step\Given before Behat\Step\When and ensure Behat\Behat\Context\Context
sits in the correct alphabetical position among class imports; adjust the three
use lines (Behat\Step\When, Behat\Behat\Context\Context, Behat\Step\Given) so
they are sorted alphabetically to match the project's import ordering rules.
In `@src/Sylius/Behat/Context/Setup/ProductAssociationContext.php`:
- Line 16: Imports in ProductAssociationContext are out of alphabetical order:
place the Behat\Behat\Context\Context import before Behat\Step\Given; update the
import block in the ProductAssociationContext class accordingly and apply the
same fix to other Setup context files mentioned (CurrencyContext, ThemeContext,
TaxationContext) so that "Behat\Behat\Context\Context" precedes
"Behat\Step\Given" in each file's use statements.
🧹 Nitpick comments (12)
src/Sylius/Behat/Context/Setup/CustomerGroupContext.php (1)
16-17: Imports are not in alphabetical order.
Behat\Behat\Context\Contextshould precedeBehat\Step\Givenalphabetically.Suggested fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/PaymentRequestContext.php (1)
16-17: Import statements are not sorted alphabetically.
Behat\Behat\Context\Contextshould precedeBehat\Step\Givenalphabetically.Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/ProductReviewContext.php (1)
16-17: Imports are not sorted alphabetically.
Behat\Behat\Context\Contextshould precedeBehat\Step\Given.Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/CustomerContext.php (1)
16-17: Import order:Behat\Step\Givenshould come afterBehat\Behat\Context\Context.As per coding guidelines,
useimports should be sorted alphabetically.Behat\Behat\...comes beforeBehat\Step\....Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given; use Doctrine\Persistence\ObjectManager;src/Sylius/Behat/Context/Setup/ProductTaxonContext.php (1)
16-17: Imports are not sorted alphabetically.
Behat\Behat\Context\Contextshould come beforeBehat\Step\Given.Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/TaxationContext.php (1)
16-17: ImportBehat\Step\Givenshould come afterBehat\Behat\Context\Contextfor alphabetical ordering.As per coding guidelines,
useimports should be sorted alphabetically.Behat\Behat\Context\Contextsorts beforeBehat\Step\Given.Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given; use Doctrine\Persistence\ObjectManager;src/Sylius/Behat/Context/Setup/CatalogPromotionContext.php (1)
16-18: Import order:Behat\Step\Whenshould come afterBehat\Step\Given.The newly added
Whenimport was placed beforeBehat\Behat\Context\Context, breaking alphabetical order.Proposed fix
-use Behat\Step\When; use Behat\Behat\Context\Context; use Behat\Step\Given; +use Behat\Step\When;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/ChannelContext.php (1)
16-18: ImportBehat\Step\Whenis placed out of alphabetical order.
Behat\Step\When(line 16) should come afterBehat\Behat\Context\ContextandBehat\Step\Givento maintain alphabetical sorting per project conventions.Proposed fix
-use Behat\Step\When; use Behat\Behat\Context\Context; use Behat\Step\Given; +use Behat\Step\When;src/Sylius/Behat/Context/Setup/AdminSecurityContext.php (1)
16-17: Import order:Behat\Step\Givenshould come afterBehat\Behat\Context\Context.Alphabetically,
Behat\BehatprecedesBehat\Step.Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given;As per coding guidelines, "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/AddressContext.php (1)
16-17: Same import ordering issue:Behat\Step\Givenshould followBehat\Behat\Context\Context.Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given;As per coding guidelines, "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/CurrencyContext.php (1)
16-17: Same import ordering issue as in the other files.Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given;As per coding guidelines, "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".src/Sylius/Behat/Context/Setup/UserContext.php (1)
16-17: Import is out of alphabetical order.
Behat\Behat\Context\Contextshould come beforeBehat\Step\Givento maintain alphabetical sorting.Proposed fix
-use Behat\Step\Given; use Behat\Behat\Context\Context; +use Behat\Step\Given;As per coding guidelines: "Sort PHP
useimports alphabetically and group by type (classes, functions, constants)".
| use Behat\Step\When; | ||
| use Behat\Behat\Context\Context; | ||
| use Behat\Step\Given; |
There was a problem hiding this comment.
Import When is out of alphabetical order.
Behat\Step\When should be placed after Behat\Step\Given (line 18), not before Behat\Behat\Context\Context.
Proposed fix
-use Behat\Step\When;
use Behat\Behat\Context\Context;
use Behat\Step\Given;
+use Behat\Step\When;As per coding guidelines: "Sort PHP use imports alphabetically and group by type (classes, functions, constants)".
🤖 Prompt for AI Agents
In `@src/Sylius/Behat/Context/Setup/OrderContext.php` around lines 16 - 18, The
import ordering is incorrect: move the use statement for Behat\Step\When so
imports are alphabetized and grouped by type — place Behat\Step\Given before
Behat\Step\When and ensure Behat\Behat\Context\Context sits in the correct
alphabetical position among class imports; adjust the three use lines
(Behat\Step\When, Behat\Behat\Context\Context, Behat\Step\Given) so they are
sorted alphabetically to match the project's import ordering rules.
There was a problem hiding this comment.
Yep, indeed, but with the amount of files, I prefer to wait for the github job for the linter execution.
There was a problem hiding this comment.
@loic425, that sounds like a good approach! With the number of files being updated in this PR, letting the automated linter handle the import ordering across all of them will be more efficient and consistent. The CI job should catch and fix these ordering issues uniformly. 👍
🧠 Learnings used
Learnt from: CR
Repo: Sylius/Sylius PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-23T14:27:12.477Z
Learning: Applies to src/Sylius/Behat/Context/**/*Context.php : Behat context files should be placed in `src/Sylius/Behat/Context/` directory
Learnt from: CR
Repo: Sylius/Sylius PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-23T14:27:12.477Z
Learning: Applies to features/**/*.feature : Follow Given-When-Then pattern strictly in Behat scenarios
Learnt from: CR
Repo: Sylius/Sylius PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-23T14:27:12.477Z
Learning: Applies to **/*.php : Sort PHP `use` imports alphabetically and group by type (classes, functions, constants)
|
|
||
| namespace Sylius\Behat\Context\Setup; | ||
|
|
||
| use Behat\Step\Given; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
cat -n src/Sylius/Behat/Context/Setup/ProductAssociationContext.php | sed -n '1,25p'Repository: Sylius/Sylius
Length of output: 1063
🏁 Script executed:
# Check for other instances of the same pattern
rg -n 'use Behat\\Step\\' --type=php -B2 -A2 src/Sylius/Behat/Context/ | head -100Repository: Sylius/Sylius
Length of output: 7512
Sort imports alphabetically: Behat\Behat\Context\Context should precede Behat\Step\Given.
Lines 16–17 violate alphabetical ordering. Since Behat\Behat... comes before Behat\Step... alphabetically, Behat\Behat\Context\Context must be placed first.
This pattern appears across multiple Setup context files in this PR (CurrencyContext, ThemeContext, TaxationContext). Consider fixing all instances.
Proposed fix
-use Behat\Step\Given;
use Behat\Behat\Context\Context;
+use Behat\Step\Given;
use Doctrine\Persistence\ObjectManager;🤖 Prompt for AI Agents
In `@src/Sylius/Behat/Context/Setup/ProductAssociationContext.php` at line 16,
Imports in ProductAssociationContext are out of alphabetical order: place the
Behat\Behat\Context\Context import before Behat\Step\Given; update the import
block in the ProductAssociationContext class accordingly and apply the same fix
to other Setup context files mentioned (CurrencyContext, ThemeContext,
TaxationContext) so that "Behat\Behat\Context\Context" precedes
"Behat\Step\Given" in each file's use statements.
Summary by CodeRabbit