mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
Review fixes
This commit is contained in:
parent
ece8b0d9d1
commit
4b43865fd5
10 changed files with 61 additions and 72 deletions
|
|
@ -1,5 +1,14 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ default:
|
|||
contexts_as_services:
|
||||
- sylius.behat.context.hook.doctrine_orm
|
||||
|
||||
- sylius.behat.context.transform.lexical
|
||||
- sylius.behat.context.transform.shared_storage
|
||||
- sylius.behat.context.transform.addressing
|
||||
- sylius.behat.context.transform.customer
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
@promotion
|
||||
Feature: Deleting a promotion
|
||||
In order to remove test, obsolete or incorrect promotions
|
||||
As an Administrator
|
||||
I want to be able to remove promotions
|
||||
|
||||
Background:
|
||||
Given the store operates on a single channel in "France"
|
||||
And there is a promotion "Holiday promotion"
|
||||
|
||||
@todo
|
||||
Scenario: Deleted promotion should disappear from the registry
|
||||
When I delete promotion "Holiday promotion"
|
||||
Then it should not exist in the registry
|
||||
|
|
@ -12,4 +12,4 @@ Feature: Deleting a coupon
|
|||
Scenario: Deleted coupon should disappear from the registry
|
||||
When I delete "Santa's Gift" coupon
|
||||
Then I should be notified that it has been successfully deleted
|
||||
And this coupon should no longer exist in the registry
|
||||
And this coupon should no longer exist in the coupon registry
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
@promotion
|
||||
Feature: Deleting a promotion
|
||||
In order to remove test, obsolete or incorrect promotions
|
||||
As an Administrator
|
||||
I want to be able to delete a promotion from the registry
|
||||
|
||||
Background:
|
||||
Given the store operates on a single channel in "France"
|
||||
And there is a promotion "Christmas sale"
|
||||
|
||||
@domain
|
||||
Scenario: Deleted promotion should disappear from the registry
|
||||
When I delete promotion "Christmas sale"
|
||||
Then I should be notified that it has been successfully deleted
|
||||
And this promotion should no longer exist in the promotion registry
|
||||
|
|
@ -2,21 +2,21 @@
|
|||
Feature: Prevent deletion of promotions applied to order
|
||||
In order to maintain proper order history
|
||||
As an Administrator
|
||||
I want to be prevented from deleting promotions which have been applied to an order
|
||||
I want to be prevented from deleting a promotion which has been applied to an order
|
||||
|
||||
Background:
|
||||
Given the store operates on a single channel in "France"
|
||||
And the store ships everywhere for free
|
||||
And the store allows paying with "Cash on Delivery"
|
||||
And the store has a product "PHP Mug" priced at "€12.00"
|
||||
And there is a promotion "Holiday promotion"
|
||||
And there is a promotion "Christmas sale"
|
||||
And it gives "€3.00" fixed discount to every order
|
||||
And the customer "john.doe@gmail.com" placed an order "#00000022"
|
||||
And the customer chose "Free" shipping method to "France" with "Cash on Delivery" payment
|
||||
And the customer bought single "PHP Mug"
|
||||
|
||||
@todo
|
||||
@domain
|
||||
Scenario: Being unable to delete a promotion that was applied to an order
|
||||
When I delete promotion "Holiday promotion"
|
||||
When I try to delete promotion "Christmas sale"
|
||||
Then I should be notified that it is in use and cannot be deleted
|
||||
And this promotion should still exist in the registry
|
||||
And promotion "Christmas sale" should still exist in the registry
|
||||
|
|
@ -78,7 +78,7 @@ final class PromotionContext implements Context
|
|||
}
|
||||
|
||||
/**
|
||||
* @Then /^([^"]+ should no longer) exist in the registry$/
|
||||
* @Then /^([^"]+ should no longer) exist in the coupon registry$/
|
||||
*/
|
||||
public function couponShouldNotExistInTheRegistry($couponId)
|
||||
{
|
||||
|
|
@ -104,23 +104,34 @@ final class PromotionContext implements Context
|
|||
}
|
||||
|
||||
/**
|
||||
* @When /^I delete (promotion "([^"]+)")$/
|
||||
* @When /^I try to delete (promotion "([^"]+)")$/
|
||||
*/
|
||||
public function iDeletePromotion(PromotionInterface $promotion)
|
||||
public function iTryToDeletePromotion(PromotionInterface $promotion)
|
||||
{
|
||||
try {
|
||||
$this->promotionRepository->remove($promotion);
|
||||
|
||||
throw new \Exception(sprintf('Promotion "%s" has been removed, but it should not.', $promotion->getName()));
|
||||
} catch (ForeignKeyConstraintViolationException $exception) {
|
||||
$this->sharedStorage->set('exception', $exception);
|
||||
$this->sharedStorage->set('last_exception', $exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then :it should not exist in the registry
|
||||
* @When /^I delete (promotion "([^"]+)")$/
|
||||
*/
|
||||
public function promotionShouldNotExistInTheRegistry(PromotionInterface $promotion)
|
||||
public function iDeletePromotion(PromotionInterface $promotion)
|
||||
{
|
||||
expect($this->promotionRepository->find($promotion->getId()))->toBe(null);
|
||||
$this->sharedStorage->set('promotion_id', $promotion->getId());
|
||||
$this->promotionRepository->remove($promotion);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Then /^([^"]+ should no longer) exist in the promotion registry$/
|
||||
*/
|
||||
public function promotionShouldNotExistInTheRegistry($promotionId)
|
||||
{
|
||||
expect($this->promotionRepository->find($promotionId))->toBe(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -143,26 +143,27 @@ class PromotionContextSpec extends ObjectBehavior
|
|||
;
|
||||
}
|
||||
|
||||
function it_removes_a_promotion(PromotionRepositoryInterface $promotionRepository, PromotionInterface $promotion)
|
||||
{
|
||||
function it_removes_a_promotion(
|
||||
PromotionRepositoryInterface $promotionRepository,
|
||||
SharedStorageInterface $sharedStorage,
|
||||
PromotionInterface $promotion
|
||||
) {
|
||||
$promotion->getId()->willReturn(5);
|
||||
$promotionRepository->find(5)->willReturn($promotion);
|
||||
$sharedStorage->set('promotion_id', 5)->shouldBeCalled();
|
||||
$promotionRepository->remove($promotion)->shouldBeCalled();
|
||||
|
||||
$this->iDeletePromotion($promotion);
|
||||
}
|
||||
|
||||
function it_checks_whether_a_promotion_does_not_exist_in_the_registry(
|
||||
PromotionRepositoryInterface $promotionRepository,
|
||||
PromotionInterface $promotion
|
||||
PromotionRepositoryInterface $promotionRepository
|
||||
) {
|
||||
$promotion->getId()->willReturn(5);
|
||||
$promotionRepository->find(5)->willReturn(null);
|
||||
|
||||
$this->promotionShouldNotExistInTheRegistry($promotion);
|
||||
$this->promotionShouldNotExistInTheRegistry(5);
|
||||
}
|
||||
|
||||
function it_throws_exception_when_a_promotion_is_found_when_it_should_not(
|
||||
function it_throws_exception_when_a_promotion_is_found_but_it_should_not_exist(
|
||||
PromotionRepositoryInterface $promotionRepository,
|
||||
PromotionInterface $promotion
|
||||
) {
|
||||
|
|
@ -171,7 +172,7 @@ class PromotionContextSpec extends ObjectBehavior
|
|||
|
||||
$this
|
||||
->shouldThrow(NotEqualException::class)
|
||||
->during('promotionShouldNotExistInTheRegistry', [$promotion])
|
||||
->during('promotionShouldNotExistInTheRegistry', [5])
|
||||
;
|
||||
}
|
||||
|
||||
|
|
@ -185,7 +186,7 @@ class PromotionContextSpec extends ObjectBehavior
|
|||
$this->promotionShouldStillExistInTheRegistry($promotion);
|
||||
}
|
||||
|
||||
function it_throws_exception_when_a_promotion_is_not_found_when_it_should(
|
||||
function it_throws_exception_when_a_promotion_is_not_found_but_it_should_exist(
|
||||
PromotionRepositoryInterface $promotionRepository,
|
||||
PromotionInterface $promotion
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -220,38 +220,4 @@ class OrderContextSpec extends ObjectBehavior
|
|||
|
||||
$this->theCustomerBoughtSingleUsing($product, $coupon);
|
||||
}
|
||||
|
||||
function it_adds_single_item_by_customer_and_applies_a_promotion(
|
||||
FactoryInterface $orderItemFactory,
|
||||
OrderInterface $order,
|
||||
OrderItemInterface $item,
|
||||
OrderItemQuantityModifierInterface $itemQuantityModifier,
|
||||
ProductInterface $product,
|
||||
PromotionInterface $promotion,
|
||||
SharedStorageInterface $sharedStorage,
|
||||
ProductVariantInterface $variant,
|
||||
OrderRecalculatorInterface $orderRecalculator,
|
||||
ObjectManager $objectManager
|
||||
) {
|
||||
$sharedStorage->get('order')->willReturn($order);
|
||||
|
||||
$orderItemFactory->createNew()->willReturn($item);
|
||||
|
||||
$product->getMasterVariant()->willReturn($variant);
|
||||
$product->getPrice()->willReturn(1234);
|
||||
|
||||
$itemQuantityModifier->modify($item, 1)->shouldBeCalled();
|
||||
|
||||
$item->setVariant($variant)->shouldBeCalled();
|
||||
$item->setUnitPrice(1234)->shouldBeCalled();
|
||||
|
||||
$promotion->setUsed(1)->shouldBeCalled();
|
||||
$order->addPromotion($promotion)->shouldBeCalled();
|
||||
$order->addItem($item)->shouldBeCalled();
|
||||
|
||||
$orderRecalculator->recalculate($order)->shouldBeCalled();
|
||||
$objectManager->flush()->shouldBeCalled();
|
||||
|
||||
$this->theCustomerBoughtSingleWhile($product, $promotion);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@
|
|||
<many-to-many field="promotions" target-entity="Sylius\Component\Promotion\Model\PromotionInterface">
|
||||
<join-table name="sylius_promotion_order">
|
||||
<join-columns>
|
||||
<join-column name="order_id" referenced-column-name="id" on-delete="CASCADE"/>
|
||||
<join-column name="order_id" referenced-column-name="id" on-delete="CASCADE" />
|
||||
</join-columns>
|
||||
<inverse-join-columns>
|
||||
<join-column name="promotion_id" referenced-column-name="id" />
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue