Skip to content

Commit

Permalink
[Behat] Fix CS after introducing PHP 7.4 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed May 31, 2022
1 parent 5477cd0 commit e3961b0
Show file tree
Hide file tree
Showing 25 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Client/ResponseChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getCollection(Response $response): array

public function getCollectionItemsWithValue(Response $response, string $key, string $value): array
{
$items = array_filter($this->getCollection($response), fn(array $item): bool => $item[$key] === $value);
$items = array_filter($this->getCollection($response), fn (array $item): bool => $item[$key] === $value);

return $items;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Api/Admin/AjaxContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function iShouldSeeProductVariantsInTheList($number): void
*/
public function iShouldSeeTheProductVariantNamedAnd(...$names): void
{
$itemsNames = array_map(static fn($item) => strstr($item['descriptor'], ' ', true), $this->getJSONResponse());
$itemsNames = array_map(static fn ($item) => strstr($item['descriptor'], ' ', true), $this->getJSONResponse());

Assert::allOneOf($itemsNames, $names);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Setup/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ public function thisProductSizeBelongsToShippingCategory(ProductInterface $produ
{
$code = sprintf('%s_%s', $product->getCode(), $optionValueName);
/** @var ProductVariantInterface $productVariant */
$productVariant = $product->getVariants()->filter(fn($variant) => $code === $variant->getCode())->first();
$productVariant = $product->getVariants()->filter(fn ($variant) => $code === $variant->getCode())->first();

Assert::notNull($productVariant, sprintf('Product variant with given code %s not exists!', $code));

Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Transform/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public function getProductByName($productName)
*/
public function getProductsByNames(...$productsNames)
{
return array_map(fn($productName) => $this->getProductByName($productName), $productsNames);
return array_map(fn ($productName) => $this->getProductByName($productName), $productsNames);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(array $shippingCalculators, TranslatorInterface $tra
public function getShippingCalculatorByName(string $shippingCalculator): string
{
$flippedCalculators = array_flip(array_map(
fn(string $translationKey): string => $this->translator->trans($translationKey),
fn (string $translationKey): string => $this->translator->trans($translationKey),
$this->shippingCalculators
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function iAddANewCatalogPromotionScope(): void
*/
public function iAddScopeThatAppliesOnVariants(ProductVariantInterface ...$variants): void
{
$variantCodes = array_map(fn(ProductVariantInterface $variant) => $variant->getCode(), $variants);
$variantCodes = array_map(fn (ProductVariantInterface $variant) => $variant->getCode(), $variants);

$this->formElement->addScope();
$this->formElement->chooseScopeType('For variants');
Expand All @@ -245,7 +245,7 @@ public function iAddScopeThatAppliesOnVariants(ProductVariantInterface ...$varia
*/
public function iAddScopeThatAppliesOnTaxons(TaxonInterface ...$taxons): void
{
$taxonsCodes = array_map(fn(TaxonInterface $taxon) => $taxon->getCode(), $taxons);
$taxonsCodes = array_map(fn (TaxonInterface $taxon) => $taxon->getCode(), $taxons);

$this->formElement->addScope();
$this->formElement->chooseScopeType('For taxons');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private function addCollectionElement(string $collectionElement, string $buttonE

$this->getElement($buttonElement)->click();

$this->getDocument()->waitFor(5, fn() => $count + 1 === count($this->getCollectionItems($collectionElement)));
$this->getDocument()->waitFor(5, fn () => $count + 1 === count($this->getCollectionItems($collectionElement)));
}

/** @return NodeElement[] */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getMenuItems(): array
{
$menu = $this->getElement('vertical-menu');

return array_map(fn(NodeElement $element): string => $element->getText(), $menu->findAll('css', '[data-test-vertical-menu-item]'));
return array_map(fn (NodeElement $element): string => $element->getText(), $menu->findAll('css', '[data-test-vertical-menu-item]'));
}

public function canNavigateToParentTaxon(): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Element/Shop/MenuElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getMenuItems(): array
{
$menu = $this->getElement('menu');

return array_map(fn(NodeElement $element): string => $element->getText(), $menu->findAll('css', '[data-test-menu-item]'));
return array_map(fn (NodeElement $element): string => $element->getText(), $menu->findAll('css', '[data-test-menu-item]'));
}

protected function getDefinedElements(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Page/Admin/Customer/ShowPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private function getStatisticsForChannel(string $channelName): NodeElement
->findAll('css', '.row > .column > .statistic > .sylius-channel-name')
;

$statisticsRibs = array_filter($statisticsRibs, fn(NodeElement $statistic) => $channelName === trim($statistic->getText()));
$statisticsRibs = array_filter($statisticsRibs, fn (NodeElement $statistic) => $channelName === trim($statistic->getText()));

$actualStatisticsCount = count($statisticsRibs);
Assert::same(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function associateProducts(ProductAssociationTypeInterface $productAssoci
$dropdown->click();

foreach ($productsNames as $productName) {
$dropdown->waitFor(5, fn() => $this->hasElement('association_dropdown_item', [
$dropdown->waitFor(5, fn () => $this->hasElement('association_dropdown_item', [
'%association%' => $productAssociationType->getName(),
'%item%' => $productName,
]));
Expand Down Expand Up @@ -292,7 +292,7 @@ private function selectElementFromAttributesDropdown(string $id): void
private function waitForFormElement(int $timeout = 5): void
{
$form = $this->getElement('form');
$this->getDocument()->waitFor($timeout, fn() => false === strpos($form->getAttribute('class'), 'loading'));
$this->getDocument()->waitFor($timeout, fn () => false === strpos($form->getAttribute('class'), 'loading'));
}

private function clickTabIfItsNotActive(string $tabName): void
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Page/Admin/Product/IndexPerTaxonPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function savePositions(): void
$saveConfigurationButton = $this->getElement('save_configuration_button');
$saveConfigurationButton->press();

$this->getDocument()->waitFor(5, fn() => null === $saveConfigurationButton->find('css', '.loading'));
$this->getDocument()->waitFor(5, fn () => null === $saveConfigurationButton->find('css', '.loading'));
}

protected function getDefinedElements(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function selectMainTaxon(TaxonInterface $taxon): void

$this->getDriver()->executeScript(sprintf('$(\'input.search\').val(\'%s\')', $taxon->getName()));
$this->getElement('search')->click();
$this->getElement('search')->waitFor(10, fn() => $this->hasElement('search_item_selected'));
$this->getElement('search')->waitFor(10, fn () => $this->hasElement('search_item_selected'));
$itemSelected = $this->getElement('search_item_selected');
$itemSelected->click();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function addSelectedAttributes(): void

$form = $this->getDocument()->find('css', 'form');

$this->getDocument()->waitFor(1, fn() => $form->hasClass('loading'));
$this->getDocument()->waitFor(1, fn () => $form->hasClass('loading'));
}

public function removeAttribute(string $attributeName, string $localeCode): void
Expand Down Expand Up @@ -284,7 +284,7 @@ public function associateProducts(ProductAssociationTypeInterface $productAssoci
$dropdown->click();

foreach ($productsNames as $productName) {
$dropdown->waitFor(5, fn() => $this->hasElement('association_dropdown_item', [
$dropdown->waitFor(5, fn () => $this->hasElement('association_dropdown_item', [
'%association%' => $productAssociationType->getName(),
'%item%' => $productName,
]));
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Page/Admin/ProductVariant/IndexPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function savePositions(): void
{
$this->getElement('save_configuration_button')->press();

$this->getDocument()->waitFor(5, fn() => null === $this->getElement('save_configuration_button')->find('css', '.loading'));
$this->getDocument()->waitFor(5, fn () => null === $this->getElement('save_configuration_button')->find('css', '.loading'));
}

protected function getDefinedElements(): array
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function addRule(?string $ruleName): void

$this->getDocument()->clickLink('Add rule');

$this->getDocument()->waitFor(5, fn() => $count + 1 === count($this->getCollectionItems('rules')));
$this->getDocument()->waitFor(5, fn () => $count + 1 === count($this->getCollectionItems('rules')));

if (null !== $ruleName) {
$this->selectRuleOption('Type', $ruleName);
Expand Down Expand Up @@ -80,7 +80,7 @@ public function addAction(?string $actionName): void

$this->getDocument()->clickLink('Add action');

$this->getDocument()->waitFor(5, fn() => $count + 1 === count($this->getCollectionItems('actions')));
$this->getDocument()->waitFor(5, fn () => $count + 1 === count($this->getCollectionItems('actions')));

if (null !== $actionName) {
$this->selectActionOption('Type', $actionName);
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Page/Admin/ShippingMethod/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function addRule(string $ruleName): void

$this->getDocument()->clickLink('Add rule');

$this->getDocument()->waitFor(5, fn() => $count + 1 === count($this->getCollectionItems('rules')));
$this->getDocument()->waitFor(5, fn () => $count + 1 === count($this->getCollectionItems('rules')));

$this->selectRuleOption('Type', $ruleName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function activateLanguageTab(string $locale): void
$languageTabTitle->click();
}

$this->getDocument()->waitFor(10, fn() => $languageTabTitle->hasClass('active'));
$this->getDocument()->waitFor(10, fn () => $languageTabTitle->hasClass('active'));
}

public function enable(): void
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Page/Admin/Zone/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function checkValidationMessageForMembers(string $message): bool

public function chooseMember(string $name): void
{
$selectItems = $this->getDocument()->waitFor(2, fn() => $this->getDocument()->findAll('css', 'div[data-form-type="collection"] select'));
$selectItems = $this->getDocument()->waitFor(2, fn () => $this->getDocument()->findAll('css', 'div[data-form-type="collection"] select'));
$lastSelectItem = end($selectItems);

if (false === $lastSelectItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ protected function getDefinedElements(): array

private function waitForElement(int $timeout, string $elementName): void
{
$this->getDocument()->waitFor($timeout, fn() => $this->hasElement($elementName));
$this->getDocument()->waitFor($timeout, fn () => $this->hasElement($elementName));
}
}
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Page/Shop/Cart/SummaryPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function updateCart(): void

public function waitForRedirect(int $timeout): void
{
$this->getDocument()->waitFor($timeout, fn() => $this->isOpen());
$this->getDocument()->waitFor($timeout, fn () => $this->isOpen());
}

public function getPromotionCouponValidationMessage(): string
Expand Down
12 changes: 6 additions & 6 deletions src/Sylius/Behat/Page/Shop/Checkout/AddressPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function signIn(): void

public function specifyPassword(string $password): void
{
$this->getDocument()->waitFor(5, fn() => $this->getElement('login_password')->isVisible());
$this->getDocument()->waitFor(5, fn () => $this->getElement('login_password')->isVisible());

$this->getElement('login_password')->setValue($password);
}
Expand Down Expand Up @@ -231,7 +231,7 @@ public function selectShippingAddressFromAddressBook(AddressInterface $address):
$addressBookSelect = $this->getElement('shipping_address_book');

$addressBookSelect->click();
$addressOption = $addressBookSelect->waitFor(5, fn() => $addressBookSelect->find('css', sprintf('[data-test-address-book-item][data-id="%s"]', $address->getId())));
$addressOption = $addressBookSelect->waitFor(5, fn () => $addressBookSelect->find('css', sprintf('[data-test-address-book-item][data-id="%s"]', $address->getId())));

if (null === $addressOption) {
throw new ElementNotFoundException($this->getDriver(), 'option', 'css', sprintf('[data-test-address-book-item][data-id="%s"]', $address->getId()));
Expand All @@ -246,7 +246,7 @@ public function selectBillingAddressFromAddressBook(AddressInterface $address):
$addressBookSelect = $this->getElement('billing_address_book');

$addressBookSelect->click();
$addressOption = $addressBookSelect->waitFor(5, fn() => $addressBookSelect->find('css', sprintf('[data-test-address-book-item][data-id="%s"]', $address->getId())));
$addressOption = $addressBookSelect->waitFor(5, fn () => $addressBookSelect->find('css', sprintf('[data-test-address-book-item][data-id="%s"]', $address->getId())));

if (null === $addressOption) {
throw new ElementNotFoundException($this->getDriver(), 'option', 'css', sprintf('[data-test-address-book-item][data-id="%s"]', $address->getId()));
Expand Down Expand Up @@ -319,7 +319,7 @@ private function getOptionsFromSelect(NodeElement $element): array
{
return array_map(
/** @return string[] */
static fn(NodeElement $element): string => $element->getText(),
static fn (NodeElement $element): string => $element->getText(),
$element->findAll('css', 'option[value!=""]')
);
}
Expand Down Expand Up @@ -383,12 +383,12 @@ private function getFieldElement(string $element): ?NodeElement

private function waitForLoginAction(): bool
{
return $this->getDocument()->waitFor(5, fn() => !$this->hasElement('login_password'));
return $this->getDocument()->waitFor(5, fn () => !$this->hasElement('login_password'));
}

private function waitForElement(int $timeout, string $elementName): bool
{
return $this->getDocument()->waitFor($timeout, fn() => $this->hasElement($elementName));
return $this->getDocument()->waitFor($timeout, fn () => $this->hasElement($elementName));
}

private function assertAddressType(string $type): void
Expand Down
6 changes: 3 additions & 3 deletions src/Sylius/Behat/Page/Shop/HomePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getActiveCurrency(): string
public function getAvailableCurrencies(): array
{
return array_map(
fn(NodeElement $element) => $element->getText(),
fn (NodeElement $element) => $element->getText(),
$this->getElement('currency_selector')->findAll('css', '[data-test-available-currency]')
);
}
Expand All @@ -79,7 +79,7 @@ public function getActiveLocale(): string
public function getAvailableLocales(): array
{
return array_map(
fn(NodeElement $element) => $element->getText(),
fn (NodeElement $element) => $element->getText(),
$this->getElement('locale_selector')->findAll('css', '[data-test-available-locale]')
);
}
Expand All @@ -92,7 +92,7 @@ public function switchLocale($localeCode): void
public function getLatestProductsNames(): array
{
return array_map(
fn(NodeElement $element) => $element->getText(),
fn (NodeElement $element) => $element->getText(),
$this->getElement('latest_products')->findAll('css', '[data-test-product-name]')
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Sylius/Behat/Page/Shop/Product/ShowPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function getCatalogPromotionNames(): array
$productPriceContent = $this->getElement('product_price_content');
$catalogPromotions = $productPriceContent->findAll('css', '.promotion_label');

return array_map(fn(NodeElement $element): string => $element->getText(), $catalogPromotions);
return array_map(fn (NodeElement $element): string => $element->getText(), $catalogPromotions);
}

public function getCurrentUrl(): string
Expand Down Expand Up @@ -339,7 +339,7 @@ public function getOptionValues(string $optionCode): array
$optionElement = $this->getElement('option_select', ['%optionCode%' => strtoupper($optionCode)]);

return array_map(
fn(NodeElement $element) => $element->getText(),
fn (NodeElement $element) => $element->getText(),
$optionElement->findAll('css', 'option')
);
}
Expand Down Expand Up @@ -383,7 +383,7 @@ private function waitForCartSummary(): void
{
if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) {
JQueryHelper::waitForAsynchronousActionsToFinish($this->getSession());
$this->getDocument()->waitFor(3, fn(): bool => $this->summaryPage->isOpen());
$this->getDocument()->waitFor(3, fn (): bool => $this->summaryPage->isOpen());
}
}
}
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Service/JQueryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public static function waitForAsynchronousActionsToFinish(Session $session): voi
public static function waitForFormToStopLoading(DocumentElement $document, int $timeout = 10): void
{
$form = $document->find('css', 'form');
$document->waitFor($timeout, fn() => !$form->hasClass('loading'));
$document->waitFor($timeout, fn () => !$form->hasClass('loading'));
}
}

0 comments on commit e3961b0

Please sign in to comment.