Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Commit

Permalink
Additional test + improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszpietrzak1994 committed Jun 12, 2018
1 parent f542dbe commit 09026d1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
11 changes: 11 additions & 0 deletions features/being_notified_about_changes_in_order.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ Feature: Being notified about changes in order
And I should be notified that previous order total was "$59.00"
And I should see exactly 2 notifications

@ui
Scenario: Reordering previously placed order when several items is out of stock
Given the product "Angel T-Shirt" is out of stock
Given the product "Awesome Mug" is out of stock
When I browse my orders
And I click reorder button next to the order "#00000666"
Then I should be on my cart summary page
And I should be notified that products "Angel T-Shirt", "Awesome Mug" are out of stock
And I should be notified that previous order total was "$59.00"
And I should see exactly 2 notifications

@ui
Scenario: Reordering previously placed order when promotion is no longer available
Given the promotion was disabled for the channel "Web"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ final class ReorderEligibilityConstraintMessageFormatter implements ReorderEligi
{
public function format(array $messageParameters): string
{
$messageParameter = '';
$message = '';

if (count($messageParameters) === 1) {
$messageParameter = array_pop($messageParameters);
$message = array_pop($messageParameters);
}

else {
$lastMessageParameter = end($messageParameters);
foreach ($messageParameters as $messageParameter) {
$messageParameter .= $messageParameter . ($messageParameters !== $lastMessageParameter) ? ', ' : '';
$message .= $messageParameter . (($messageParameter !== $lastMessageParameter) ? ', ' : '');
}
}

return $messageParameter;
return $message;
}
}
18 changes: 13 additions & 5 deletions tests/Behat/Context/Reorder/ReorderContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@
use Behat\Mink\Session;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\PromotionInterface;
use Sylius\CustomerReorderPlugin\ReorderEligibility\ReorderEligibilityConstraintMessageFormatterInterface;

final class ReorderContext implements Context
{
/** @var Session */
private $session;

public function __construct(Session $session)
{
/** @var ReorderEligibilityConstraintMessageFormatterInterface */
private $reorderEligibilityConstraintMessageFormatter;

public function __construct(
Session $session,
ReorderEligibilityConstraintMessageFormatterInterface $reorderEligibilityConstraintMessageFormatter
) {
$this->session = $session;
$this->reorderEligibilityConstraintMessageFormatter = $reorderEligibilityConstraintMessageFormatter;
}

/**
Expand Down Expand Up @@ -59,13 +66,14 @@ public function iClickReorderButtonNextToTheOrder(string $orderNumber): void
}

/**
* @Then I should be notified that product :product is out of stock
* @Then I should be notified that product :firstProduct is out of stock
* @Then I should be notified that products :firstProduct, :secondProduct are out of stock
*/
public function iShouldBeNotifiedThatProductIsOutOfStock(string $product): void
public function iShouldBeNotifiedThatProductIsOutOfStock(string ... $products): void
{
$this->assertFlashMessageWithTextExists(sprintf(
'Following items: %s are out of stock. It may have affected order total.',
$product)
$this->reorderEligibilityConstraintMessageFormatter->format($products))
);
}

Expand Down
1 change: 1 addition & 0 deletions tests/Behat/Resources/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<service id="sylius_customer_reorder.behat.context.setup.reorder" class="Tests\Sylius\CustomerReorderPlugin\Behat\Context\Reorder\ReorderContext" public="false">
<argument type="service" id="sylius_customer_reorder.behat.mink.session" />
<tag name="fob.context_service" />
<argument type="service" id="__symfony__.Sylius\CustomerReorderPlugin\ReorderEligibility\ReorderEligibilityConstraintMessageFormatter"/>
</service>
<service id="sylius_customer_reorder.behat.mink.session" class="Behat\Mink\Session" lazy="true" public="false">
<factory service="__behat__.mink" method="getSession" />
Expand Down

0 comments on commit 09026d1

Please sign in to comment.