diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php b/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php index 30bc86ad6..d8a4755f6 100644 --- a/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php +++ b/core/lib/Thelia/Constraint/Rule/AvailableForTotalAmountManager.php @@ -111,8 +111,8 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract $this->availableOperators[self::INPUT1] ); if (!$isOperator1Legit) { - throw new \InvalidArgumentException( - 'Operator for price field is not legit' + throw new InvalidRuleOperatorException( + get_class(), 'price' ); } @@ -121,15 +121,15 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract $this->availableOperators[self::INPUT2] ); if (!$isOperator1Legit) { - throw new \InvalidArgumentException( - 'Operator for currency field is not legit' + throw new InvalidRuleOperatorException( + get_class(), 'price' ); } $floatType = new FloatType(); if (!$floatType->isValid($priceValue) || $priceValue <= 0) { - throw new \InvalidArgumentException( - 'Value for price field is not legit' + throw new InvalidRuleValueException( + get_class(), 'price' ); } diff --git a/core/lib/Thelia/Constraint/Rule/AvailableForXArticlesManager.php b/core/lib/Thelia/Constraint/Rule/AvailableForXArticlesManager.php index 572d39b1d..f73d5e2be 100644 --- a/core/lib/Thelia/Constraint/Rule/AvailableForXArticlesManager.php +++ b/core/lib/Thelia/Constraint/Rule/AvailableForXArticlesManager.php @@ -30,6 +30,7 @@ use Thelia\Constraint\Validator\QuantityParam; use Thelia\Constraint\Validator\RuleValidator; use Thelia\Coupon\CouponAdapterInterface; use Thelia\Exception\InvalidRuleException; +use Thelia\Exception\InvalidRuleOperatorException; use Thelia\Exception\InvalidRuleValueException; use Thelia\Type\FloatType; @@ -98,14 +99,14 @@ class AvailableForXArticlesManager extends CouponRuleAbstract $this->availableOperators[self::INPUT1] ); if (!$isOperator1Legit) { - throw new \InvalidArgumentException( - 'Operator for quantity field is not legit' + throw new InvalidRuleOperatorException( + get_class(), 'quantity' ); } if ((int) $quantityValue <= 0) { - throw new \InvalidArgumentException( - 'Value for quantity field is not legit' + throw new InvalidRuleValueException( + get_class(), 'quantity' ); } diff --git a/core/lib/Thelia/Constraint/Rule/Operators.php b/core/lib/Thelia/Constraint/Rule/Operators.php index 2ed5c2909..a6c457c75 100644 --- a/core/lib/Thelia/Constraint/Rule/Operators.php +++ b/core/lib/Thelia/Constraint/Rule/Operators.php @@ -56,62 +56,6 @@ abstract class Operators /** Param1 is not in Param2 */ CONST OUT = 'out'; -// /** -// * Check if a parameter is valid against a ComparableInterface from its operator -// * -// * @param mixed $a Parameter to validate -// * @param string $operator Operator to validate against -// * @param ComparableInterface $b Comparable to validate against -// * -// * @return bool -// */ -// public static function isValid($a, $operator, ComparableInterface $b) -// { -// $ret = false; -// -// try { -// $comparison = $b->compareTo($a); -// } catch (\Exception $e) { -// return false; -// } -// -// switch ($operator) { -// case self::INFERIOR: -// if ($comparison == 1) { -// return true; -// } -// break; -// case self::INFERIOR_OR_EQUAL: -// if ($comparison == 1 || $comparison == 0) { -// return true; -// } -// break; -// case self::EQUAL: -// if ($comparison == 0) { -// return true; -// } -// break; -// case self::SUPERIOR_OR_EQUAL: -// if ($comparison == -1 || $comparison == 0) { -// return true; -// } -// break; -// case self::SUPERIOR: -// if ($comparison == -1) { -// return true; -// } -// break; -// case self::DIFFERENT: -// if ($comparison != 0) { -// return true; -// } -// break; -// default: -// } -// -// return $ret; -// } - /** * Get operator translation * diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php index 12deb34b8..4937826b6 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php @@ -54,34 +54,10 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase } -// /** -// * Check if validity test on BackOffice inputs are working -// * -// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput -// * -// */ -// public function testValidBackOfficeInput() -// { -// $translator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') -// ->disableOriginalConstructor() -// ->getMock(); -// -// $rule = new AvailableForXArticles($translator); -// $operators = array(AvailableForXArticles::PARAM1_QUANTITY => Operators::SUPERIOR); -// $values = array( -// AvailableForXArticles::PARAM1_QUANTITY => 4 -// ); -// $rule->populateFromForm($operators, $values); -// -// $expected = true; -// $actual = $rule->checkBackOfficeInput(); -// $this->assertEquals($expected, $actual); -// } - /** * Check if validity test on BackOffice inputs are working * - * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput + * @covers Thelia\Coupon\Rule\AvailableForXArticlesManager::setValidators * @expectedException \Thelia\Exception\InvalidRuleOperatorException */ public function testInValidBackOfficeInputOperator() @@ -116,7 +92,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if validity test on BackOffice inputs are working * - * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput + * @covers Thelia\Coupon\Rule\AvailableForXArticlesManager::setValidators * @expectedException \Thelia\Exception\InvalidRuleValueException */ public function testInValidBackOfficeInputValue() @@ -148,58 +124,6 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $actual); } -// /** -// * Check if validity test on BackOffice inputs are working -// * -// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput -// * @expectedException \Thelia\Exception\InvalidRuleValueException -// */ -// public function testInValidBackOfficeInputNegative() -// { -// $adapter = $this->stubTheliaAdapter; -// -// $validators = array( -// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( -// Operators::SUPERIOR, -// new QuantityParam( -// $adapter, -// -1 -// ) -// ) -// ); -// $rule = new AvailableForXArticles($adapter, $validators); -// -// $expected = false; -// $actual = $rule->checkBackOfficeInput(); -// $this->assertEquals($expected, $actual); -// } - -// /** -// * Check if validity test on BackOffice inputs are working -// * -// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput -// * @expectedException \Thelia\Exception\InvalidRuleValueException -// */ -// public function testInValidBackOfficeInputString() -// { -// $adapter = $this->stubTheliaAdapter; -// -// $validators = array( -// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator( -// Operators::SUPERIOR, -// new QuantityParam( -// $adapter, -// 'bad' -// ) -// ) -// ); -// $rule = new AvailableForXArticles($adapter, $validators); -// -// $expected = false; -// $actual = $rule->checkBackOfficeInput(); -// $this->assertEquals($expected, $actual); -// } - /** * Check if test inferior operator is working *