From 50d50d3b91ac7b7799192b63fe82b46ff65c150d Mon Sep 17 00:00:00 2001 From: gmorel Date: Wed, 28 Aug 2013 09:33:33 +0200 Subject: [PATCH] WIP Coupon Refactor : creating dedicated reusable module for Constraints Adding ConstraintManager Secured : - Effects : RemoveXPercent + RemoveXAmount - Validators : all except ModelParam (need CustomerModelParam, AreaModelParam, CountryModelParam ?) - Conditions : AvailableForTotalAmount --- .../Rule/AvailableForTotalAmount.php | 24 ++- .../Constraint/Rule/AvailableForXArticles.php | 139 +++++++++++++++++- .../Constraint/Rule/CouponRuleAbstract.php | 26 ++-- .../Constraint/Rule/CouponRuleInterface.php | 5 +- .../lib/Thelia/Coupon/Type/CouponAbstract.php | 5 +- .../Thelia/Coupon/Type/CouponInterface.php | 7 +- .../lib/Thelia/Coupon/Type/RemoveXPercent.php | 7 +- .../Constraint/ConstraintManagerTest.php | 75 +--------- .../Rule/AvailableForTotalAmountTest.php | 91 +++++++----- .../Rule/AvailableForXArticlesTest.php | 87 ++++++----- .../Tests/Constraint/Rule/OperatorsTest.php | 54 ++++--- .../Validator/QuantityParamTest.php | 3 +- .../Thelia/Tests/Coupon/CouponFactoryTest.php | 4 +- .../Thelia/Tests/Coupon/CouponManagerTest.php | 10 +- .../Tests/Coupon/CouponRuleCollectionTest.php | 4 +- .../Type/RemoveXAmountForCategoryYTest.php | 7 + .../Tests/Coupon/Type/RemoveXAmountTest.php | 14 +- .../Type/RemoveXPercentForCategoryYTest.php | 7 + .../Tests/Coupon/Type/RemoveXPercentTest.php | 46 +++--- 19 files changed, 350 insertions(+), 265 deletions(-) diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmount.php b/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmount.php index 704df073e..a6e5d60ee 100644 --- a/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmount.php +++ b/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmount.php @@ -61,14 +61,16 @@ class AvailableForTotalAmount extends CouponRuleAbstract /** * Constructor * - * @param array $validators Array of RuleValidator - * validating $paramsToValidate against + * @param CouponAdapterInterface $adapter allowing to gather + * all necessary Thelia variables + * @param array $validators Array of RuleValidator + * validating $paramsToValidate against * * @throws \Thelia\Exception\InvalidRuleException */ - public function __construct(array $validators) + public function __construct(CouponAdapterInterface $adapter, array $validators) { - parent::__construct($validators); + parent::__construct($adapter, $validators); if (isset($validators[self::PARAM1_PRICE]) && $validators[self::PARAM1_PRICE] instanceof RuleValidator @@ -77,7 +79,6 @@ class AvailableForTotalAmount extends CouponRuleAbstract } else { throw new InvalidRuleException(get_class()); } - } @@ -109,8 +110,6 @@ class AvailableForTotalAmount extends CouponRuleAbstract $this->checkBackOfficeInputsOperators(); - - return $this->isPriceValid($price->getPrice()); } @@ -129,9 +128,9 @@ class AvailableForTotalAmount extends CouponRuleAbstract throw new InvalidRuleValueException(get_class(), self::PARAM1_PRICE); } - $quantity = $this->paramsToValidate[self::PARAM1_PRICE]; + $price = $this->paramsToValidate[self::PARAM1_PRICE]; - return $this->isPriceValid($quantity); + return $this->isPriceValid($price); } /** @@ -157,15 +156,12 @@ class AvailableForTotalAmount extends CouponRuleAbstract /** * Generate current Rule param to be validated from adapter * - * @param CouponAdapterInterface $adapter allowing to gather - * all necessary Thelia variables - * * @return $this */ - protected function setParametersToValidate(CouponAdapterInterface $adapter) + protected function setParametersToValidate() { $this->paramsToValidate = array( - self::PARAM1_PRICE => $adapter->getCartTotalPrice() + self::PARAM1_PRICE => $this->adapter->getCartTotalPrice() ); return $this; diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForXArticles.php b/core/lib/Thelia/Constraint/Rule/AvailableForXArticles.php index b38a53ce4..1a8e17da2 100644 --- a/core/lib/Thelia/Constraint/Rule/AvailableForXArticles.php +++ b/core/lib/Thelia/Constraint/Rule/AvailableForXArticles.php @@ -23,6 +23,11 @@ namespace Thelia\Constraint\Rule; +use Thelia\Constraint\Validator\QuantityParam; +use Thelia\Constraint\Validator\RuleValidator; +use Thelia\Coupon\CouponAdapterInterface; +use Thelia\Exception\InvalidRuleValueException; + /** * Created by JetBrains PhpStorm. * Date: 8/19/13 @@ -36,15 +41,90 @@ namespace Thelia\Constraint\Rule; */ class AvailableForXArticles extends CouponRuleAbstract { + /** Rule 1st parameter : price */ + CONST PARAM1_QUANTITY = 'quantity'; + + /** @var array Available Operators (Operators::CONST) */ + protected $availableOperators = array( + Operators::INFERIOR, + Operators::EQUAL, + Operators::SUPERIOR, + ); + + /** @var RuleValidator Quantity Validator */ + protected $quantityValidator = null; + + /** + * Constructor + * + * @param CouponAdapterInterface $adapter allowing to gather + * all necessary Thelia variables + * @param array $validators Array of RuleValidator + * validating $paramsToValidate against + * + * @throws InvalidRuleException + */ + public function __construct(CouponAdapterInterface $adapter, array $validators) + { + parent::__construct($adapter, $validators); + + if (isset($validators[self::PARAM1_QUANTITY]) + && $validators[self::PARAM1_QUANTITY] instanceof RuleValidator + ) { + $this->quantityValidator = $validators[self::PARAM1_QUANTITY]; + } else { + throw new InvalidRuleException(get_class()); + } + + $this->adapter = $adapter; + } /** * Check if backoffice inputs are relevant or not * + * @throws InvalidRuleOperatorException if Operator is not allowed + * @throws InvalidRuleValueException if Value is not allowed * @return bool */ public function checkBackOfficeInput() { - // TODO: Implement checkBackOfficeInput() method. + if (!isset($this->validators) + || empty($this->validators) + ||!isset($this->validators[self::PARAM1_QUANTITY]) + ||!isset($this->validators[self::PARAM1_QUANTITY]) + ) { + throw new InvalidRuleValueException(get_class(), self::PARAM1_QUANTITY); + } + + /** @var RuleValidator $ruleValidator */ + $ruleValidator = $this->validators[self::PARAM1_QUANTITY]; + /** @var QuantityParam $quantity */ + $quantity = $ruleValidator->getParam(); + + if (!$quantity instanceof QuantityParam) { + throw new InvalidRuleValueException(get_class(), self::PARAM1_QUANTITY); + } + + $this->checkBackOfficeInputsOperators(); + + return $this->isQuantityValid($quantity->getInteger()); + } + + /** + * Generate current Rule param to be validated from adapter + * + * @param CouponAdapterInterface $adapter allowing to gather + * all necessary Thelia variables + * + * @return $this + */ + protected function setParametersToValidate() + { + $this->paramsToValidate = array( + self::PARAM1_QUANTITY => $this->adapter->getCartTotalPrice() + ); + + return $this; } /** @@ -57,4 +137,61 @@ class AvailableForXArticles extends CouponRuleAbstract // TODO: Implement checkCheckoutInput() method. } + /** + * Check if a quantity is valid + * + * @param float $quantity Quantity to check + * + * @throws InvalidRuleValueException if Value is not allowed + * @return bool + */ + protected function isQuantityValid($quantity) + { + $quantityValidator = $this->quantityValidator; + try { + $quantityValidator->getParam()->compareTo($quantity); + } catch(\InvalidArgumentException $e) { + throw new InvalidRuleValueException(get_class(), self::PARAM1_QUANTITY); + } + + return true; + } + + /** + * Get I18n name + * + * @return string + */ + public function getName() + { + return $this->adapter + ->getTranslator() + ->trans('Number of articles in cart', null, 'constraint'); + } + + /** + * Get I18n tooltip + * + * @return string + */ + public function getToolTip() + { + $i18nOperator = Operators::getI18n( + $this->adapter, $this->priceValidator->getOperator() + ); + + $toolTip = $this->adapter + ->getTranslator() + ->trans( + 'If cart products quantity is %operator% %quantity%', + array( + '%operator%' => $i18nOperator, + '%quantity%' => $this->quantityValidator->getParam()->getInteger(), + ), + 'constraint' + ); + + return $toolTip; + } + } \ No newline at end of file diff --git a/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php b/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php index 9fbcc21fc..d7a966a13 100644 --- a/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php +++ b/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php @@ -57,6 +57,9 @@ abstract class CouponRuleAbstract implements CouponRuleInterface /** @var array Parameters to be validated */ protected $paramsToValidate = array(); + /** @var CouponAdapterInterface Provide necessary value from Thelia */ + protected $adapter = null; + /** * Constructor * Ex: @@ -70,14 +73,16 @@ abstract class CouponRuleAbstract implements CouponRuleInterface * Param 2 : * $paramsToValidate[AvailableForTotalAmount::PARAM1_PRICE] = 9 * - * @param array $validators Array of RuleValidator - * validating $paramsToValidate against - * - * @throws InvalidRuleException + * @param CouponAdapterInterface $adapter allowing to gather + * all necessary Thelia variables + * @param array $validators Array of RuleValidator + * validating $paramsToValidate against */ - public function __construct(array $validators) + public function __construct(CouponAdapterInterface $adapter, array $validators) { $this->setValidators($validators); + $this->adapter = $adapter; + $this->setParametersToValidate($this->adapter); } /** @@ -104,14 +109,10 @@ abstract class CouponRuleAbstract implements CouponRuleInterface /** * Check if the current Checkout matches this condition * - * @param CouponAdapterInterface $adapter allowing to gather - * all necessary Thelia variables - * * @return bool */ - public function isMatching(CouponAdapterInterface $adapter) + public function isMatching() { - $this->setParametersToValidate($adapter); $this->checkBackOfficeInput(); $this->checkCheckoutInput(); @@ -165,13 +166,10 @@ abstract class CouponRuleAbstract implements CouponRuleInterface /** * Generate current Rule param to be validated from adapter * - * @param CouponAdapterInterface $adapter allowing to gather - * all necessary Thelia variables - * * @throws \Thelia\Exception\NotImplementedException * @return $this */ - protected function setParametersToValidate(CouponAdapterInterface $adapter) + protected function setParametersToValidate() { throw new \Thelia\Exception\NotImplementedException(); } diff --git a/core/lib/Thelia/Constraint/Rule/CouponRuleInterface.php b/core/lib/Thelia/Constraint/Rule/CouponRuleInterface.php index 9e75c7fe1..ea0ba42d9 100644 --- a/core/lib/Thelia/Constraint/Rule/CouponRuleInterface.php +++ b/core/lib/Thelia/Constraint/Rule/CouponRuleInterface.php @@ -55,12 +55,9 @@ interface CouponRuleInterface /** * Check if the current Checkout matches this condition * - * @param CouponAdapterInterface $adapter allowing to gather - * all necessary Thelia variables - * * @return bool */ - public function isMatching(CouponAdapterInterface $adapter); + public function isMatching(); /** * Return all available Operators for this Rule diff --git a/core/lib/Thelia/Coupon/Type/CouponAbstract.php b/core/lib/Thelia/Coupon/Type/CouponAbstract.php index a5e82c83e..79e0b760c 100644 --- a/core/lib/Thelia/Coupon/Type/CouponAbstract.php +++ b/core/lib/Thelia/Coupon/Type/CouponAbstract.php @@ -168,12 +168,9 @@ abstract class CouponAbstract implements CouponInterface * Return effects generated by the coupon * A negative value * - * @param CouponAdapterInterface $adapter allowing to gather - * all necessary Thelia variables - * * @return float Amount removed from the Total Checkout */ - public function getDiscount(CouponAdapterInterface $adapter) + public function getDiscount() { return $this->amount; } diff --git a/core/lib/Thelia/Coupon/Type/CouponInterface.php b/core/lib/Thelia/Coupon/Type/CouponInterface.php index 334520104..116995496 100644 --- a/core/lib/Thelia/Coupon/Type/CouponInterface.php +++ b/core/lib/Thelia/Coupon/Type/CouponInterface.php @@ -88,16 +88,13 @@ interface CouponInterface * A positive value * * Effects could also affect something else than the final Checkout price - * CouponAdapter could be use to directly pass a Session value + * CouponAdapter $adapter could be use to directly pass a Session value * some would wish to modify * Hence affecting a wide variety of Thelia elements * - * @param CouponAdapterInterface $adapter allowing to gather - * all necessary Thelia variables - * * @return float Amount removed from the Total Checkout */ - public function getDiscount(CouponAdapterInterface $adapter); + public function getDiscount(); /** * Return condition to validate the Coupon or not diff --git a/core/lib/Thelia/Coupon/Type/RemoveXPercent.php b/core/lib/Thelia/Coupon/Type/RemoveXPercent.php index 5d1d14b63..6279c3536 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveXPercent.php +++ b/core/lib/Thelia/Coupon/Type/RemoveXPercent.php @@ -92,14 +92,11 @@ class RemoveXPercent extends CouponAbstract * Return effects generated by the coupon * A negative value * - * @param CouponAdapterInterface $adapter allowing to gather - * all necessary Thelia variables - * * @throws \Thelia\Exception\MissingAdapterException * @throws \InvalidArgumentException * @return float */ - public function getDiscount(CouponAdapterInterface $adapter) + public function getDiscount() { if ($this->percent >= 100) { throw new \InvalidArgumentException( @@ -107,7 +104,7 @@ class RemoveXPercent extends CouponAbstract ); } - $basePrice = $adapter->getCartTotalPrice(); + $basePrice = $this->adapter->getCartTotalPrice(); return $basePrice * (( $this->percent ) / 100); } diff --git a/core/lib/Thelia/Tests/Constraint/ConstraintManagerTest.php b/core/lib/Thelia/Tests/Constraint/ConstraintManagerTest.php index 770746ba1..08389ef9e 100644 --- a/core/lib/Thelia/Tests/Constraint/ConstraintManagerTest.php +++ b/core/lib/Thelia/Tests/Constraint/ConstraintManagerTest.php @@ -56,36 +56,11 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase - /** - * Generate valid CouponRuleInterfaces - * - * @return array Array of CouponRuleInterface - */ - public static function generateValidRules() + public function incompleteTest() { - $rule1 = new AvailableForTotalAmount( - array( - AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( - Operators::SUPERIOR, - new PriceParam( - , 40.00, 'EUR' - ) - ) - ) + $this->markTestIncomplete( + 'This test has not been implemented yet.' ); - $rule2 = new AvailableForTotalAmount( - array( - AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( - Operators::INFERIOR, - new PriceParam( - , 400.00, 'EUR' - ) - ) - ) - ); - $rules = new CouponRuleCollection(array($rule1, $rule2)); - - return $rules; } /** @@ -95,48 +70,4 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase protected function tearDown() { } - - /** - * Generate a fake Adapter - * - * @param array $coupons Coupons - * @param float $cartTotalPrice Cart total price - * @param float $checkoutTotalPrice Checkout total price - * @param float $postagePrice Checkout postage price - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - public function generateFakeAdapter(array $coupons, $cartTotalPrice, $checkoutTotalPrice, $postagePrice = 6.00) - { - $stubCouponBaseAdapter = $this->getMock( - 'Thelia\Coupon\CouponBaseAdapter', - array( - 'getCurrentCoupons', - 'getCartTotalPrice', - 'getCheckoutTotalPrice', - 'getCheckoutPostagePrice' - ), - array() - ); - - $stubCouponBaseAdapter->expects($this->any()) - ->method('getCurrentCoupons') - ->will($this->returnValue(($coupons))); - - // Return Cart product amount = $cartTotalPrice euros - $stubCouponBaseAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue($cartTotalPrice)); - - // Return Checkout amount = $checkoutTotalPrice euros - $stubCouponBaseAdapter->expects($this->any()) - ->method('getCheckoutTotalPrice') - ->will($this->returnValue($checkoutTotalPrice)); - - $stubCouponBaseAdapter->expects($this->any()) - ->method('getCheckoutPostagePrice') - ->will($this->returnValue($postagePrice)); - - return $stubCouponBaseAdapter; - } } diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountTest.php b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountTest.php index 05e507863..303970e90 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountTest.php @@ -50,6 +50,8 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { + /** @var CouponAdapterInterface $stubTheliaAdapter */ + $stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); } /** @@ -62,11 +64,11 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase /** @var CouponAdapterInterface $stubTheliaAdapter */ $stubTheliaAdapter = $this->getMock( 'CouponBaseAdapter', - array('getCheckoutTotalPrice'), + array('getCartTotalPrice'), array() ); $stubTheliaAdapter->expects($this->any()) - ->method('getCheckoutTotalPrice') + ->method('getCartTotalPrice') ->will($this->returnValue(421.23)); return $stubTheliaAdapter; @@ -79,21 +81,20 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase */ public function testValidBackOfficeInput() { - /** @var CouponAdapterInterface $stubTheliaAdapter */ - $stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); + $adapter = new CouponBaseAdapter(); $validators = array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::SUPERIOR, new PriceParam( - , 421.23, 'EUR' + $adapter, 421.23, 'EUR' ) ) ); $validated = array( - AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice() + AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice() ); - $rule = new AvailableForTotalAmount($validators, $validated); + $rule = new AvailableForTotalAmount($adapter, $validators, $validated); $expected = true; $actual = $rule->checkBackOfficeInput(); @@ -108,22 +109,21 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase */ public function testInValidBackOfficeInputOperator() { - /** @var CouponAdapterInterface $stubTheliaAdapter */ - $stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); + $adapter = new CouponBaseAdapter(); $validators = array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( 'X', new PriceParam( - , 421.23, 'EUR' + $adapter, 421.23, 'EUR' ) ) ); $validated = array( - AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice() + AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice() ); - $rule = new AvailableForTotalAmount($validators, $validated); + $rule = new AvailableForTotalAmount($adapter, $validators, $validated); $expected = false; $actual = $rule->checkBackOfficeInput(); @@ -138,8 +138,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase */ public function testInValidBackOfficeInputValue() { - /** @var CouponAdapterInterface $stubTheliaAdapter */ - $stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); + $adapter = new CouponBaseAdapter(); $validators = array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( @@ -149,9 +148,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase ); $validated = array( - AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice() + AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice() ); - $rule = new AvailableForTotalAmount($validators, $validated); + $rule = new AvailableForTotalAmount($adapter, $validators, $validated); $expected = false; $actual = $rule->checkBackOfficeInput(); @@ -167,22 +166,21 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase */ public function testValidCheckoutInput() { - /** @var CouponAdapterInterface $stubTheliaAdapter */ - $stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); + $adapter = new CouponBaseAdapter(); $validators = array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::SUPERIOR, new PriceParam( - , 421.23, 'EUR' + $adapter, 421.23, 'EUR' ) ) ); $validated = array( - AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice() + AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice() ); - $rule = new AvailableForTotalAmount($validators, $validated); + $rule = new AvailableForTotalAmount($adapter, $validators, $validated); $expected = true; $actual = $rule->checkCheckoutInput(); @@ -197,11 +195,13 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase */ public function testInValidCheckoutInputValue() { + $adapter = new CouponBaseAdapter(); + $validators = array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::SUPERIOR, new PriceParam( - , 421.23, 'EUR' + $adapter, 421.23, 'EUR' ) ) ); @@ -209,7 +209,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $validated = array( AvailableForTotalAmount::PARAM1_PRICE => 421 ); - $rule = new AvailableForTotalAmount($validators, $validated); + $rule = new AvailableForTotalAmount($adapter, $validators, $validated); $expected = false; $actual = $rule->checkCheckoutInput(); @@ -224,11 +224,13 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase */ public function testInValidCheckoutInputType() { + $adapter = new CouponBaseAdapter(); + $validators = array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::SUPERIOR, new PriceParam( - , 421.23, 'EUR' + $adapter, 421.23, 'EUR' ) ) ); @@ -236,7 +238,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $validated = array( AvailableForTotalAmount::PARAM1_PRICE => 421 ); - $rule = new AvailableForTotalAmount($validators, $validated); + $rule = new AvailableForTotalAmount($adapter, $validators, $validated); $expected = false; $actual = $rule->checkCheckoutInput(); @@ -250,11 +252,13 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase */ public function testMatchingRuleInferior() { + $adapter = new CouponBaseAdapter(); + $validators = array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::INFERIOR, new PriceParam( - , 421.23, 'EUR' + $adapter, 421.23, 'EUR' ) ) ); @@ -262,7 +266,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $validated = array( AvailableForTotalAmount::PARAM1_PRICE => 421.22 ); - $rule = new AvailableForTotalAmount($validators, $validated); + $rule = new AvailableForTotalAmount($adapter, $validators, $validated); $expected = true; $actual = $rule->isMatching(); @@ -276,11 +280,13 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase */ public function testNotMatchingRuleInferior() { + $adapter = new CouponBaseAdapter(); + $validators = array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::INFERIOR, new PriceParam( - , 421.23, 'EUR' + $adapter, 421.23, 'EUR' ) ) ); @@ -288,7 +294,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $validated = array( AvailableForTotalAmount::PARAM1_PRICE => 421.23 ); - $rule = new AvailableForTotalAmount($validators, $validated); + $rule = new AvailableForTotalAmount($adapter, $validators, $validated); $expected = false; $actual = $rule->isMatching(); @@ -302,22 +308,21 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase */ public function testMatchingRuleEqual() { - /** @var CouponAdapterInterface $stubTheliaAdapter */ - $stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); + $adapter = new CouponBaseAdapter(); $validators = array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::EQUAL, new PriceParam( - , 421.23, 'EUR' + $adapter, 421.23, 'EUR' ) ) ); $validated = array( - AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice() + AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice() ); - $rule = new AvailableForTotalAmount($validators, $validated); + $rule = new AvailableForTotalAmount($adapter, $validators, $validated); $expected = true; $actual = $rule->isMatching(); @@ -331,11 +336,13 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase */ public function testNotMatchingRuleEqual() { + $adapter = new CouponBaseAdapter(); + $validators = array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::EQUAL, new PriceParam( - , 421.23, 'EUR' + $adapter, 421.23, 'EUR' ) ) ); @@ -343,7 +350,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $validated = array( AvailableForTotalAmount::PARAM1_PRICE => 421.22 ); - $rule = new AvailableForTotalAmount($validators, $validated); + $rule = new AvailableForTotalAmount($adapter, $validators, $validated); $expected = false; $actual = $rule->isMatching(); @@ -357,11 +364,13 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase */ public function testMatchingRuleSuperior() { + $adapter = new CouponBaseAdapter(); + $validators = array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::SUPERIOR, new PriceParam( - , 421.23, 'EUR' + $adapter, 421.23, 'EUR' ) ) ); @@ -369,7 +378,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $validated = array( AvailableForTotalAmount::PARAM1_PRICE => 421.24 ); - $rule = new AvailableForTotalAmount($validators, $validated); + $rule = new AvailableForTotalAmount($adapter, $validators, $validated); $expected = true; $actual = $rule->isMatching(); @@ -383,11 +392,13 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase */ public function testNotMatchingRuleSuperior() { + $adapter = new CouponBaseAdapter(); + $validators = array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::SUPERIOR, new PriceParam( - , 421.23, 'EUR' + $adapter, 421.23, 'EUR' ) ) ); @@ -395,7 +406,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $validated = array( AvailableForTotalAmount::PARAM1_PRICE => 421.23 ); - $rule = new AvailableForTotalAmount($validators, $validated); + $rule = new AvailableForTotalAmount($adapter, $validators, $validated); $expected = false; $actual = $rule->isMatching(); diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesTest.php b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesTest.php index 69bfd13a6..9c5808010 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesTest.php @@ -45,16 +45,23 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { + /** @var CouponAdapterInterface $stubTheliaAdapter */ + $stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); } + /** + * Return an Adapter Mock wick 4 products int the Cart + * + * @return CouponAdapterInterface + */ protected function generateValidCouponBaseAdapterMock() { /** @var CouponAdapterInterface $stubTheliaAdapter */ - $stubTheliaAdapter = $this->getMock( - 'CouponBaseAdapter', - array('getNbArticlesInCart'), - array() - ); + $stubTheliaAdapter = $this->getMock( + 'CouponBaseAdapter', + array('getNbArticlesInCart'), + array() + ); $stubTheliaAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); @@ -69,12 +76,11 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase */ public function testValidBackOfficeInput() { - /** @var CouponAdapterInterface $stubTheliaAdapter */ - $stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); + $adapter = new CouponBaseAdapter(); $validators = array(4); - $validated = array($stubTheliaAdapter->getNbArticlesInCart()); - $rule = new AvailableForXArticles($validators, $validated); + $validated = array($adapter->getNbArticlesInCart()); + $rule = new AvailableForXArticles($adapter, $validators, $validated); $expected = true; $actual = $rule->checkBackOfficeInput(); @@ -88,28 +94,27 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase */ public function testInValidBackOfficeInput() { - /** @var CouponAdapterInterface $stubTheliaAdapter */ - $stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); + $adapter = new CouponBaseAdapter(); $validators = array(4.5); - $validated = array($stubTheliaAdapter->getNbArticlesInCart()); - $rule = new AvailableForXArticles($validators, $validated); + $validated = array($adapter->getNbArticlesInCart()); + $rule = new AvailableForXArticles($adapter, $validators, $validated); $expected = false; $actual = $rule->checkBackOfficeInput(); $this->assertEquals($expected, $actual); $validators = array(-1); - $validated = array($stubTheliaAdapter->getNbArticlesInCart()); - $rule = new AvailableForXArticles($validators, $validated); + $validated = array($adapter->getNbArticlesInCart()); + $rule = new AvailableForXArticles($adapter, $validators, $validated); $expected = false; $actual = $rule->checkBackOfficeInput(); $this->assertEquals($expected, $actual); $validators = array('bad'); - $validated = array($stubTheliaAdapter->getNbArticlesInCart()); - $rule = new AvailableForXArticles($validators, $validated); + $validated = array($adapter->getNbArticlesInCart()); + $rule = new AvailableForXArticles($adapter, $validators, $validated); $expected = false; $actual = $rule->checkBackOfficeInput(); @@ -125,12 +130,10 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase */ public function testValidCheckoutInput() { - /** @var CouponAdapterInterface $stubTheliaAdapter */ - $stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); - + $adapter = new CouponBaseAdapter(); $validators = array(4); - $validated = array($stubTheliaAdapter->getNbArticlesInCart()); - $rule = new AvailableForXArticles($validators, $validated); + $validated = array($adapter->getNbArticlesInCart()); + $rule = new AvailableForXArticles($adapter, $validators, $validated); $expected = true; $actual = $rule->checkCheckoutInput(); @@ -144,28 +147,26 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase */ public function testInValidCheckoutInput() { - /** @var CouponAdapterInterface $stubTheliaAdapter */ - $stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); - + $adapter = new CouponBaseAdapter(); $validators = array(4.5); - $validated = array($stubTheliaAdapter->getNbArticlesInCart()); - $rule = new AvailableForXArticles($validators, $validated); + $validated = array($adapter->getNbArticlesInCart()); + $rule = new AvailableForXArticles($adapter, $validators, $validated); $expected = false; $actual = $rule->checkCheckoutInput(); $this->assertEquals($expected, $actual); $validators = array(-1); - $validated = array($stubTheliaAdapter->getNbArticlesInCart()); - $rule = new AvailableForXArticles($validators, $validated); + $validated = array($adapter->getNbArticlesInCart()); + $rule = new AvailableForXArticles($adapter, $validators, $validated); $expected = false; $actual = $rule->checkCheckoutInput(); $this->assertEquals($expected, $actual); $validators = array('bad'); - $validated = array($stubTheliaAdapter->getNbArticlesInCart()); - $rule = new AvailableForXArticles($validators, $validated); + $validated = array($adapter->getNbArticlesInCart()); + $rule = new AvailableForXArticles($adapter, $validators, $validated); $expected = false; $actual = $rule->checkCheckoutInput(); @@ -179,12 +180,10 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase */ public function testMatchingRuleEqual() { - /** @var CouponAdapterInterface $stubTheliaAdapter */ - $stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); - + $adapter = new CouponBaseAdapter(); $validators = array(4); - $validated = array($stubTheliaAdapter->getNbArticlesInCart()); - $rule = new AvailableForXArticles($validators, $validated); + $validated = array($adapter->getNbArticlesInCart()); + $rule = new AvailableForXArticles($adapter, $validators, $validated); $expected = true; $actual = $rule->isMatching(); @@ -198,12 +197,10 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase */ public function testMatchingRuleSuperior() { - /** @var CouponAdapterInterface $stubTheliaAdapter */ - $stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); - + $adapter = new CouponBaseAdapter(); $validators = array(5); - $validated = array($stubTheliaAdapter->getNbArticlesInCart()); - $rule = new AvailableForXArticles($validators, $validated); + $validated = array($adapter->getNbArticlesInCart()); + $rule = new AvailableForXArticles($adapter, $validators, $validated); $expected = true; $actual = $rule->isMatching(); @@ -217,12 +214,10 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase */ public function testNotMatchingRule() { - /** @var CouponAdapterInterface $stubTheliaAdapter */ - $stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); - + $adapter = new CouponBaseAdapter(); $validators = array(3); - $validated = array($stubTheliaAdapter->getNbArticlesInCart()); - $rule = new AvailableForXArticles($validators, $validated); + $validated = array($adapter->getNbArticlesInCart()); + $rule = new AvailableForXArticles($adapter, $validators, $validated); $expected = false; $actual = $rule->isMatching(); diff --git a/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php b/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php index 51d5d06f1..aecd303b2 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php @@ -55,10 +55,11 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase */ public function testOperatorInferiorValidBefore() { + $adapter = new CouponBaseAdapter(); // Given $a = 11; $operator = Operators::INFERIOR; - $b = new QuantityParam(, 12); + $b = new QuantityParam($adapter, 12); // When $actual = Operators::isValid($a, $operator, $b); @@ -75,9 +76,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorInferiorInvalidEquals() { // Given + $adapter = new CouponBaseAdapter(); $a = 12; $operator = Operators::INFERIOR; - $b = new QuantityParam(, 12); + $b = new QuantityParam($adapter, 12); // When $actual = Operators::isValid($a, $operator, $b); @@ -94,9 +96,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorInferiorInvalidAfter() { // Given + $adapter = new CouponBaseAdapter(); $a = 13; $operator = Operators::INFERIOR; - $b = new QuantityParam(, 12); + $b = new QuantityParam($adapter, 12); // When $actual = Operators::isValid($a, $operator, $b); @@ -113,9 +116,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorInferiorOrEqualValidEqual() { // Given + $adapter = new CouponBaseAdapter(); $a = 11; $operator = Operators::INFERIOR_OR_EQUAL; - $b = new QuantityParam(, 11); + $b = new QuantityParam($adapter, 11); // When $actual = Operators::isValid($a, $operator, $b); @@ -132,9 +136,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorInferiorOrEqualValidBefore() { // Given + $adapter = new CouponBaseAdapter(); $a = 10; $operator = Operators::INFERIOR_OR_EQUAL; - $b = new QuantityParam(, 11); + $b = new QuantityParam($adapter, 11); // When $actual = Operators::isValid($a, $operator, $b); @@ -151,9 +156,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorInferiorOrEqualInValidAfter() { // Given + $adapter = new CouponBaseAdapter(); $a = 12; $operator = Operators::INFERIOR_OR_EQUAL; - $b = new QuantityParam(, 11); + $b = new QuantityParam($adapter, 11); // When $actual = Operators::isValid($a, $operator, $b); @@ -170,9 +176,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorEqualValidEqual() { // Given + $adapter = new CouponBaseAdapter(); $a = 12; $operator = Operators::EQUAL; - $b = new QuantityParam(, 12); + $b = new QuantityParam($adapter, 12); // When $actual = Operators::isValid($a, $operator, $b); @@ -189,9 +196,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorEqualInValidBefore() { // Given + $adapter = new CouponBaseAdapter(); $a = 11; $operator = Operators::EQUAL; - $b = new QuantityParam(, 12); + $b = new QuantityParam($adapter, 12); // When $actual = Operators::isValid($a, $operator, $b); @@ -208,9 +216,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorEqualInValidAfter() { // Given + $adapter = new CouponBaseAdapter(); $a = 13; $operator = Operators::EQUAL; - $b = new QuantityParam(, 12); + $b = new QuantityParam($adapter, 12); // When $actual = Operators::isValid($a, $operator, $b); @@ -227,9 +236,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorSuperiorOrEqualValidEqual() { // Given + $adapter = new CouponBaseAdapter(); $a = 13; $operator = Operators::SUPERIOR_OR_EQUAL; - $b = new QuantityParam(, 13); + $b = new QuantityParam($adapter, 13); // When $actual = Operators::isValid($a, $operator, $b); @@ -246,9 +256,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorSuperiorOrEqualAfter() { // Given + $adapter = new CouponBaseAdapter(); $a = 14; $operator = Operators::SUPERIOR_OR_EQUAL; - $b = new QuantityParam(, 13); + $b = new QuantityParam($adapter, 13); // When $actual = Operators::isValid($a, $operator, $b); @@ -265,9 +276,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorSuperiorOrEqualInvalidBefore() { // Given + $adapter = new CouponBaseAdapter(); $a = 12; $operator = Operators::SUPERIOR_OR_EQUAL; - $b = new QuantityParam(, 13); + $b = new QuantityParam($adapter, 13); // When $actual = Operators::isValid($a, $operator, $b); @@ -284,9 +296,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorSuperiorValidAfter() { // Given + $adapter = new CouponBaseAdapter(); $a = 13; $operator = Operators::SUPERIOR; - $b = new QuantityParam(, 12); + $b = new QuantityParam($adapter, 12); // When $actual = Operators::isValid($a, $operator, $b); @@ -303,9 +316,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorSuperiorInvalidEqual() { // Given + $adapter = new CouponBaseAdapter(); $a = 12; $operator = Operators::SUPERIOR; - $b = new QuantityParam(, 12); + $b = new QuantityParam($adapter, 12); // When $actual = Operators::isValid($a, $operator, $b); @@ -322,9 +336,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorSuperiorInvalidBefore() { // Given + $adapter = new CouponBaseAdapter(); $a = 11; $operator = Operators::SUPERIOR; - $b = new QuantityParam(, 12); + $b = new QuantityParam($adapter, 12); // When $actual = Operators::isValid($a, $operator, $b); @@ -341,9 +356,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorDifferentValid() { // Given + $adapter = new CouponBaseAdapter(); $a = 12; $operator = Operators::DIFFERENT; - $b = new QuantityParam(, 11); + $b = new QuantityParam($adapter, 11); // When $actual = Operators::isValid($a, $operator, $b); @@ -360,9 +376,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorDifferentInvalidEquals() { // Given + $adapter = new CouponBaseAdapter(); $a = 11; $operator = Operators::DIFFERENT; - $b = new QuantityParam(, 11); + $b = new QuantityParam($adapter, 11); // When $actual = Operators::isValid($a, $operator, $b); @@ -379,9 +396,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase public function testOperatorInValid() { // Given + $adapter = new CouponBaseAdapter(); $a = 12; $operator = 'X'; - $b = new QuantityParam(, 11); + $b = new QuantityParam($adapter, 11); // When $actual = Operators::isValid($a, $operator, $b); diff --git a/core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php index 9543388f6..bd83d45db 100644 --- a/core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php +++ b/core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php @@ -24,6 +24,7 @@ namespace Thelia\Coupon; use InvalidArgumentException; +use Thelia\Constraint\Validator\PriceParam; use Thelia\Constraint\Validator\QuantityParam; /** @@ -173,7 +174,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase $this->assertEquals($param->getValue(), $unserialized->getValue()); $this->assertEquals($param->getInteger(), $unserialized->getInteger()); - $new = new PriceParam($adapter, $unserialized->getInteger()); + $new = new QuantityParam($adapter, $unserialized->getInteger()); $this->assertEquals($param->getInteger(), $new->getInteger()); } diff --git a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php index f3cf99054..c4006be0d 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php @@ -204,7 +204,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase protected function generateValidRules() { $rule1 = new AvailableForTotalAmount( - array( + , array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::SUPERIOR, new PriceParam( @@ -214,7 +214,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase ) ); $rule2 = new AvailableForTotalAmount( - array( + , array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::INFERIOR, new PriceParam( diff --git a/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php b/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php index 08673746e..9d171a021 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php @@ -110,7 +110,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua /** @var CouponInterface $coupon1 */ $coupon1 = self::generateValidCoupon(); $rule1 = new AvailableForTotalAmount( - array( + $adapter, array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::SUPERIOR, new PriceParam( @@ -148,7 +148,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $checkoutTotalPrice = 26.00; $rule1 = new AvailableForTotalAmount( - array( + $adapter, array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::SUPERIOR, new PriceParam( @@ -185,7 +185,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $checkoutTotalPrice = 27.00; $rule1 = new AvailableForTotalAmount( - array( + $adapter, array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::SUPERIOR, new PriceParam( @@ -642,7 +642,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua { $adapter = new CouponBaseAdapter(); $rule1 = new AvailableForTotalAmount( - array( + $adapter, array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::SUPERIOR, new PriceParam( @@ -652,7 +652,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua ) ); $rule2 = new AvailableForTotalAmount( - array( + $adapter, array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::INFERIOR, new PriceParam( diff --git a/core/lib/Thelia/Tests/Coupon/CouponRuleCollectionTest.php b/core/lib/Thelia/Tests/Coupon/CouponRuleCollectionTest.php index eab22758b..e1ad4ecdd 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponRuleCollectionTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponRuleCollectionTest.php @@ -47,7 +47,7 @@ class CouponRuleCollectionTest extends \PHPUnit_Framework_TestCase public function testRuleSerialisation() { $rule1 = new AvailableForTotalAmount( - array( + , array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::SUPERIOR, new PriceParam( @@ -57,7 +57,7 @@ class CouponRuleCollectionTest extends \PHPUnit_Framework_TestCase ) ); $rule2 = new AvailableForTotalAmount( - array( + , array( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( Operators::INFERIOR, new PriceParam( diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountForCategoryYTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountForCategoryYTest.php index 65bf2e344..896cc5feb 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountForCategoryYTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountForCategoryYTest.php @@ -45,6 +45,13 @@ class RemoveXAmountForCategoryYTest extends \PHPUnit_Framework_TestCase { } + public function incompleteTest() + { + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php index 69e01549f..182594666 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php @@ -151,7 +151,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); $expected = 10; - $actual = $coupon->getDiscount($adapter); + $actual = $coupon->getDiscount(); $this->assertEquals($expected, $actual); } @@ -234,7 +234,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // Then $expected = 10.00; - $actual = $coupon->getDiscount($adapter); + $actual = $coupon->getDiscount(); $this->assertEquals($expected, $actual); } @@ -259,7 +259,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // Then $expected = 10.00; - $actual = $coupon->getDiscount($adapter); + $actual = $coupon->getDiscount(); $this->assertEquals($expected, $actual); } @@ -284,7 +284,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // Then $expected = 10.00; - $actual = $coupon->getDiscount($adapter); + $actual = $coupon->getDiscount(); $this->assertEquals($expected, $actual); } @@ -309,7 +309,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // Then $expected = 10.00; - $actual = $coupon->getDiscount($adapter); + $actual = $coupon->getDiscount(); $this->assertEquals($expected, $actual); } @@ -334,7 +334,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // Then $expected = 10.00; - $actual = $coupon->getDiscount($adapter); + $actual = $coupon->getDiscount(); $this->assertEquals($expected, $actual); } @@ -371,7 +371,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase ) ); - return new AvailableForTotalAmount($validators); + return new AvailableForTotalAmount($adapter, $validators); } } diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php index 24388104d..1ea0c67bb 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php @@ -45,6 +45,13 @@ class RemoveXPercentForCategoryYTest extends \PHPUnit_Framework_TestCase { } + public function incompleteTest() + { + $this->markTestIncomplete( + 'This test has not been implemented yet.' + ); + } + /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php index 5b80ac1a3..67d09341c 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php @@ -63,7 +63,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase */ public function testIsCumulative() { - $coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, true, true); + $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, true, true); $actual = $coupon->isCumulative(); $this->assertTrue($actual); @@ -77,7 +77,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase */ public function testIsNotCumulative() { - $coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); + $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); $actual = $coupon->isCumulative(); $this->assertFalse($actual); @@ -92,7 +92,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase */ public function testIsRemovingPostage() { - $coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, true, true); + $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, true, true); $actual = $coupon->isRemovingPostage(); $this->assertTrue($actual); @@ -105,7 +105,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase */ public function testIsNotRemovingPostage() { - $coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); + $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); $actual = $coupon->isRemovingPostage(); $this->assertFalse($actual); @@ -120,7 +120,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase public function testGetEffect() { $adapter = $this->generateFakeAdapter(245); - $coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); + $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); $expected = 24.50; $actual = $coupon->getDiscount($adapter); @@ -149,7 +149,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase 421.23 ); - $coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); + $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // When $coupon->setRules(new CouponRuleCollection(array($rule0, $rule1, $rule2))); @@ -179,7 +179,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase ); $rule2 = $this; - $coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); + $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // When $coupon->setRules(new CouponRuleCollection(array($rule0, $rule1, $rule2))); @@ -194,19 +194,18 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase public function testGetEffectIfTotalAmountInferiorTo400Valid() { // Given - $adapter = $this->generateFakeAdapter(245); $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( Operators::INFERIOR, 400.00 ); - $coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); + $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // When $coupon->setRules(new CouponRuleCollection(array($rule0))); // Then $expected = 24.50; - $actual = $coupon->getDiscount($adapter); + $actual = $coupon->getDiscount(); $this->assertEquals($expected, $actual); } @@ -219,19 +218,18 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase public function testGetEffectIfTotalAmountInferiorOrEqualTo400Valid() { // Given - $adapter = $this->generateFakeAdapter(245); $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( Operators::INFERIOR_OR_EQUAL, 400.00 ); - $coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); + $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // When $coupon->setRules(new CouponRuleCollection(array($rule0))); // Then $expected = 24.50; - $actual = $coupon->getDiscount($adapter); + $actual = $coupon->getDiscount(); $this->assertEquals($expected, $actual); } @@ -244,19 +242,18 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase public function testGetEffectIfTotalAmountEqualTo400Valid() { // Given - $adapter = $this->generateFakeAdapter(245); $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( Operators::EQUAL, 400.00 ); - $coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); + $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // When $coupon->setRules(new CouponRuleCollection(array($rule0))); // Then $expected = 24.50; - $actual = $coupon->getDiscount($adapter); + $actual = $coupon->getDiscount(); $this->assertEquals($expected, $actual); } @@ -269,19 +266,18 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase public function testGetEffectIfTotalAmountSuperiorOrEqualTo400Valid() { // Given - $adapter = $this->generateFakeAdapter(245); $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( Operators::SUPERIOR_OR_EQUAL, 400.00 ); - $coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); + $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // When $coupon->setRules(new CouponRuleCollection(array($rule0))); // Then $expected = 24.50; - $actual = $coupon->getDiscount($adapter); + $actual = $coupon->getDiscount(); $this->assertEquals($expected, $actual); } @@ -294,19 +290,18 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase public function testGetEffectIfTotalAmountSuperiorTo400Valid() { // Given - $adapter = $this->generateFakeAdapter(245); $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( Operators::SUPERIOR, 400.00 ); - $coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); + $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); // When $coupon->setRules(new CouponRuleCollection(array($rule0))); // Then $expected = 24.50; - $actual = $coupon->getDiscount($adapter); + $actual = $coupon->getDiscount(); $this->assertEquals($expected, $actual); } @@ -331,7 +326,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase * * @return CouponInterface */ - public static function generateValidCoupon( + public function generateValidCoupon( $code = null, $title = null, $shortDescription = null, @@ -345,7 +340,8 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase $isAvailableOnSpecialOffers = null, $maxUsage = null ) { - $adapter = new CouponBaseAdapter(); + $adapter = $this->generateFakeAdapter(245); + if ($code === null) { $code = CouponManagerTest::VALID_CODE; } @@ -417,7 +413,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase ) ); - return new AvailableForTotalAmount($validators); + return new AvailableForTotalAmount($adapter, $validators); } /**