WIP : Coupon : unit tests on Rules

This commit is contained in:
gmorel
2013-09-16 23:56:31 +02:00
parent ad48823b48
commit a7ef4300aa
4 changed files with 13 additions and 144 deletions

View File

@@ -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'
);
}

View File

@@ -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'
);
}

View File

@@ -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
*

View File

@@ -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
*