Skip to content

Convert Behat annotations to PHP attributes in Api Shop contexts#18826

Merged
TheMilek merged 1 commit intoSylius:2.3from
loic425:behat-annotations-to-attributes/api-shop
Feb 17, 2026
Merged

Convert Behat annotations to PHP attributes in Api Shop contexts#18826
TheMilek merged 1 commit intoSylius:2.3from
loic425:behat-annotations-to-attributes/api-shop

Conversation

@loic425
Copy link
Copy Markdown
Member

@loic425 loic425 commented Feb 13, 2026

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

Summary by CodeRabbit

  • Refactor

    • Migrated test step declarations to PHP 8 attribute syntax for consistency and clearer test mapping.
  • Tests

    • Updated numerous API test scenarios (addresses, cart, checkout, auth, registration, products, etc.) to use the new step wiring and adjusted flows where needed.
  • Bug Fix

    • Fixed default-address handling so marking an address as default correctly updates the customer record.

@loic425 loic425 requested review from a team as code owners February 13, 2026 10:24
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

Migrates Behat step declarations in ~20 Shop API context classes from PHPDoc annotations to PHP 8 attributes (#[Given]/#[When]/#[Then]). Preserves method signatures and most control flow; notable behavioral edits in AddressContext (default-address update), ProductVariantContext (immediate filter call), LoginContext and RegistrationContext flows.

Changes

Cohort / File(s) Summary
Address (default-address change)
src/Sylius/Behat/Context/Api/Shop/AddressContext.php
Replaced docblock steps with PHP 8 attributes; changed default-address flow to PATCH the customer resource with defaultAddress set to the address IRI.
Checkout & Cart
src/Sylius/Behat/Context/Api/Shop/CartContext.php, src/Sylius/Behat/Context/Api/Shop/Checkout/*, src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php, src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutCompleteContext.php, src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php
Migrated many step definitions from docblock annotations to PHP 8 attributes; added Behat step imports; one new public step added in CheckoutContext.
Login & Registration
src/Sylius/Behat/Context/Api/Shop/LoginContext.php, src/Sylius/Behat/Context/Api/Shop/RegistrationContext.php
Attribute-based step migration; adjusted password-reset, login, and email verification flows (token handling and explicit request paths) while preserving signatures.
Products & Variants
src/Sylius/Behat/Context/Api/Shop/ProductContext.php, src/Sylius/Behat/Context/Api/Shop/ProductVariantContext.php, src/Sylius/Behat/Context/Api/Shop/ProductAttributeContext.php, src/Sylius/Behat/Context/Api/Shop/ProductReviewContext.php
Converted docblock steps to attributes; ProductVariantContext now triggers filter() immediately in iFilterVariantsByOption and stores results.
Orders, Payments, Shipments
src/Sylius/Behat/Context/Api/Shop/OrderContext.php, src/Sylius/Behat/Context/Api/Shop/OrderItemContext.php, src/Sylius/Behat/Context/Api/Shop/PaymentContext.php, src/Sylius/Behat/Context/Api/Shop/PaymentRequestContext.php, src/Sylius/Behat/Context/Api/Shop/ShipmentContext.php
Docblock → attribute migration for numerous steps; added Behat step imports; no signature changes.
Customer / Contact / Promotion / Currency / Exchange / Locale / Homepage / Taxon
src/Sylius/Behat/Context/Api/Shop/CustomerContext.php, src/Sylius/Behat/Context/Api/Shop/ContactContext.php, src/Sylius/Behat/Context/Api/Shop/PromotionContext.php, src/Sylius/Behat/Context/Api/Shop/CurrencyContext.php, src/Sylius/Behat/Context/Api/Shop/ExchangeRateContext.php, src/Sylius/Behat/Context/Api/Shop/LocaleContext.php, src/Sylius/Behat/Context/Api/Shop/HomepageContext.php, src/Sylius/Behat/Context/Api/Shop/TaxonContext.php
Replaced PHPDoc step annotations with PHP 8 attributes and added required imports; LocaleContext contains minor assertion adjustments; otherwise behavioral parity retained.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related PRs

Suggested labels

DX, API

Suggested reviewers

  • Rafikooo

Poem

🐰 I hopped through docblocks, nibbling old lines,
Replaced them with attributes—neat little signs.
Steps now wear badges of PHP eight,
Test-bunnies clap—this feels first-rate! 🥕✨

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.19% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the pull request: converting Behat annotations to PHP attributes across multiple Api Shop context files.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into 2.3

✏️ 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

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 13, 2026

❗ Preview Environment delete from Bunnyshell failed

Check https://github.com/Sylius/Sylius/actions/runs/22101627609 for details.

See: Environment Details

Available commands:

  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

@loic425 loic425 mentioned this pull request Feb 13, 2026
27 tasks
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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/Sylius/Behat/Context/Api/Shop/AddressContext.php (1)

122-130: ⚠️ Potential issue | 🟡 Minor

The behavioral change is intentional and tested.

This method correctly uses Resources::CUSTOMERS with the defaultAddress field to set the default address, which is consistent with how the same data is read in addressShouldBeMarkedAsMyDefaultAddress() (line 271) and iShouldHaveNoDefaultAddress() (line 323). The feature file setting_default_address.feature contains scenarios that exercise this step.

However, the import ordering on lines 16-19 violates the coding guidelines. Imports should be sorted alphabetically; currently Behat\Step\Given, Behat\Step\When, and Behat\Step\Then appear before Behat\Behat\Context\Context, which should come first alphabetically.

src/Sylius/Behat/Context/Api/Shop/ProductContext.php (1)

375-383: ⚠️ Potential issue | 🟡 Minor

Change #[When] to #[Then] on line 375.

The step I should see only (\d+) product(s) is an assertion step that matches the semantic pattern of other "I should see" steps in this file (all marked #[Then]). The method contains only assertions and no actions, confirming it should use the #[Then] attribute.

Fix
-    #[When('/^I should see only (\d+) product(s)$/')]
+    #[Then('/^I should see only (\d+) product(s)$/')]
🤖 Fix all issues with AI agents
In `@src/Sylius/Behat/Context/Api/Shop/AddressContext.php`:
- Around line 313-318: The step handler iShouldStillHaveAsMySpecifiedProvince
currently only checks that the update failed but ignores the $provinceName
parameter; update it to first assert the update was unsuccessful (keep
Assert::false($this->responseChecker->isUpdateSuccessful($this->client->getLastResponse()))),
then fetch the current address representation (e.g. obtain the response content
for the address resource from $this->client->getLastResponse() or re-fetch the
address via the shop API) and assert that the province field/value in that
representation equals $provinceName (use the existing responseChecker helpers or
Assert::same/equals to compare the province value to $provinceName) so the step
verifies the actual province remains unchanged.

In `@src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php`:
- Around line 1110-1114: The step definition attribute on method
iShouldSeeWithUnitPrice is incorrect: change the attribute from #[When('/^I
should see (product "[^"]+") with unit price ("[^"]+")$/')] to #[Then(...)] so
the assertion step is bound as a Then step; update the attribute on the
iShouldSeeWithUnitPrice(ProductInterface $product, int $unitPrice): void method
in CheckoutContext to use #[Then] with the same regex pattern (no other code
changes needed).

In `@src/Sylius/Behat/Context/Api/Shop/HomepageContext.php`:
- Around line 16-19: Reorder the PHP use statements so imports are alphabetized
and grouped by type: move ApiPlatform\Metadata\IriConverterInterface before
Behat\Step\Then and Behat\Step\When, and ensure Then comes before When; keep
Behat\Behat\Context\Context in the correct group as well. Adjust the import
block containing Context, IriConverterInterface, Then, and When to follow
alphabetical order (Context, IriConverterInterface, Then, When) so the use list
in HomepageContext.php complies with the project's import-sorting rules.
🧹 Nitpick comments (10)
src/Sylius/Behat/Context/Api/Shop/CurrencyContext.php (1)

16-17: Imports are not sorted alphabetically.

Then should come before When to comply with the alphabetical ordering convention.

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

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

src/Sylius/Behat/Context/Api/Shop/ShipmentContext.php (1)

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

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

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

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

src/Sylius/Behat/Context/Api/Shop/ProductAttributeContext.php (1)

16-17: Import order: Behat\Step\Then should come after Behat\Behat\Context\Context.

Behat\Behat\… sorts before Behat\Step\… alphabetically.

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/Api/Shop/OrderItemContext.php (1)

16-17: Imports are not sorted alphabetically.

Behat\Step\Then should come before Behat\Step\When. Additionally, these should be grouped with the other Behat\ import on line 18 for consistent ordering. As per coding guidelines, use imports should be sorted alphabetically and grouped by type.

Proposed fix
-use Behat\Step\When;
-use Behat\Step\Then;
 use Behat\Behat\Context\Context;
+use Behat\Step\Then;
+use Behat\Step\When;
src/Sylius/Behat/Context/Api/Shop/ProductReviewContext.php (1)

16-17: Imports are not sorted alphabetically.

Behat\Step\When and Behat\Step\Then are placed before ApiPlatform\Metadata\IriConverterInterface and are themselves in the wrong relative order (When before Then). As per coding guidelines, use imports should be sorted alphabetically.

Proposed fix
-use Behat\Step\When;
-use Behat\Step\Then;
 use ApiPlatform\Metadata\IriConverterInterface;
 use Behat\Behat\Context\Context;
+use Behat\Step\Then;
+use Behat\Step\When;
 use Sylius\Behat\Client\ApiClientInterface;
src/Sylius/Behat/Context/Api/Shop/PaymentRequestContext.php (1)

16-18: Reorder use statements alphabetically.

The newly added use statements should be sorted alphabetically. Currently, Behat\Step\When and Behat\Step\Then appear before Behat\Behat\Context\Context, but alphabetically Behat\Behat\... should come first. Additionally, Then should precede When. As per coding guidelines, use imports must be sorted alphabetically.

♻️ Proposed fix to reorder use statements
-use Behat\Step\When;
-use Behat\Step\Then;
 use Behat\Behat\Context\Context;
+use Behat\Step\Then;
+use Behat\Step\When;
src/Sylius/Behat/Context/Api/Shop/LoginContext.php (1)

166-168: Consider adding missing : void return type on iLogOut.

While the attribute conversion on lines 166–167 is correct, the method on line 168 is missing a : void return type declaration. This is pre-existing but worth addressing in this cleanup pass. As per coding guidelines, "Add type declarations for all properties, arguments, and return values in PHP code."

Suggested fix
     #[When('I log out')]
     #[When('the customer logged out')]
-    public function iLogOut()
+    public function iLogOut(): void
     {
src/Sylius/Behat/Context/Api/Shop/CustomerContext.php (1)

16-18: Imports are not sorted alphabetically.

Behat\Behat\Context\Context should come before Behat\Step\*, and Behat\Step\Then before Behat\Step\When. This ordering issue is consistent across all files in this PR.

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

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

src/Sylius/Behat/Context/Api/Shop/TaxonContext.php (1)

16-19: Imports are not sorted alphabetically.

ApiPlatform\Metadata\IriConverterInterface (line 18) should precede all Behat\* imports, and Behat\Behat\Context\Context should come before Behat\Step\*.

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

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

src/Sylius/Behat/Context/Api/Shop/OrderContext.php (1)

16-17: Imports are not sorted alphabetically.

Behat\Step\When and Behat\Step\Then are placed before ApiPlatform\Metadata\IriConverterInterface, violating the alphabetical import ordering. This same pattern repeats across all files in this PR.

Suggested fix
-use Behat\Step\When;
-use Behat\Step\Then;
 use ApiPlatform\Metadata\IriConverterInterface;
 use Behat\Behat\Context\Context;
+use Behat\Step\Then;
+use Behat\Step\When;

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

Comment on lines +313 to 318
#[Then('I should still have :provinceName as my specified province')]
#[Then('I should still have :provinceName as my chosen province')]
public function iShouldStillHaveAsMySpecifiedProvince(string $provinceName): void
{
Assert::false($this->responseChecker->isUpdateSuccessful($this->client->getLastResponse()));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

$provinceName parameter is not used in the assertion.

The static analysis hint is valid here. The method checks that the update was unsuccessful but never verifies the province name matches $provinceName. This means the step I should still have :provinceName as my specified province would pass regardless of the actual province value, as long as the last request failed. This is likely a pre-existing issue.

🧰 Tools
🪛 PHPMD (2.15.0)

[warning] 315-315: Avoid unused parameters such as '$provinceName'. (undefined)

(UnusedFormalParameter)

🤖 Prompt for AI Agents
In `@src/Sylius/Behat/Context/Api/Shop/AddressContext.php` around lines 313 - 318,
The step handler iShouldStillHaveAsMySpecifiedProvince currently only checks
that the update failed but ignores the $provinceName parameter; update it to
first assert the update was unsuccessful (keep
Assert::false($this->responseChecker->isUpdateSuccessful($this->client->getLastResponse()))),
then fetch the current address representation (e.g. obtain the response content
for the address resource from $this->client->getLastResponse() or re-fetch the
address via the shop API) and assert that the province field/value in that
representation equals $provinceName (use the existing responseChecker helpers or
Assert::same/equals to compare the province value to $provinceName) so the step
verifies the actual province remains unchanged.

Comment on lines +1110 to 1114
#[When('/^I should see (product "[^"]+") with unit price ("[^"]+")$/')]
public function iShouldSeeWithUnitPrice(ProductInterface $product, int $unitPrice): void
{
Assert::true($this->hasProductWithUnitPrice($product->getName(), $unitPrice));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

rg -n "should see product .* with unit price" --type-add 'feature:*.feature' --type feature -C1

Repository: Sylius/Sylius

Length of output: 442


Change #[When] to #[Then] for assertion step.

The step "I should see product ... with unit price ..." is semantically an assertion and is used in feature files following a Then keyword (as And I should see...). It should be bound with the #[Then] attribute.

Suggested fix
-    #[When('/^I should see (product "[^"]+") with unit price ("[^"]+")$/')]
+    #[Then('/^I should see (product "[^"]+") with unit price ("[^"]+")$/')]
🤖 Prompt for AI Agents
In `@src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php` around lines 1110 -
1114, The step definition attribute on method iShouldSeeWithUnitPrice is
incorrect: change the attribute from #[When('/^I should see (product "[^"]+")
with unit price ("[^"]+")$/')] to #[Then(...)] so the assertion step is bound as
a Then step; update the attribute on the
iShouldSeeWithUnitPrice(ProductInterface $product, int $unitPrice): void method
in CheckoutContext to use #[Then] with the same regex pattern (no other code
changes needed).

Comment on lines +16 to 19
use Behat\Step\When;
use Behat\Step\Then;
use ApiPlatform\Metadata\IriConverterInterface;
use Behat\Behat\Context\Context;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Import statements are not sorted alphabetically.

The new Behat\Step\* imports are placed before the ApiPlatform\* import, violating alphabetical ordering. Additionally, When is listed before Then.

Proposed fix
-use Behat\Step\When;
-use Behat\Step\Then;
 use ApiPlatform\Metadata\IriConverterInterface;
 use Behat\Behat\Context\Context;
+use Behat\Step\Then;
+use Behat\Step\When;
 use Doctrine\Persistence\ObjectManager;

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

📝 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.

Suggested change
use Behat\Step\When;
use Behat\Step\Then;
use ApiPlatform\Metadata\IriConverterInterface;
use Behat\Behat\Context\Context;
use ApiPlatform\Metadata\IriConverterInterface;
use Behat\Behat\Context\Context;
use Behat\Step\Then;
use Behat\Step\When;
🤖 Prompt for AI Agents
In `@src/Sylius/Behat/Context/Api/Shop/HomepageContext.php` around lines 16 - 19,
Reorder the PHP use statements so imports are alphabetized and grouped by type:
move ApiPlatform\Metadata\IriConverterInterface before Behat\Step\Then and
Behat\Step\When, and ensure Then comes before When; keep
Behat\Behat\Context\Context in the correct group as well. Adjust the import
block containing Context, IriConverterInterface, Then, and When to follow
alphabetical order (Context, IriConverterInterface, Then, When) so the use list
in HomepageContext.php complies with the project's import-sorting rules.

@Rafikooo
Copy link
Copy Markdown
Contributor

Please rebase the PR, should be green now

@loic425 loic425 force-pushed the behat-annotations-to-attributes/api-shop branch from 293872d to 6ec7d0a Compare February 13, 2026 11:16
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Sylius/Behat/Context/Api/Shop/ProductVariantContext.php (1)

72-79: ⚠️ Potential issue | 🔴 Critical

Behavioral change: iFilterVariantsByOption now immediately executes the filter request.

This method previously only configured the filter via addFilter(). Now it also calls $this->client->filter() and stores the result in shared storage. This is a functional change beyond the annotation-to-attribute migration scope of this PR.

A scenario in features/shop/product/show/options/viewing_diagonal_variant_options.feature (lines 37-38) chains multiple filter steps before an assertion:

And I filter them by "Blue" option value
And I filter them by "Small" option value
Then I should not see any variants

This scenario expects both filters to be accumulated and applied together. With the new behavior, each call executes filter() independently, overwriting the shared storage result and breaking the intended multi-filter behavior. This must be reverted to the previous pattern of only calling addFilter(), allowing another step to trigger the actual filter request.

🤖 Fix all issues with AI agents
In `@src/Sylius/Behat/Context/Api/Shop/LoginContext.php`:
- Around line 166-171: The method iLogOut() in class LoginContext is missing a
return type declaration; update the method signature for public function
iLogOut() to include the void return type (i.e. public function iLogOut(): void)
to match other methods in the class and satisfy the coding guideline requiring
return type declarations; ensure any callers/tests remain compatible and run
unit/Behat tests after the change.

In `@src/Sylius/Behat/Context/Api/Shop/ProductContext.php`:
- Around line 375-376: The step definition attribute on iShouldSeeOnlyProducts
is incorrectly marked as #[When] but it is an assertion and should be #[Then];
update the attribute on the iShouldSeeOnlyProducts method to use #[Then('/^I
should see only (\d+) product(s)$/')] so the step follows the Given-When-Then
convention and is recognized as a verification step by Behat.
🧹 Nitpick comments (13)
src/Sylius/Behat/Context/Api/Shop/CurrencyContext.php (1)

16-18: Imports are not sorted alphabetically.

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

Proposed fix
-use Behat\Step\When;
-use Behat\Step\Then;
 use Behat\Behat\Context\Context;
+use Behat\Step\Then;
+use Behat\Step\When;
src/Sylius/Behat/Context/Api/Shop/ExchangeRateContext.php (1)

16-17: Imports are not sorted alphabetically.

Behat\Step\Then should come before Behat\Step\When.

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

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

src/Sylius/Behat/Context/Api/Shop/ShipmentContext.php (1)

16-17: Imports are not sorted alphabetically.

Behat\Step\Then should come before Behat\Step\When.

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

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

src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutOrderDetailsContext.php (1)

16-17: Import order: Then should come before When alphabetically.

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

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

src/Sylius/Behat/Context/Api/Shop/LocaleContext.php (1)

16-18: Imports are not sorted alphabetically.

Behat\Behat\Context\Context should come before the Behat\Step\* imports. As per coding guidelines: "Sort PHP use imports alphabetically and group by type."

Proposed fix
-use Behat\Step\When;
-use Behat\Step\Then;
 use Behat\Behat\Context\Context;
+use Behat\Step\Then;
+use Behat\Step\When;
src/Sylius/Behat/Context/Api/Shop/Checkout/CheckoutCompleteContext.php (1)

16-19: Imports are not sorted alphabetically.

The newly added Behat\Step\Given and Behat\Step\Then were inserted above Behat\Behat\Context\Context, breaking alphabetical order.

Suggested fix
-use Behat\Step\Given;
-use Behat\Step\Then;
 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 (classes, functions, constants)".

src/Sylius/Behat/Context/Api/Shop/CustomerContext.php (1)

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

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

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

src/Sylius/Behat/Context/Api/Shop/ProductReviewContext.php (1)

16-17: Import order for new use statements.

The new Behat\Step\When and Behat\Step\Then imports are placed before the ApiPlatform namespace and Then comes after When. Alphabetically, ApiPlatform < Behat, and Then < When. Consider reordering:

-use Behat\Step\When;
-use Behat\Step\Then;
 use ApiPlatform\Metadata\IriConverterInterface;
+use Behat\Step\Then;
+use Behat\Step\When;

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

src/Sylius/Behat/Context/Api/Shop/LoginContext.php (1)

16-18: Imports are not sorted alphabetically.

Behat\Step\* imports should be ordered Given, Then, When and placed after the ApiPlatform\Metadata\IriConverterInterface import to maintain overall alphabetical order.

Suggested fix
-use Behat\Step\Given;
-use Behat\Step\When;
-use Behat\Step\Then;
 use ApiPlatform\Metadata\IriConverterInterface;
+use Behat\Step\Given;
+use Behat\Step\Then;
+use Behat\Step\When;
 use Behat\Behat\Context\Context;

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

src/Sylius/Behat/Context/Api/Shop/ProductContext.php (1)

16-17: Import order: Behat\Step\Then and Behat\Step\When are not sorted alphabetically between themselves.

Then should appear before When alphabetically.

Proposed fix
-use Behat\Step\When;
-use Behat\Step\Then;
+use Behat\Step\Then;
+use Behat\Step\When;
src/Sylius/Behat/Context/Api/Shop/ProductVariantContext.php (1)

16-18: Import order: Behat\Step\* imports should follow ApiPlatform\* alphabetically.

Per the coding guideline to sort use imports alphabetically, ApiPlatform\Metadata\IriConverterInterface should precede the Behat\Step\* imports. Also, Then should come before When.

Suggested reorder
-use Behat\Step\When;
-use Behat\Step\Then;
 use ApiPlatform\Metadata\IriConverterInterface;
 use Behat\Behat\Context\Context;
+use Behat\Step\Then;
+use Behat\Step\When;

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

src/Sylius/Behat/Context/Api/Shop/AddressContext.php (2)

16-18: Imports are not sorted alphabetically.

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

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

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


307-311: $fullName parameter is unused (PHPMD warning).

This is an intentionally empty method (API context no-op for a UI step), which is a common pattern in this codebase. Consider adding a /** @phpmd-suppress UnusedFormalParameter */ or similar suppression to silence the static analysis warning explicitly.

Comment on lines +166 to 171
#[When('I log out')]
#[When('the customer logged out')]
public function iLogOut()
{
$this->apiSecurityClient->logOut();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Missing return type declaration on iLogOut().

This method lacks the : void return type, unlike every other method in the class.

Suggested fix
-    public function iLogOut()
+    public function iLogOut(): void

As per coding guidelines: "Add type declarations for all properties, arguments, and return values in PHP code".

🤖 Prompt for AI Agents
In `@src/Sylius/Behat/Context/Api/Shop/LoginContext.php` around lines 166 - 171,
The method iLogOut() in class LoginContext is missing a return type declaration;
update the method signature for public function iLogOut() to include the void
return type (i.e. public function iLogOut(): void) to match other methods in the
class and satisfy the coding guideline requiring return type declarations;
ensure any callers/tests remain compatible and run unit/Behat tests after the
change.

Comment on lines +375 to 376
#[When('/^I should see only (\d+) product(s)$/')]
public function iShouldSeeOnlyProducts(int $count): void
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

#[When] should be #[Then] — this is an assertion step.

"I should see only N products" is a verification/assertion, which follows the Then convention in Given-When-Then. This should use #[Then] instead of #[When].

Proposed fix
-    #[When('/^I should see only (\d+) product(s)$/')]
+    #[Then('/^I should see only (\d+) product(s)$/')]

Based on learnings: "Follow Given-When-Then pattern strictly in Behat scenarios."

📝 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.

Suggested change
#[When('/^I should see only (\d+) product(s)$/')]
public function iShouldSeeOnlyProducts(int $count): void
#[Then('/^I should see only (\d+) product(s)$/')]
public function iShouldSeeOnlyProducts(int $count): void
🤖 Prompt for AI Agents
In `@src/Sylius/Behat/Context/Api/Shop/ProductContext.php` around lines 375 - 376,
The step definition attribute on iShouldSeeOnlyProducts is incorrectly marked as
#[When] but it is an assertion and should be #[Then]; update the attribute on
the iShouldSeeOnlyProducts method to use #[Then('/^I should see only (\d+)
product(s)$/')] so the step follows the Given-When-Then convention and is
recognized as a verification step by Behat.

@loic425
Copy link
Copy Markdown
Member Author

loic425 commented Feb 13, 2026

@Rafikooo Done, CI is green.

@TheMilek TheMilek merged commit a8fcc86 into Sylius:2.3 Feb 17, 2026
36 checks passed
@loic425 loic425 deleted the behat-annotations-to-attributes/api-shop branch February 25, 2026 13:07
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