[Core][Order][Behat] Minor fixes for expired orders and carts

This commit is contained in:
Mateusz Zalewski 2016-10-07 11:15:39 +02:00
parent e50e9a36d1
commit bbba066e3e
7 changed files with 19 additions and 18 deletions

View file

@ -1,6 +1,6 @@
@shopping_cart
Feature: Deleting expired carts automatically
In order to get rid of started but not finished orders
In order to remove started but not finished orders after 2 days of idleness
As an Administrator
I want to have expired carts automatically deleted

View file

@ -1,6 +1,6 @@
@managing_orders
Feature: Cancelling unpaid orders automatically
In order to get rid of completed but not paid orders
In order to get rid of completed orders after 5 days of being unpaid
As an Administrator
I want to have unpaid orders automatically cancelled
@ -12,16 +12,16 @@ Feature: Cancelling unpaid orders automatically
@domain
Scenario: Having order cancelled after 10 days of being unpaid
And there is a customer "john.doe@gmail.com" that placed an order "#00000022"
Given there is a customer "john.doe@gmail.com" that placed an order "#00000022"
And the customer bought a single "PHP T-Shirt"
And the customer chose "Free" shipping method to "United States" with "Paypal Express Checkout" payment
And this order has not been paid for 10 days
When this order has not been paid for 10 days
Then this order should be automatically cancelled
@domain
Scenario: Having unpaid order not cancelled if expiration time has not been reached
And there is a customer "john.doe@gmail.com" that placed an order "#00000022"
Given there is a customer "john.doe@gmail.com" that placed an order "#00000022"
And the customer bought a single "PHP T-Shirt"
And the customer chose "Free" shipping method to "United States" with "Paypal Express Checkout" payment
And this order has not been paid for 2 days
When this order has not been paid for 2 days
Then this order should not be cancelled

View file

@ -56,12 +56,10 @@ final class CartContext implements Context
/**
* @Given /^(?:|he|she) abandoned (the cart) (\d+) (day|days|hour|hours) ago$/
*/
public function heAbandonedHisCartHoursAgo(OrderInterface $cart, $amount, $time)
public function theyAbandonedTheirCart(OrderInterface $cart, $amount, $time)
{
$cart->setUpdatedAt(new \DateTime('-'.$amount.' '.$time));
$this->orderManager->flush();
$this->expiredCartsRemover->remove();
}
/**
@ -69,6 +67,8 @@ final class CartContext implements Context
*/
public function thisCartShouldBeAutomaticallyDeleted(OrderInterface $cart)
{
$this->expiredCartsRemover->remove();
Assert::null(
$cart->getId(),
'This cart should not exist in registry but it does.'
@ -80,6 +80,8 @@ final class CartContext implements Context
*/
public function thisCartShouldNotBeDeleted(OrderInterface $cart)
{
$this->expiredCartsRemover->remove();
Assert::notNull(
$cart->getId(),
'This cart should be in registry but it is not.'

View file

@ -557,8 +557,8 @@ final class OrderContext implements Context
/**
* @param CustomerInterface $customer
* @param ChannelInterface|null $channel
* @param null $currencyCode
* @param null $localeCode
* @param string|null $currencyCode
* @param string|null $localeCode
*
* @return OrderInterface
*/
@ -586,7 +586,7 @@ final class OrderContext implements Context
}
/**
* @param $count
* @param int $count
*
* @return CustomerInterface[]
*/

View file

@ -103,9 +103,6 @@ sylius_order:
order_item_unit:
classes:
model: Sylius\Component\Core\Model\OrderItemUnit
expiration:
cart: 2 days
order: 5 days
sylius_payment:
resources:

View file

@ -218,9 +218,10 @@ class Configuration implements ConfigurationInterface
$node
->children()
->arrayNode('expiration')
->addDefaultsIfNotSet()
->children()
->scalarNode('cart')->cannotBeEmpty()->end()
->scalarNode('order')->cannotBeEmpty()->end()
->scalarNode('cart')->defaultValue('2 days')->cannotBeEmpty()->end()
->scalarNode('order')->defaultValue('5 days')->cannotBeEmpty()->end()
->end()
->end()
->end()

View file

@ -12,6 +12,7 @@
namespace spec\Sylius\Component\Order\Remover;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Order\Model\OrderInterface;
use Sylius\Component\Order\Remover\ExpiredCartsRemover;
use Sylius\Component\Order\Remover\ExpiredCartsRemoverInterface;
@ -44,7 +45,7 @@ final class ExpiredCartsRemoverSpec extends ObjectBehavior
OrderInterface $firstCart,
OrderInterface $secondCart
) {
$orderRepository->findCartsNotModifiedSince(new \DateTime('-2 months'))->willReturn([
$orderRepository->findCartsNotModifiedSince(Argument::type('\DateTime'))->willReturn([
$firstCart,
$secondCart
]);