Skip to content

Convert Behat annotations to PHP attributes in Api Admin contexts#18821

Merged
NoResponseMate merged 1 commit intoSylius:2.3from
loic425:behat-annotations-to-attributes/api-admin
Feb 13, 2026
Merged

Convert Behat annotations to PHP attributes in Api Admin contexts#18821
NoResponseMate merged 1 commit intoSylius:2.3from
loic425:behat-annotations-to-attributes/api-admin

Conversation

@loic425
Copy link
Copy Markdown
Member

@loic425 loic425 commented Feb 12, 2026

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

Summary by CodeRabbit

Release Notes

  • Tests

    • Modernized Behat test context annotations across admin API tests, converting from traditional docblock-style declarations to PHP 8 attributes for improved code consistency and maintainability.
  • Refactor

    • Updated test infrastructure to leverage PHP 8 native attribute syntax, streamlining test step definitions without behavioral changes to the application.

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

coderabbitai bot commented Feb 12, 2026

📝 Walkthrough

Walkthrough

This pull request systematically migrates Behat step definitions across 46 Admin API context files from PHPDoc-based annotations (@Given, @When, @Then) to PHP 8 attributes (#[Given], #[When], #[Then]), modernizing the test infrastructure while preserving all step definitions and their behavior.

Changes

Cohort / File(s) Summary
Catalog & Product Management
src/Sylius/Behat/Context/Api/Admin/BrowsingCatalogPromotionProductVariantsContext.php, BrowsingProductVariantsContext.php, CreatingProductVariantContext.php, ManagingCatalogPromotionsContext.php, ManagingProductAssociationTypesContext.php, ManagingProductAssociationsContext.php, ManagingProductAttributesContext.php, ManagingProductImagesContext.php, ManagingProductOptionsContext.php, ManagingProductReviewsContext.php, ManagingProductTaxonsContext.php, ManagingProductVariantsContext.php, ManagingProductVariantsPricesContext.php, ManagingProductsContext.php
Migrated all Behat step annotations to PHP 8 attributes. Notable changes include updated translations structure in product association types (nested translations array), conditional translation updates in product options, and adjusted response checking patterns for product reviews.
Commerce Operations
ManagingChannelPricingLogEntryContext.php, ManagingChannelsContext.php, ManagingChannelsBillingDataContext.php, ManagingOrdersContext.php, ManagingPaymentMethodsContext.php, ManagingPaymentRequestsContext.php, ManagingPaymentsContext.php, ManagingPlacedOrderAddressesContext.php, ManagingShipmentsContext.php, ManagingShippingCategoriesContext.php, ManagingShippingMethodsContext.php
Converted all step annotations to attributes across order, channel, payment, and shipment management contexts. Includes minor logic adjustments in currency handling and expanded request-building logic for promotion and catalog pricing contexts.
Customer & Administration
LoginContext.php, ManagingAdministratorsContext.php, ManagingCustomerGroupsContext.php, ManagingCustomersContext.php, ResettingPasswordContext.php
Migrated step definitions from docblocks to attributes. Includes avatar upload request construction adjustments in administrator context, group filtering logic updates in customer management, method renaming from intentionallyLeftEmpty to intentionallyLeftBlank, and HTTP method constant alignment in password reset context.
Configuration & Settings
DashboardContext.php, ManagingChannelPriceHistoryConfigContext.php, ManagingCountriesContext.php, ManagingCurrenciesContext.php, ManagingExchangeRatesContext.php, ManagingLocalesContext.php, ManagingTaxCategoriesContext.php, ManagingTaxRatesContext.php, ManagingZonesContext.php
Replaced all annotation-based step definitions with PHP 8 attributes for channels, currencies, locales, tax, and zone management. Updated assertion patterns to use ResponseChecker-based validations; adjusted currency and locale presence verification logic.
Promotion & Offers
ManagingPromotionCouponsContext.php, ManagingPromotionsContext.php
Migrated Behat step annotations to attributes. Includes minor behavioral change in promotion counting using collection-based response checking instead of previous approach.
Taxon Management
ManagingTaxonImagesContext.php, ManagingTaxonsContext.php, RemovingTaxonContext.php
Converted step definitions from docblock annotations to PHP 8 attributes with no changes to method signatures or core behavior.
Utilities & Helpers
Helper/ValidationTrait.php, TranslationContext.php, RemovingProductContext.php
Migrated utility and helper context files to attribute-based step definitions, maintaining identical behavior and method signatures.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

API, Admin, DX

Suggested reviewers

  • GSadee
  • TheMilek

Poem

🐰 Hop, hop, the times they change so bright,
From docblocks old to attributes in light,
Eight point zero, our Behat steps now gleam,
Modernized context, a developer's dream!
With forty-six files synchronized in time,
This migration rabbit says all is sublime!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.07% 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 PR title clearly and concisely summarizes the main objective: converting Behat annotations to PHP attributes across Api Admin context files.

✏️ 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 12, 2026

❗ Preview Environment delete from Bunnyshell failed

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

See: Environment Details

Available commands:

  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove 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: 6

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/Admin/ManagingCatalogPromotionsContext.php (1)

438-458: ⚠️ Potential issue | 🔴 Critical

Critical: undefined variables and call to non-existent method

This method has multiple issues that will cause runtime failures:

  1. Lines 447–448: $type and $configuration are undefined variables. The method signature only declares $catalogPromotion and $productVariant parameters; these variables are never defined.
  2. Line 453: $this->changeFirstScopeConfigurationTo(...) does not exist in this class or in its ValidationTrait, nor anywhere in the Behat context codebase.
  3. The method contains conflicting code paths — lines 446–452 perform manual scope manipulation and call update(), while lines 453–457 attempt similar logic via a non-existent helper method.

This appears to be a bad merge where two implementations were left in the same method. The code will crash at runtime with undefined variable notices and a fatal "Call to undefined method" error when any Behat scenario exercises this step.

Likely intended implementation
 #[When('/^I edit ("[^"]+" catalog promotion) to be applied on ("[^"]+" variant)$/')]
     public function iEditCatalogPromotionToBeAppliedOnVariant(
         CatalogPromotionInterface $catalogPromotion,
         ProductVariantInterface $productVariant,
     ): void {
         $this->client->buildUpdateRequest(Resources::CATALOG_PROMOTIONS, $catalogPromotion->getCode());
 
         $content = $this->client->getContent();
         unset($content['scopes'][0]);
-        $content['scopes'][0]['type'] = $type;
-        $content['scopes'][0]['configuration'] = $configuration;
-
-        $this->client->setRequestData($content);
-
-        $this->client->update();
-        $this->changeFirstScopeConfigurationTo(
-            $catalogPromotion,
-            InForVariantsScopeVariantChecker::TYPE,
-            ['variants' => [$productVariant->getCode()]],
-        );
+        $content['scopes'][0] = [
+            'type' => InForVariantsScopeVariantChecker::TYPE,
+            'configuration' => ['variants' => [$productVariant->getCode()]],
+        ];
+
+        $this->client->setRequestData($content);
+        $this->client->update();
     }
🤖 Fix all issues with AI agents
In `@src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php`:
- Around line 1265-1275: Replace the incorrect step annotations on the assertion
methods: change the attribute on the itShouldBeExclusive() method from
#[Given('it should be exclusive')] to #[Then('it should be exclusive')], and
likewise change the attribute on itShouldNotBeExclusive() from #[Given('it
should not be exclusive')] to #[Then('it should not be exclusive')], keeping the
method bodies (the Assert::true/false calls using
$this->responseChecker->hasValue and $this->client->getLastResponse())
unchanged.

In `@src/Sylius/Behat/Context/Api/Admin/ManagingLocalesContext.php`:
- Around line 132-136: The step definition
iShouldBeInformedThatLocaleHasBeenDeleted captures $localeCode but never
verifies it; enhance the assertion by extracting the response body from
$this->client->getLastResponse(), decode it (or read location header) and assert
it references the expected $localeCode (e.g., compare returned resource
identifier or Location header to $localeCode), or if there is no body/identifier
intentionally, add a PHPMD suppression comment for the unused parameter; update
the assertion in iShouldBeInformedThatLocaleHasBeenDeleted accordingly to either
validate the deleted locale matches $localeCode or explicitly document/suppress
the unused parameter.

In `@src/Sylius/Behat/Context/Api/Admin/ManagingProductOptionsContext.php`:
- Around line 213-216: Remove the leftover malformed PHPDoc block or convert it
to a proper attribute: delete the stray PHPDoc lines starting with "*      *
`@Then`" that sit above the method in ManagingProductOptionsContext, or if the
locale-aware step is required replace that PHPDoc with a #[Then('/^(this product
option) should not have the "([^"]*)" option value in ("([^"]+)" locale)$/')]
attribute and update the corresponding method (the method currently annotated
with #[Then('/^(this product option) should not have the "([^"]*)" option
value$/')]) to accept the extra locale parameter (add a $locale string parameter
and handle it inside the method).

In `@src/Sylius/Behat/Context/Api/Admin/ManagingProductTaxonsContext.php`:
- Around line 16-18: Reorder the PHP use imports to follow the project's
alphabetical/grouping rules: move ApiPlatform\Metadata\IriConverterInterface and
Behat\Behat\Context\Context before the Behat\Step imports, and ensure
Behat\Step\Then appears before Behat\Step\When; update the use block in
ManagingProductTaxonsContext.php accordingly so imports are grouped and sorted
alphabetically.

In `@src/Sylius/Behat/Context/Api/Admin/ManagingPromotionsContext.php`:
- Around line 546-552: Change the Behat step attribute on the
thePromotionShouldHaveLabelInLocale method from #[When(...)] to #[Then(...)] to
reflect that it is an assertion/verification step; locate the method named
thePromotionShouldHaveLabelInLocale and update its attribute decorator
accordingly so the step uses #[Then('the :promotion promotion should have a
label :label in :localeCode locale')].

In `@src/Sylius/Behat/Context/Api/Admin/ManagingTaxRatesContext.php`:
- Around line 16-18: Reorder the PHP use imports in ManagingTaxRatesContext.php
to follow the project's alphabetical/grouping rules: place the ApiPlatform use
(IriConverterInterface) and any Behat\Behat\... groupings before the Behat\Step
imports, and within the Behat\Step group sort alphabetically so Then comes
before When; update the three imports (IriConverterInterface, Then, When) so
they are in the correct grouped order and alphabetically sorted.
🧹 Nitpick comments (31)
src/Sylius/Behat/Context/Api/Admin/TranslationContext.php (1)

16-17: Imports are not in alphabetical order.

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

Proposed fix
-use Behat\Step\Then;
 use Behat\Behat\Context\Context;
+use Behat\Step\Then;
 use Sylius\Behat\Client\ApiClientInterface;

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

src/Sylius/Behat/Context/Api/Admin/ManagingProductVariantsPricesContext.php (1)

16-17: Import order: Behat\Behat\Context\Context should precede Behat\Step\When alphabetically.

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

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

src/Sylius/Behat/Context/Api/Admin/ManagingProductAssociationsContext.php (1)

16-17: Import statements 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\When;

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

src/Sylius/Behat/Context/Api/Admin/ManagingTaxonImagesContext.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;
src/Sylius/Behat/Context/Api/Admin/ManagingCustomerGroupsContext.php (1)

16-17: Import statements 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/Admin/ManagingPaymentMethodsContext.php (1)

16-18: Imports are not sorted alphabetically.

The Behat\Step\* imports should be ordered alphabetically per the project's coding guidelines: Given, Then, When.

Proposed fix
-use Behat\Step\When;
-use Behat\Step\Given;
-use Behat\Step\Then;
+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/Admin/RemovingProductContext.php (1)

16-18: Imports are not sorted alphabetically.

Behat\Behat\Context\Context should precede the Behat\Step\* imports, and Then should come 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;

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

src/Sylius/Behat/Context/Api/Admin/ManagingChannelsBillingDataContext.php (1)

16-17: Imports are not in alphabetical order.

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

Suggested fix
-use Behat\Step\Then;
 use Behat\Behat\Context\Context;
+use Behat\Step\Then;
 use Sylius\Behat\Client\ApiClientInterface;

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

src/Sylius/Behat/Context/Api/Admin/ManagingShipmentsContext.php (1)

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

Suggested 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."

src/Sylius/Behat/Context/Api/Admin/ManagingProductImagesContext.php (1)

16-17: Imports are not sorted alphabetically.

Behat\Step\Then should come before Behat\Step\When. 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\Step\Then;
+use Behat\Step\When;
src/Sylius/Behat/Context/Api/Admin/ManagingCurrenciesContext.php (1)

16-18: Imports are not sorted alphabetically.

Behat\Behat\Context\Context should come before the Behat\Step\* imports per alphabetical ordering.

Suggested order
-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/Admin/ManagingExchangeRatesContext.php (1)

16-18: Imports not sorted alphabetically.

use imports should be Given, Then, When to respect alphabetical order.

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

src/Sylius/Behat/Context/Api/Admin/ManagingShippingCategoriesContext.php (1)

16-18: Imports are not sorted alphabetically.

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

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/Admin/ManagingProductsContext.php (1)

16-18: Imports not sorted alphabetically: Then should come before When.

As per coding guidelines, use imports should be sorted alphabetically.

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

16-18: Imports are not sorted alphabetically.

Behat\Step\When and Behat\Step\Then should follow Behat\Behat\Context\Context, and Then should precede When.

Suggested order
-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/Admin/ManagingOrdersContext.php (2)

16-17: Imports are not sorted alphabetically.

Behat\Step\Given (line 16) should come after ApiPlatform\Metadata\IriConverterInterface (line 17) to maintain alphabetical order.

Proposed fix
-use Behat\Step\Given;
 use ApiPlatform\Metadata\IriConverterInterface;
 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)".


590-599: Missing return type declaration.

iShouldNotSeeOrderWithNumber on line 591 is missing a : void return type, unlike every other method in this class. This is likely a pre-existing oversight but worth fixing while touching this file.

Proposed fix
-    public function iShouldNotSeeOrderWithNumber(string $orderNumber)
+    public function iShouldNotSeeOrderWithNumber(string $orderNumber): void

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

src/Sylius/Behat/Context/Api/Admin/ManagingProductVariantsContext.php (1)

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

As per coding guidelines, "Sort PHP use imports alphabetically and group by type." Behat\Step\Then should precede Behat\Step\When.

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

16-18: Import statements are not sorted alphabetically.

Then should come before When per alphabetical ordering.

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

src/Sylius/Behat/Context/Api/Admin/ManagingProductAssociationTypesContext.php (1)

164-164: Nit: unnecessary regex for a plain string pattern.

Line 164 wraps the step pattern in regex delimiters (/^...$/) but this pattern has no captures, optional groups, or wildcards. All other simple string patterns in this file use plain Turnip syntax (e.g., line 129). Consider using a plain string for consistency:

Suggested change
-    #[Then('/^I should be notified that it has been successfully deleted$/')]
+    #[Then('I should be notified that it has been successfully deleted')]
src/Sylius/Behat/Context/Api/Admin/ManagingCustomersContext.php (1)

16-17: Import placement is out of alphabetical order, but otherwise correct.

The new use Behat\Step\When and use Behat\Step\Then imports should be placed after Behat\Behat\Context\Context (and Then before When) to maintain alphabetical ordering. Noting this as a nit since no linter/static analysis tool flagged it. As per coding guidelines, "Sort PHP use imports alphabetically and group by type (classes, functions, constants)."

Suggested reordering
-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/Admin/ManagingProductOptionsContext.php (1)

16-18: Nit: use imports for Behat\Step are not sorted alphabetically.

Then should come before When.

Suggested 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".

src/Sylius/Behat/Context/Api/Admin/CreatingProductVariantContext.php (1)

16-17: Imports are not sorted alphabetically.

Behat\Step\When (Line 16) is placed before ApiPlatform\Metadata\IriConverterInterface (Line 17). As per coding guidelines, use imports should be sorted alphabetically.

Proposed fix
-use Behat\Step\When;
 use ApiPlatform\Metadata\IriConverterInterface;
 use Behat\Behat\Context\Context;
+use Behat\Step\When;
src/Sylius/Behat/Context/Api/Admin/ManagingChannelPriceHistoryConfigContext.php (1)

16-18: Imports are not sorted alphabetically.

Behat\Step\When and Behat\Step\Then (Lines 16–17) are placed before Behat\Behat\Context\Context (Line 18), and When precedes Then. Alphabetically, Behat\Behat < Behat\Step\Then < Behat\Step\When.

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/Admin/DashboardContext.php (1)

16-18: Imports are not sorted alphabetically — same pattern as the other files.

Behat\Step\* imports should follow Behat\Behat\Context\Context.

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/Admin/ManagingPaymentRequestsContext.php (1)

16-18: Imports are not sorted alphabetically — consistent with the other 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;
src/Sylius/Behat/Context/Api/Admin/ManagingTaxonsContext.php (1)

16-18: Imports are not sorted alphabetically — consistent with the other 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;
src/Sylius/Behat/Context/Api/Admin/ManagingTaxCategoriesContext.php (1)

16-19: Imports are not sorted alphabetically.

Behat\Step\* imports should follow Behat\Behat\Context\Context, and within the group: Given < Then < When.

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

16-19: Imports are not sorted alphabetically — consistent with the other files in this PR.

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

16-19: Imports are not sorted alphabetically.

Behat\Step\When and Behat\Step\Then (Lines 16–17) are placed before ApiPlatform\Metadata\IriConverterInterface (Line 18). Alphabetically, ApiPlatform < Behat\Behat < Behat\Step\Then < Behat\Step\When.

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;
src/Sylius/Behat/Context/Api/Admin/Helper/ValidationTrait.php (1)

16-17: Imports are not sorted alphabetically.

Behat\Step\Then should come before Behat\Step\When. This same issue applies to all files in this PR.

Proposed fix
-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".

Comment on lines +1265 to 1275
#[Given('it should be exclusive')]
public function itShouldBeExclusive(): void
{
Assert::true($this->responseChecker->hasValue($this->client->getLastResponse(), 'exclusive', true));
}

/**
* @Given it should not be exclusive
*/
#[Given('it should not be exclusive')]
public function itShouldNotBeExclusive(): void
{
Assert::false($this->responseChecker->hasValue($this->client->getLastResponse(), 'exclusive', true));
}
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

#[Given] used for assertion steps — should be #[Then].

Lines 1265 and 1271 use #[Given('it should be exclusive')] and #[Given('it should not be exclusive')]. These are assertion steps and should use #[Then] to follow the Given-When-Then convention. Based on learnings, Behat scenarios should follow the Given-When-Then pattern strictly.

Suggested fix
-    #[Given('it should be exclusive')]
+    #[Then('it should be exclusive')]
     public function itShouldBeExclusive(): void
     {
         Assert::true($this->responseChecker->hasValue($this->client->getLastResponse(), 'exclusive', true));
     }
 
-    #[Given('it should not be exclusive')]
+    #[Then('it should not be exclusive')]
     public function itShouldNotBeExclusive(): void
🤖 Prompt for AI Agents
In `@src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php`
around lines 1265 - 1275, Replace the incorrect step annotations on the
assertion methods: change the attribute on the itShouldBeExclusive() method from
#[Given('it should be exclusive')] to #[Then('it should be exclusive')], and
likewise change the attribute on itShouldNotBeExclusive() from #[Given('it
should not be exclusive')] to #[Then('it should not be exclusive')], keeping the
method bodies (the Assert::true/false calls using
$this->responseChecker->hasValue and $this->client->getLastResponse())
unchanged.

Comment on lines +132 to 136
#[Then('I should be informed that locale :localeCode has been deleted')]
public function iShouldBeInformedThatLocaleHasBeenDeleted(string $localeCode): void
{
Assert::same($this->client->getLastResponse()->getStatusCode(), Response::HTTP_NO_CONTENT);
}
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

$localeCode parameter is captured but never verified.

The method only asserts HTTP_NO_CONTENT without confirming the deleted locale matches $localeCode. While the preceding step likely targets the correct resource, this makes the assertion weaker than the step text implies. Consider whether validating the locale code adds value here, or suppress the PHPMD warning if this is intentional.

🧰 Tools
🪛 PHPMD (2.15.0)

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

(UnusedFormalParameter)

🤖 Prompt for AI Agents
In `@src/Sylius/Behat/Context/Api/Admin/ManagingLocalesContext.php` around lines
132 - 136, The step definition iShouldBeInformedThatLocaleHasBeenDeleted
captures $localeCode but never verifies it; enhance the assertion by extracting
the response body from $this->client->getLastResponse(), decode it (or read
location header) and assert it references the expected $localeCode (e.g.,
compare returned resource identifier or Location header to $localeCode), or if
there is no body/identifier intentionally, add a PHPMD suppression comment for
the unused parameter; update the assertion in
iShouldBeInformedThatLocaleHasBeenDeleted accordingly to either validate the
deleted locale matches $localeCode or explicitly document/suppress the unused
parameter.

Comment on lines 213 to +216
/**
* @Then /^(this product option) should not have the "([^"]*)" option value$/
* @Then /^(this product option) should not have the "([^"]*)" option value in ("([^"]+)" locale)$/
* * @Then /^(this product option) should not have the "([^"]*)" option value in ("([^"]+)" locale)$/
*/
#[Then('/^(this product option) should not have the "([^"]*)" option value$/')]
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

Leftover malformed PHPDoc annotation not converted to attribute.

This PHPDoc block contains what appears to be an unconverted @Then annotation with a locale-aware pattern. The double * and extra indentation (* * @Then``) make it malformed — Behat won't match it either as an annotation or an attribute.

If this step pattern is still needed, convert it to a #[Then(...)] attribute (and update the method signature to accept a locale parameter). If it's intentionally dropped, remove the PHPDoc block entirely.

Suggested fix (remove dead annotation)
-    /**
-     *      * `@Then` /^(this product option) should not have the "([^"]*)" option value in ("([^"]+)" locale)$/
-     */
     #[Then('/^(this product option) should not have the "([^"]*)" option value$/')]
📝 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
/**
* @Then /^(this product option) should not have the "([^"]*)" option value$/
* @Then /^(this product option) should not have the "([^"]*)" option value in ("([^"]+)" locale)$/
* * @Then /^(this product option) should not have the "([^"]*)" option value in ("([^"]+)" locale)$/
*/
#[Then('/^(this product option) should not have the "([^"]*)" option value$/')]
#[Then('/^(this product option) should not have the "([^"]*)" option value$/')]
🤖 Prompt for AI Agents
In `@src/Sylius/Behat/Context/Api/Admin/ManagingProductOptionsContext.php` around
lines 213 - 216, Remove the leftover malformed PHPDoc block or convert it to a
proper attribute: delete the stray PHPDoc lines starting with "*      * `@Then`"
that sit above the method in ManagingProductOptionsContext, or if the
locale-aware step is required replace that PHPDoc with a #[Then('/^(this product
option) should not have the "([^"]*)" option value in ("([^"]+)" locale)$/')]
attribute and update the corresponding method (the method currently annotated
with #[Then('/^(this product option) should not have the "([^"]*)" option
value$/')]) to accept the extra locale parameter (add a $locale string parameter
and handle it inside the method).

Comment on lines +16 to 18
use Behat\Step\When;
use Behat\Step\Then;
use ApiPlatform\Metadata\IriConverterInterface;
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

Imports are not sorted alphabetically.

Behat\Step\When and Behat\Step\Then should be placed after ApiPlatform\Metadata\IriConverterInterface and Behat\Behat\Context\Context, and Then should come before When.

♻️ 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;

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/Api/Admin/ManagingProductTaxonsContext.php` around
lines 16 - 18, Reorder the PHP use imports to follow the project's
alphabetical/grouping rules: move ApiPlatform\Metadata\IriConverterInterface and
Behat\Behat\Context\Context before the Behat\Step imports, and ensure
Behat\Step\Then appears before Behat\Step\When; update the use block in
ManagingProductTaxonsContext.php accordingly so imports are grouped and sorted
alphabetically.

Comment on lines +546 to 552
#[When('the :promotion promotion should have a label :label in :localeCode locale')]
public function thePromotionShouldHaveLabelInLocale(PromotionInterface $promotion, string $label, string $localeCode): void
{
$response = $this->client->show(Resources::PROMOTIONS, $promotion->getCode());

Assert::true($this->responseChecker->hasTranslation($response, $localeCode, 'label', $label));
}
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 likely be #[Then] for this assertion step.

The step text 'the :promotion promotion should have a label :label in :localeCode locale' reads as a verification/assertion, which conventionally maps to #[Then]. Using #[When] here will still work at runtime (Behat doesn't enforce Given/When/Then semantics), but it breaks the Given-When-Then convention.

Suggested fix
-    #[When('the :promotion promotion should have a label :label in :localeCode locale')]
+    #[Then('the :promotion promotion should have a label :label in :localeCode locale')]
🤖 Prompt for AI Agents
In `@src/Sylius/Behat/Context/Api/Admin/ManagingPromotionsContext.php` around
lines 546 - 552, Change the Behat step attribute on the
thePromotionShouldHaveLabelInLocale method from #[When(...)] to #[Then(...)] to
reflect that it is an assertion/verification step; locate the method named
thePromotionShouldHaveLabelInLocale and update its attribute decorator
accordingly so the step uses #[Then('the :promotion promotion should have a
label :label in :localeCode locale')].

Comment on lines +16 to 18
use Behat\Step\When;
use Behat\Step\Then;
use ApiPlatform\Metadata\IriConverterInterface;
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

Imports are not sorted alphabetically.

The new use statements should be placed after ApiPlatform\... and Behat\Behat\..., and Then should precede When.

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;

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/Api/Admin/ManagingTaxRatesContext.php` around lines
16 - 18, Reorder the PHP use imports in ManagingTaxRatesContext.php to follow
the project's alphabetical/grouping rules: place the ApiPlatform use
(IriConverterInterface) and any Behat\Behat\... groupings before the Behat\Step
imports, and within the Behat\Step group sort alphabetically so Then comes
before When; update the three imports (IriConverterInterface, Then, When) so
they are in the correct grouped order and alphabetically sorted.

@loic425 loic425 mentioned this pull request Feb 12, 2026
27 tasks
@NoResponseMate NoResponseMate merged commit 73fcfcd into Sylius:2.3 Feb 13, 2026
36 checks passed
@loic425 loic425 deleted the behat-annotations-to-attributes/api-admin branch February 13, 2026 10:04
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.

2 participants