From d719c1bc81a8d7a176868b5ab61e7550c79e3e7f Mon Sep 17 00:00:00 2001 From: Rafikooo Date: Wed, 20 Dec 2023 11:02:20 +0100 Subject: [PATCH] [Behat] Use ChannelTransformer in DashboardContext --- .../Context/Transform/ChannelContext.php | 10 ++++++++-- .../Context/Ui/Admin/DashboardContext.php | 20 +++++++------------ .../config/suites/ui/admin/dashboard.yaml | 1 + 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Sylius/Behat/Context/Transform/ChannelContext.php b/src/Sylius/Behat/Context/Transform/ChannelContext.php index 92a7cb38d5..cc1edad1b5 100644 --- a/src/Sylius/Behat/Context/Transform/ChannelContext.php +++ b/src/Sylius/Behat/Context/Transform/ChannelContext.php @@ -15,10 +15,14 @@ namespace Sylius\Behat\Context\Transform; use Behat\Behat\Context\Context; use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; +use Sylius\Component\Core\Model\ChannelInterface; use Webmozart\Assert\Assert; final class ChannelContext implements Context { + /** + * @param ChannelRepositoryInterface $channelRepository + */ public function __construct(private ChannelRepositoryInterface $channelRepository) { } @@ -29,7 +33,7 @@ final class ChannelContext implements Context * @Transform /^channel to "([^"]+)"$/ * @Transform :channel */ - public function getChannelByName($channelName) + public function getChannelByName(string $channelName) { $channels = $this->channelRepository->findByName($channelName); @@ -44,8 +48,10 @@ final class ChannelContext implements Context /** * @Transform all channels + * + * @return array */ - public function getAllChannels() + public function getAllChannels(): array { return $this->channelRepository->findAll(); } diff --git a/src/Sylius/Behat/Context/Ui/Admin/DashboardContext.php b/src/Sylius/Behat/Context/Ui/Admin/DashboardContext.php index 32b6209161..9a578dd28b 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/DashboardContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/DashboardContext.php @@ -16,7 +16,7 @@ namespace Sylius\Behat\Context\Ui\Admin; use Behat\Behat\Context\Context; use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException; use Sylius\Behat\Page\Admin\DashboardPageInterface; -use Sylius\Component\Core\Formatter\StringInflector; +use Sylius\Component\Core\Model\ChannelInterface; use Webmozart\Assert\Assert; final class DashboardContext implements Context @@ -39,32 +39,26 @@ final class DashboardContext implements Context } /** - * @When I view statistics for :name channel + * @When I view statistics for :channel channel * * @throws UnexpectedPageException */ - public function iViewStatisticsForChannel(string $channelName): void + public function iViewStatisticsForChannel(ChannelInterface $channel): void { - $channelName === 'United States' ? - $channelName = 'WEB-US' : $channelName = StringInflector::nameToLowercaseCode($channelName); - - $this->dashboardPage->open(['channel' => $channelName]); + $this->dashboardPage->open(['channel' => $channel->getCode()]); } /** - * @When /^I view statistics for "([^"]+)" channel and (current|previous|next) year split by (month|day)$/ + * @When /^I view statistics for ("[^"]+" channel) and (current|previous|next) year split by (month|day)$/ * * @throws UnexpectedPageException */ public function iViewStatisticsForChannelAndYear( - string $channelName, + ChannelInterface $channel, string $period, string $interval, ): void { - $channelName === 'United States' - ? $channelName = 'WEB-US' : $channelName = StringInflector::nameToLowercaseCode($channelName); - - $this->dashboardPage->open(['channel' => $channelName]); + $this->dashboardPage->open(['channel' => $channel->getCode()]); match ($interval) { 'month' => $this->dashboardPage->chooseYearSplitByMonthsInterval(), diff --git a/src/Sylius/Behat/Resources/config/suites/ui/admin/dashboard.yaml b/src/Sylius/Behat/Resources/config/suites/ui/admin/dashboard.yaml index e6900bcfdf..e83a16d9a4 100644 --- a/src/Sylius/Behat/Resources/config/suites/ui/admin/dashboard.yaml +++ b/src/Sylius/Behat/Resources/config/suites/ui/admin/dashboard.yaml @@ -20,6 +20,7 @@ default: - sylius.behat.context.setup.zone - Sylius\Calendar\Tests\Behat\Context\Setup\CalendarContext + - sylius.behat.context.transform.channel - sylius.behat.context.transform.customer - sylius.behat.context.transform.lexical - sylius.behat.context.transform.order