From c49bfa4b25b0ef283d1ecb123d11586174baa5de Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 11:26:37 +0200 Subject: [PATCH] Working : Coupon : Fix unit tests @todo refactor --- .../Thelia/Constraint/ConstraintValidator.php | 4 +- .../Constraint/Rule/CouponRuleAbstract.php | 4 ++ .../Constraint/ConstraintValidatorTest.php | 12 ++++++ .../Rule/AvailableForTotalAmountTest.php | 43 +++++++++++++++++++ .../Rule/AvailableForXArticlesTest.php | 43 +++++++++++++++++++ 5 files changed, 104 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Constraint/ConstraintValidator.php b/core/lib/Thelia/Constraint/ConstraintValidator.php index 325faed22..d3fe69a34 100644 --- a/core/lib/Thelia/Constraint/ConstraintValidator.php +++ b/core/lib/Thelia/Constraint/ConstraintValidator.php @@ -69,10 +69,10 @@ class ConstraintValidator /** * Do variable comparison * - * @param mixed $v1 Variable 1 + * @param mixed $v1 Variable 1 * @param string $o Operator + * @param mixed $v2 Variable 2 * - * @param mixed $v2 Variable 2 * @throws \Exception * @return bool */ diff --git a/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php b/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php index 942e48d1f..0986daa50 100644 --- a/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php +++ b/core/lib/Thelia/Constraint/Rule/CouponRuleAbstract.php @@ -24,6 +24,7 @@ namespace Thelia\Constraint\Rule; use Symfony\Component\Intl\Exception\NotImplementedException; +use Thelia\Constraint\ConstraintValidator; use Thelia\Core\Translation\Translator; use Thelia\Coupon\CouponAdapterInterface; use Thelia\Constraint\Validator\ComparableInterface; @@ -73,6 +74,9 @@ abstract class CouponRuleAbstract implements CouponRuleInterface /** @var array Values set by Admin in BackOffice */ protected $values = array(); + /** @var ConstraintValidator Constaints validator */ + protected $constraintValidator = null; + /** * Constructor * diff --git a/core/lib/Thelia/Tests/Constraint/ConstraintValidatorTest.php b/core/lib/Thelia/Tests/Constraint/ConstraintValidatorTest.php index 17b6b49e1..68818a092 100644 --- a/core/lib/Thelia/Tests/Constraint/ConstraintValidatorTest.php +++ b/core/lib/Thelia/Tests/Constraint/ConstraintValidatorTest.php @@ -65,6 +65,9 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue($ConstraintValidator)); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -99,6 +102,9 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue($ConstraintValidator)); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -136,6 +142,9 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(5)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue($ConstraintValidator)); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -183,6 +192,9 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(5)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue($ConstraintValidator)); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountTest.php b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountTest.php index 4c6da4ad2..c3f7249df 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountTest.php @@ -23,6 +23,7 @@ namespace Thelia\Coupon; +use Thelia\Constraint\ConstraintValidator; use Thelia\Constraint\Rule\AvailableForTotalAmountManager; use Thelia\Constraint\Rule\Operators; @@ -169,6 +170,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -205,6 +209,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -241,6 +248,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -277,6 +287,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -313,6 +326,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -349,6 +365,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -385,6 +404,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -421,6 +443,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -457,6 +482,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -493,6 +521,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -529,6 +560,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -565,6 +599,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -601,6 +638,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( @@ -637,6 +677,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForTotalAmountManager($stubAdapter); $operators = array( diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesTest.php b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesTest.php index 76a744848..4ecbcb8ac 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesTest.php @@ -23,6 +23,7 @@ namespace Thelia\Coupon; +use Thelia\Constraint\ConstraintValidator; use Thelia\Constraint\Rule\AvailableForXArticlesManager; use Thelia\Constraint\Rule\Operators; use Thelia\Constraint\Rule\SerializableRule; @@ -192,6 +193,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -224,6 +228,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -256,6 +263,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -288,6 +298,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -320,6 +333,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -352,6 +368,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -384,6 +403,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -416,6 +438,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -448,6 +473,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -480,6 +508,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -512,6 +543,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -544,6 +578,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -570,6 +607,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array( @@ -602,6 +642,9 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); + $stubAdapter->expects($this->any()) + ->method('getConstraintValidator') + ->will($this->returnValue(new ConstraintValidator())); $rule1 = new AvailableForXArticlesManager($stubAdapter); $operators = array(