Skip to content

Commit

Permalink
behat hostname fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SirDomin committed Apr 27, 2021
1 parent f5b3c76 commit 9caa1c2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Feature: Viewing products from a specific taxon and a channel
I want to be able to view products from a specific taxon and a channel

Background:
Given the store operates on a channel named "Poland"
And the store operates on another channel named "United States"
Given the store operates on a channel named "Poland" with hostname "poland"
And the store operates on another channel named "United States" with hostname "united-states"
And the store classifies its products as "T-Shirts" and "Funny"
And the store has a product "T-Shirt Banana" available in "Poland" channel
And this product belongs to "T-Shirts"
Expand Down
23 changes: 20 additions & 3 deletions src/Sylius/Behat/Context/Api/Shop/ChannelContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Webmozart\Assert\Assert;

Expand All @@ -27,14 +28,30 @@ final class ChannelContext implements Context
/** @var ResponseCheckerInterface */
private $responseChecker;

public function __construct(ApiClientInterface $client, ResponseCheckerInterface $responseChecker)
{
/** @var SharedStorageInterface */
private $sharedStorage;

public function __construct(
ApiClientInterface $client,
ResponseCheckerInterface $responseChecker,
SharedStorageInterface $sharedStorage
) {
$this->client = $client;
$this->responseChecker = $responseChecker;
$this->sharedStorage = $sharedStorage;
}


/**
* @Given I am browsing channel :channel
*/
public function iAmBrowsingChannel(ChannelInterface $channel): void
{
$this->sharedStorage->set('hostname', $channel->getHostname());
}

/**
* @When /^I (?:am browsing|start browsing|try to browse|browse) (that channel)$/
* @When /^I (?:start browsing|try to browse|browse) (that channel)$/
*/
public function iVisitChannelHomepage(ChannelInterface $channel): void
{
Expand Down
8 changes: 0 additions & 8 deletions src/Sylius/Behat/Context/Api/Shop/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ public function __construct(
$this->iriConverter = $iriConverter;
}

/**
* @Given I am browsing channel :channel
*/
public function iAmBrowsingChannel(ChannelInterface $channel)
{
$this->sharedStorage->set('hostname', $channel->getHostname());
}

/**
* @When /^I check (this product)'s details$/
* @When I view product :product
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Behat/Context/Setup/ChannelContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ public function storeOperatesOnASingleChannel($currencyCode = null)
* @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)"$/
* @Given /^the store(?:| also) operates on (?:a|another) channel named "([^"]+)" in "([^"]+)" currency$/
* @Given the store operates on a channel identified by :code code
* @Given the store (also) operates on a channel named :channelName with hostname :hostname
* @Given the store (also) operates on a(nother) channel named :channelName with hostname :hostname
*/
public function theStoreOperatesOnAChannelNamed(string $channelName, string $currencyCode = null, string $hostname = null): void
{
$channelCode = StringInflector::nameToLowercaseCode($channelName);
$defaultData = $this->defaultChannelFactory->create($channelCode, $channelName, $currencyCode);

$defaultData['channel']->setHostname(strtolower($hostname ?: str_replace(' ', '-', $channelName)));
$defaultData['channel']->setHostname($hostname);

$this->sharedStorage->setClipboard($defaultData);
$this->sharedStorage->set('channel', $defaultData['channel']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<service id="sylius.behat.context.api.shop.channel" class="Sylius\Behat\Context\Api\Shop\ChannelContext">
<argument type="service" id="sylius.behat.api_platform_client.shop.channel" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="sylius.behat.shared_storage" />
</service>

<service id="sylius.behat.context.api.shop.cart" class="Sylius\Behat\Context\Api\Shop\CartContext">
Expand Down

0 comments on commit 9caa1c2

Please sign in to comment.