mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Behat] Implemented SharedStorageContext
Also implement usage of LexicalContext in promotions steps
This commit is contained in:
parent
8af3740584
commit
a39c7789d5
8 changed files with 32 additions and 22 deletions
|
|
@ -25,6 +25,7 @@
|
|||
<parameter key="sylius.behat.context.setup.zone.class">Sylius\Behat\Context\Setup\ZoneContext</parameter>
|
||||
<parameter key="sylius.behat.context.setup.tax.class">Sylius\Behat\Context\Setup\TaxContext</parameter>
|
||||
<parameter key="sylius.behat.context.setup.lexical.class">Sylius\Behat\Context\Setup\LexicalContext</parameter>
|
||||
<parameter key="sylius.behat.context.setup.shared_storage.class">Sylius\Behat\Context\Setup\SharedStorageContext</parameter>
|
||||
|
||||
<parameter key="sylius.behat.context.hook.doctrine_orm.class">Sylius\Behat\Context\Hook\DoctrineORMContext</parameter>
|
||||
|
||||
|
|
@ -134,6 +135,11 @@
|
|||
<tag name="sylius.behat.context" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.behat.context.setup.shared_storage" class="%sylius.behat.context.setup.shared_storage.class%">
|
||||
<argument type="service" id="sylius.behat.shared_storage" container="symfony" />
|
||||
<tag name="sylius.behat.context" />
|
||||
</service>
|
||||
|
||||
<service id="sylius.behat.context.hook.doctrine_orm" class="%sylius.behat.context.hook.doctrine_orm.class%">
|
||||
<argument type="service" id="doctrine.orm.entity_manager" container="symfony_shared" />
|
||||
<tag name="sylius.behat.context" />
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ default:
|
|||
- sylius.behat.context.setup.shipping
|
||||
- sylius.behat.context.setup.zone
|
||||
- sylius.behat.context.setup.lexical
|
||||
- sylius.behat.context.setup.shared_storage
|
||||
|
||||
- sylius.behat.context.ui.checkout
|
||||
- sylius.behat.context.ui.cart
|
||||
|
|
|
|||
|
|
@ -31,6 +31,6 @@ class LexicalContext implements Context
|
|||
*/
|
||||
public function getPercentageFromString($percentage)
|
||||
{
|
||||
return ((int) $percentage)/100;
|
||||
return ((int) $percentage) / 100;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,26 +105,26 @@ final class PromotionContext implements Context
|
|||
}
|
||||
|
||||
/**
|
||||
* @Given /^(?:it|the promotion) gives "([^"]+)%" percentage discount to every order$/
|
||||
* @Given /^(?:it|the promotion) gives ("[^"]+") percentage discount to every order$/
|
||||
*/
|
||||
public function itGivesPercentageDiscountToEveryOrder($discount)
|
||||
{
|
||||
$currentPromotion = $this->sharedStorage->get('promotion');
|
||||
|
||||
$action = $this->actionFactory->createPercentageDiscount($this->getPercentageFromString($discount));
|
||||
$action = $this->actionFactory->createPercentageDiscount($discount);
|
||||
$currentPromotion->addAction($action);
|
||||
|
||||
$this->objectManager->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^(?:it|the promotion) gives "(?:€|£|\$)([^"]+)" fixed discount to every order with quantity at least ([^"]+)$/
|
||||
* @Given /^(?:it|the promotion) gives ("[^"]+") fixed discount to every order with quantity at least ([^"]+)$/
|
||||
*/
|
||||
public function itGivesFixedDiscountToEveryOrderWithQuantityAtLeast($amount, $quantity)
|
||||
{
|
||||
$currentPromotion = $this->sharedStorage->get('promotion');
|
||||
|
||||
$action = $this->actionFactory->createFixedDiscount($this->getPriceFromString($amount));
|
||||
$action = $this->actionFactory->createFixedDiscount($amount);
|
||||
$currentPromotion->addAction($action);
|
||||
|
||||
$rule = $this->ruleFactory->createCartQuantity((int) $quantity);
|
||||
|
|
@ -171,14 +171,4 @@ final class PromotionContext implements Context
|
|||
{
|
||||
return (int) round(($price * 100), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $discount
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
private function getPercentageFromString($discount)
|
||||
{
|
||||
return ((int) $discount) / 100;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,4 +39,12 @@ class SharedStorageContext implements Context
|
|||
{
|
||||
return $this->sharedStorage->getLatestResource();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Transform /^(this|that|the) ([^"]+)$/
|
||||
*/
|
||||
public function getResource($resource)
|
||||
{
|
||||
return $this->sharedStorage->get($resource);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ class PromotionContextSpec extends ObjectBehavior
|
|||
|
||||
$objectManager->flush()->shouldBeCalled();
|
||||
|
||||
$this->itGivesFixedDiscountToEveryOrder('10.00');
|
||||
$this->itGivesFixedDiscountToEveryOrder(1000);
|
||||
}
|
||||
|
||||
function it_creates_percentage_discount_action_for_promotion(
|
||||
|
|
@ -105,7 +105,7 @@ class PromotionContextSpec extends ObjectBehavior
|
|||
|
||||
$objectManager->flush()->shouldBeCalled();
|
||||
|
||||
$this->itGivesPercentageDiscountToEveryOrder('10');
|
||||
$this->itGivesPercentageDiscountToEveryOrder(0.1);
|
||||
}
|
||||
|
||||
function it_creates_fixed_discount_promotion_for_cart_with_specified_quantity(
|
||||
|
|
@ -127,7 +127,7 @@ class PromotionContextSpec extends ObjectBehavior
|
|||
|
||||
$objectManager->flush()->shouldBeCalled();
|
||||
|
||||
$this->itGivesFixedDiscountToEveryOrderWithQuantityAtLeast('10.00', '5');
|
||||
$this->itGivesFixedDiscountToEveryOrderWithQuantityAtLeast(1000, '5');
|
||||
}
|
||||
|
||||
function it_creates_fixed_discount_promotion_for_cart_with_specified_item_total(
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace spec\Sylius\Behat\Context\Setup;
|
|||
|
||||
use Behat\Behat\Context\Context;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Component\Core\Model\CustomerInterface;
|
||||
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -42,8 +43,12 @@ class SharedStorageContextSpec extends ObjectBehavior
|
|||
$this->getLatestResource()->shouldReturn('string');
|
||||
}
|
||||
|
||||
function it_transform_this_and_that_with_resource_name_to_current_resource_of_this_type($sharedStorage)
|
||||
{
|
||||
$sharedStorage->get('customer')
|
||||
function it_transform_this_that_and_the_with_resource_name_to_current_resource_of_this_type(
|
||||
$sharedStorage,
|
||||
CustomerInterface $customer
|
||||
) {
|
||||
$sharedStorage->get('customer')->willReturn($customer);
|
||||
|
||||
$this->getResource('customer')->shouldReturn($customer);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ class ShippingContextSpec extends ObjectBehavior
|
|||
|
||||
$shippingMethodRepository->add($shippingMethod)->shouldBeCalled();
|
||||
|
||||
$this->storeHasShippingMethodWithFee('Test shipping method', '10.00');
|
||||
$this->storeHasShippingMethodWithFee('Test shipping method', 1000);
|
||||
}
|
||||
|
||||
function it_configures_store_to_ship_everything_for_free_in_every_available_zone(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue