[Behat] Delete adjustments with an order

This commit is contained in:
Łukasz Chruściel 2016-02-24 16:03:12 +01:00
parent 4a0fb3da6b
commit ee2aaea9cf
6 changed files with 79 additions and 7 deletions

View file

@ -156,6 +156,7 @@
<argument type="service" id="sylius.factory.payment" container="symfony" />
<argument type="service" id="sylius.factory.order_item" container="symfony" />
<argument type="service" id="sylius.order_item_quantity_modifier" container="symfony" />
<argument type="service" id="sylius.order_processing.shipping_processor" container="symfony" />
<argument type="service" id="doctrine.orm.entity_manager" container="symfony" />
<tag name="sylius.behat.context" />
</service>
@ -295,6 +296,7 @@
<argument type="service" id="sylius.repository.order" container="symfony"/>
<argument type="service" id="sylius.repository.order_item" container="symfony"/>
<argument type="service" id="sylius.repository.address" container="symfony"/>
<argument type="service" id="sylius.repository.adjustment" container="symfony"/>
<tag name="sylius.behat.context" />
</service>

View file

@ -33,7 +33,7 @@ Feature: Deleting an order
When I delete the order "#00000022"
Then the order item with product "PHP T-Shirt" should not exist
@todo
@domain
Scenario: Order adjustments are deleted together with an order
When I delete the order "#00000022"
Then adjustments of this order should not exist

View file

@ -37,16 +37,27 @@ final class OrderContext implements Context
*/
private $addressRepository;
/**
* @var RepositoryInterface
*/
private $adjustmentRepository;
/**
* @param OrderRepositoryInterface $orderRepository
* @param RepositoryInterface $orderItemRepository
* @param RepositoryInterface $addressRepository
* @param RepositoryInterface $adjustmentRepository
*/
public function __construct(OrderRepositoryInterface $orderRepository, RepositoryInterface $orderItemRepository, RepositoryInterface $addressRepository)
{
public function __construct(
OrderRepositoryInterface $orderRepository,
RepositoryInterface $orderItemRepository,
RepositoryInterface $addressRepository,
RepositoryInterface $adjustmentRepository
) {
$this->orderRepository = $orderRepository;
$this->orderItemRepository = $orderItemRepository;
$this->addressRepository = $addressRepository;
$this->adjustmentRepository = $adjustmentRepository;
}
/**
@ -98,4 +109,17 @@ final class OrderContext implements Context
expect($billingAddress)->toBe(null);
expect($shippingAddress)->toBe(null);
}
/**
* @Then /^adjustments of ([^"]+) should not exist$/
*/
public function adjustmentShouldNotExistInTheRegistry(OrderInterface $order)
{
$adjustments = $order->getAdjustments();
foreach ($adjustments as $adjustment) {
$adjustment = $this->adjustmentRepository->find($adjustment->getId());
expect($adjustment)->toBe(null);
}
}
}

View file

@ -20,6 +20,7 @@ use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ShippingMethodInterface;
use Sylius\Component\Core\OrderProcessing\OrderShipmentProcessorInterface;
use Sylius\Component\Core\OrderProcessing\ShippingChargesProcessorInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
use Sylius\Component\Payment\Factory\PaymentFactoryInterface;
@ -32,7 +33,6 @@ use Sylius\Component\User\Model\CustomerInterface;
*/
final class OrderContext implements Context
{
/**
* @var SharedStorageInterface
*/
@ -68,19 +68,25 @@ final class OrderContext implements Context
*/
private $itemQuantityModifier;
/**
* @var ShippingChargesProcessorInterface
*/
private $shippingChargesProcessor;
/**
* @var ObjectManager
*/
private $objectManager;
/**
* @param SharedStorageInterface $sharedStorage
* @param OrderRepositoryInterface $orderRepository
* @param FactoryInterface $orderFactory
* @param OrderShipmentProcessorInterface $orderShipmentFactory
* @param PaymentFactoryInterface $paymentFactory
* @param FactoryInterface $orderItemFactory
* @param OrderItemQuantityModifierInterface $itemQuantityModifier
* @param SharedStorageInterface $sharedStorage
* @param ShippingChargesProcessorInterface $shippingChargesProcessor
* @param ObjectManager $objectManager
*/
public function __construct(
@ -91,6 +97,7 @@ final class OrderContext implements Context
PaymentFactoryInterface $paymentFactory,
FactoryInterface $orderItemFactory,
OrderItemQuantityModifierInterface $itemQuantityModifier,
ShippingChargesProcessorInterface $shippingChargesProcessor,
ObjectManager $objectManager
) {
$this->sharedStorage = $sharedStorage;
@ -100,6 +107,7 @@ final class OrderContext implements Context
$this->paymentFactory = $paymentFactory;
$this->orderItemFactory = $orderItemFactory;
$this->itemQuantityModifier = $itemQuantityModifier;
$this->shippingChargesProcessor = $shippingChargesProcessor;
$this->objectManager = $objectManager;
}
@ -135,6 +143,8 @@ final class OrderContext implements Context
$this->orderShipmentFactory->processOrderShipment($order);
$order->getShipments()->first()->setMethod($shippingMethod);
$this->shippingChargesProcessor->applyShippingCharges($order);
$payment = $this->paymentFactory->createWithAmountAndCurrency($order->getTotal(), $order->getCurrency());
$payment->setMethod($paymentMethod);

View file

@ -18,6 +18,7 @@ use PhpSpec\Exception\Example\NotEqualException;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Core\Model\AddressInterface;
use Sylius\Component\Core\Model\AdjustmentInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\Model\ProductInterface;
@ -33,9 +34,10 @@ class OrderContextSpec extends ObjectBehavior
function let(
OrderRepositoryInterface $orderRepository,
RepositoryInterface $orderItemRepository,
RepositoryInterface $addressRepository
RepositoryInterface $addressRepository,
RepositoryInterface $adjustmentRepository
) {
$this->beConstructedWith($orderRepository, $orderItemRepository, $addressRepository);
$this->beConstructedWith($orderRepository, $orderItemRepository, $addressRepository, $adjustmentRepository);
}
function it_is_initializable()
@ -158,4 +160,32 @@ class OrderContextSpec extends ObjectBehavior
$this->shouldThrow(NotEqualException::class)->during('addressesShouldNotExistInTheRegistry', [$order]);
}
function it_checks_if_an_order_adjustments_exists_in_repository(
RepositoryInterface $adjustmentRepository,
OrderInterface $order,
AdjustmentInterface $adjustment
) {
$order->getAdjustments()->willReturn([$adjustment]);
$adjustment->getId()->willReturn(1);
$adjustmentRepository->find(1)->willReturn(null);
$this->adjustmentShouldNotExistInTheRegistry($order);
}
function it_throws_an_exception_if_adjustments_still_exist(
RepositoryInterface $adjustmentRepository,
OrderInterface $order,
AdjustmentInterface $adjustment
) {
$order->getAdjustments()->willReturn([$adjustment]);
$adjustment->getId()->willReturn(1);
$adjustmentRepository->find(1)->willReturn($adjustment);
$this->shouldThrow(NotEqualException::class)->during('adjustmentShouldNotExistInTheRegistry', [$order]);
}
}

View file

@ -27,6 +27,7 @@ use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Model\ShipmentInterface;
use Sylius\Component\Core\Model\ShippingMethodInterface;
use Sylius\Component\Core\OrderProcessing\OrderShipmentProcessorInterface;
use Sylius\Component\Core\OrderProcessing\ShippingChargesProcessorInterface;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
@ -47,6 +48,7 @@ class OrderContextSpec extends ObjectBehavior
PaymentFactoryInterface $paymentFactory,
FactoryInterface $orderItemFactory,
OrderItemQuantityModifierInterface $itemQuantityModifier,
ShippingChargesProcessorInterface $chargesProcessor,
ObjectManager $objectManager
) {
$this->beConstructedWith(
@ -57,6 +59,7 @@ class OrderContextSpec extends ObjectBehavior
$paymentFactory,
$orderItemFactory,
$itemQuantityModifier,
$chargesProcessor,
$objectManager
);
}
@ -106,6 +109,7 @@ class OrderContextSpec extends ObjectBehavior
PaymentMethodInterface $paymentMethod,
SharedStorageInterface $sharedStorage,
ShipmentInterface $shipment,
ShippingChargesProcessorInterface $chargesProcessor,
ShippingMethodInterface $shippingMethod,
ObjectManager $objectManager
) {
@ -128,6 +132,8 @@ class OrderContextSpec extends ObjectBehavior
$objectManager->flush()->shouldBeCalled();
$chargesProcessor->applyShippingCharges($order)->shouldBeCalled();
$this->theCustomerChoseShippingToWithPayment($shippingMethod, $address, $paymentMethod);
}