From df08158cff14eb0900338784a7660e363a04c33e Mon Sep 17 00:00:00 2001 From: gmorel Date: Tue, 20 Aug 2013 19:05:41 +0200 Subject: [PATCH] WIP Coupon Implementation Comparable Parameters --- .../Thelia/Coupon/CouponAdapterInterface.php | 7 + core/lib/Thelia/Coupon/CouponBaseAdapter.php | 21 ++ .../Comparable.php} | 28 +- .../lib/Thelia/Coupon/Parameter/DateParam.php | 95 +++++ .../Thelia/Coupon/Parameter/IntervalParam.php | 107 ++++++ .../Coupon/Parameter/RepeatedDateParam.php | 89 +++++ .../Parameter/RepeatedIntervalParam.php | 122 +++++++ .../Thelia/Coupon/Parameter/RepeatedParam.php | 236 +++++++++++++ .../Coupon/Rule/AvailableForXArticles.php | 77 +++++ .../Thelia/Coupon/Rule/CouponRuleAbstract.php | 18 + .../Tests/Coupon/Parameter/DateParamTest.php | 96 +++++ .../Coupon/Parameter/IntervalParamTest.php | 121 +++++++ .../Parameter/RepeatedDateParamTest.php | 238 +++++++++++++ .../Parameter/RepeatedIntervalParamTest.php | 327 ++++++++++++++++++ .../Rule/AvailableForNbArticlesTest.php | 26 -- .../Coupon/Rule/AvailableForXArticlesTest.php | 211 +++++++++++ 16 files changed, 1784 insertions(+), 35 deletions(-) rename core/lib/Thelia/Coupon/{Rule/AvailableForNbArticles.php => Parameter/Comparable.php} (70%) create mode 100644 core/lib/Thelia/Coupon/Parameter/DateParam.php create mode 100644 core/lib/Thelia/Coupon/Parameter/IntervalParam.php create mode 100644 core/lib/Thelia/Coupon/Parameter/RepeatedDateParam.php create mode 100644 core/lib/Thelia/Coupon/Parameter/RepeatedIntervalParam.php create mode 100644 core/lib/Thelia/Coupon/Parameter/RepeatedParam.php create mode 100644 core/lib/Thelia/Coupon/Rule/AvailableForXArticles.php create mode 100644 core/lib/Thelia/Tests/Coupon/Parameter/DateParamTest.php create mode 100644 core/lib/Thelia/Tests/Coupon/Parameter/IntervalParamTest.php create mode 100644 core/lib/Thelia/Tests/Coupon/Parameter/RepeatedDateParamTest.php create mode 100644 core/lib/Thelia/Tests/Coupon/Parameter/RepeatedIntervalParamTest.php delete mode 100644 core/lib/Thelia/Tests/Coupon/Rule/AvailableForNbArticlesTest.php create mode 100644 core/lib/Thelia/Tests/Coupon/Rule/AvailableForXArticlesTest.php diff --git a/core/lib/Thelia/Coupon/CouponAdapterInterface.php b/core/lib/Thelia/Coupon/CouponAdapterInterface.php index f36c13427..06e3a3ca7 100644 --- a/core/lib/Thelia/Coupon/CouponAdapterInterface.php +++ b/core/lib/Thelia/Coupon/CouponAdapterInterface.php @@ -79,4 +79,11 @@ interface CouponAdapterInterface */ public function getCheckoutPostagePrice(); + /** + * Return the number of Products in the Cart + * + * @return int + */ + public function getNbArticlesInTheCart(); + } \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/CouponBaseAdapter.php b/core/lib/Thelia/Coupon/CouponBaseAdapter.php index bb24306e2..6908b3317 100644 --- a/core/lib/Thelia/Coupon/CouponBaseAdapter.php +++ b/core/lib/Thelia/Coupon/CouponBaseAdapter.php @@ -84,4 +84,25 @@ class CouponBaseAdapter implements CouponAdapterInterface // TODO: Implement getCheckoutPostagePrice() method. } + /** + * Return Products total price + * + * @return float + */ + public function getCheckoutTotalPriceWithoutDiscountAndPostagePrice() + { + // TODO: Implement getCheckoutTotalPriceWithoutDiscountAndPostagePrice() method. + } + + /** + * Return the number of Products in the Cart + * + * @return int + */ + public function getNbArticlesInTheCart() + { + // TODO: Implement getNbArticlesInTheCart() method. + } + + } \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Rule/AvailableForNbArticles.php b/core/lib/Thelia/Coupon/Parameter/Comparable.php similarity index 70% rename from core/lib/Thelia/Coupon/Rule/AvailableForNbArticles.php rename to core/lib/Thelia/Coupon/Parameter/Comparable.php index 78bbb0e00..37a7faeab 100644 --- a/core/lib/Thelia/Coupon/Rule/AvailableForNbArticles.php +++ b/core/lib/Thelia/Coupon/Parameter/Comparable.php @@ -21,18 +21,28 @@ /* */ /*************************************************************************************/ -namespace Thelia\Coupon\Rule; +namespace Thelia\Coupon\Parameter; /** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * @package Coupon - * @author Guillaume MOREL + * Comparable interface that allows to compare two value objects to each other for similarity. * + * @author Benjamin Eberlei + * @author Guilherme Blanco */ -class AvailableForNbArticles extends CouponRuleAbstract +interface Comparable { - + /** + * Compare the current object to the passed $other. + * + * Returns 0 if they are semantically equal, 1 if the other object + * is less than the current one, or -1 if its more than the current one. + * + * This method should not check for identity using ===, only for semantical equality for example + * when two different DateTime instances point to the exact same Date + TZ. + * + * @param mixed $other Object + * + * @return int + */ + public function compareTo($other); } \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Parameter/DateParam.php b/core/lib/Thelia/Coupon/Parameter/DateParam.php new file mode 100644 index 000000000..29dab530d --- /dev/null +++ b/core/lib/Thelia/Coupon/Parameter/DateParam.php @@ -0,0 +1,95 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Coupon\Parameter; + +use Thelia\Coupon\Parameter\Comparable; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Represent a DateTime + * + * @package Coupon + * @author Guillaume MOREL + * + */ +class DateParam implements Comparable +{ + /** @var \DateTime Date */ + protected $dateTime = null; + + /** + * Constructor + * + * @param \DateTime $dateTime DateTime + */ + public function __construct(\DateTime $dateTime) + { + $this->dateTime = $dateTime; + } + + /** + * Get DateTime + * + * @return \DateTime + */ + public function getDateTime() + { + return clone $this->dateTime; + } + + /** + * Compare the current object to the passed $other. + * + * Returns 0 if they are semantically equal, 1 if the other object + * is less than the current one, or -1 if its more than the current one. + * + * This method should not check for identity using ===, only for semantical equality for example + * when two different DateTime instances point to the exact same Date + TZ. + * + * @param mixed $other Object + * + * @return int + */ + public function compareTo($other) + { + if (!$other instanceof \DateTime) { + throw new \InvalidArgumentException('DateParam can compare only DateTime'); + } + + $ret = -1; + if ($this->dateTime == $other) { + $ret = 0; + } elseif ($this->dateTime > $other) { + $ret = 1; + } else { + $ret = -1; + } + + return $ret; + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Parameter/IntervalParam.php b/core/lib/Thelia/Coupon/Parameter/IntervalParam.php new file mode 100644 index 000000000..656cf69ca --- /dev/null +++ b/core/lib/Thelia/Coupon/Parameter/IntervalParam.php @@ -0,0 +1,107 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Coupon\Parameter; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Represent an DateTime period + * + * @package Coupon + * @author Guillaume MOREL + * + */ +class IntervalParam implements Comparable +{ + /** @var \DatePeriod Date period */ + protected $datePeriod = null; + + /** + * Constructor + * + * @param \DateTime $start Start interval + * @param \DateInterval $interval Period + */ + public function __construct(\DateTime $start, \DateInterval $interval) + { + $this->datePeriod = new \DatePeriod($start, $interval, 1); + } + + /** + * Get DatePeriod + * + * @return \DatePeriod + */ + public function getDatePeriod() + { + return clone $this->datePeriod; + } + + /** + * Compare the current object to the passed $other. + * + * Returns 0 if they are semantically equal, 1 if the other object + * is less than the current one, or -1 if its more than the current one. + * + * This method should not check for identity using ===, only for semantical equality for example + * when two different DateTime instances point to the exact same Date + TZ. + * + * @param mixed $other Object + * + * @return int + */ + public function compareTo($other) + { + if (!$other instanceof \DateTime) { + throw new \InvalidArgumentException('IntervalParam can compare only DateTime'); + } + + /** @var \DateTime Start Date */ + $startDate = null; + /** @var \DateTime End Date */ + $endDate = null; + + foreach ($this->datePeriod as $key => $value) { + if ($key == 0) { + $startDate = $value; + } + if ($key == 1) { + $endDate = $value; + } + } + + $ret = -1; + if ($startDate <= $other && $other <= $endDate) { + $ret = 0; + } elseif ($startDate > $other) { + $ret = 1; + } else { + $ret = -1; + } + + return $ret; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Parameter/RepeatedDateParam.php b/core/lib/Thelia/Coupon/Parameter/RepeatedDateParam.php new file mode 100644 index 000000000..150f632b8 --- /dev/null +++ b/core/lib/Thelia/Coupon/Parameter/RepeatedDateParam.php @@ -0,0 +1,89 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Coupon\Parameter; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Represent A repeated Date across the time + * Ex : + * A date repeated every 1 months 5 times + * ---------*---*---*---*---*---*---------------------------> time + * 1 2 3 4 5 6 + * 1 : $this->from Start date of the repetition + * *--- : $this->interval Duration of a whole cycle + * x6 : $this->recurrences How many cycle + * + * @package Coupon + * @author Guillaume MOREL + * + */ +class RepeatedDateParam extends RepeatedParam +{ + /** + * Constructor + */ + public function __construct() + { + $this->defaultConstructor(); + } + + /** + * Compare the current object to the passed $other. + * + * Returns 0 if they are semantically equal, 1 if the other object + * is less than the current one, or -1 if its more than the current one. + * + * This method should not check for identity using ===, only for semantical equality for example + * when two different DateTime instances point to the exact same Date + TZ. + * + * @param mixed $other Object + * + * @throws \InvalidArgumentException + * @return int + */ + public function compareTo($other) + { + if (!$other instanceof \DateTime) { + throw new \InvalidArgumentException('RepeatedDateParam can compare only DateTime'); + } + + $ret = -1; + $dates = array(); + /** @var $value \DateTime */ + foreach ($this->datePeriod as $value) { + $dates[$value->getTimestamp()] = $value; + } + + foreach ($dates as $date) { + if ($date == $other) { + return 0; + } + } + + return $ret; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Parameter/RepeatedIntervalParam.php b/core/lib/Thelia/Coupon/Parameter/RepeatedIntervalParam.php new file mode 100644 index 000000000..4bbbd8569 --- /dev/null +++ b/core/lib/Thelia/Coupon/Parameter/RepeatedIntervalParam.php @@ -0,0 +1,122 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Coupon\Parameter; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Represent A repeated DateInterval across the time + * Ex : + * A duration of 1 month repeated every 2 months 5 times + * ---------****----****----****----****----****----****-----------------> time + * 1 2 3 4 5 6 + * 1 : $this->from Start date of the repetition + * ****---- : $this->interval Duration of a whole cycle + * x6 : $this->recurrences How many cycle + * **** : $this->durationInDays Duration of a period + * + * @package Coupon + * @author Guillaume MOREL + * + */ +class RepeatedIntervalParam extends RepeatedParam +{ + + /** @var int duration of the param */ + protected $durationInDays = 1; + + /** + * Get how many day a Param is lasting + * + * @return int + */ + public function getDurationInDays() + { + return $this->durationInDays; + } + + /** + * Set how many day a Param is lasting + * + * @param int $durationInDays How many day a Param is lasting + * + * @return $this + */ + public function setDurationInDays($durationInDays = 1) + { + $this->durationInDays = $durationInDays; + + return $this; + } + + /** + * Constructor + */ + public function __construct() + { + $this->defaultConstructor(); + } + + /** + * Compare the current object to the passed $other. + * + * Returns 0 if they are semantically equal, 1 if the other object + * is less than the current one, or -1 if its more than the current one. + * + * This method should not check for identity using ===, only for semantical equality for example + * when two different DateTime instances point to the exact same Date + TZ. + * + * @param mixed $other Object + * + * @return int + */ + public function compareTo($other) + { + if (!$other instanceof \DateTime) { + throw new \InvalidArgumentException('RepeatedIntervalParam can compare only DateTime'); + } + + $ret = -1; + $dates = array(); + /** @var $value \DateTime */ + foreach ($this->datePeriod as $value) { + $dates[$value->getTimestamp()]['startDate'] = $value; + $endDate = new \DateTime(); + $dates[$value->getTimestamp()]['endDate'] = $endDate->setTimestamp( + $value->getTimestamp() + ($this->durationInDays * 60 *60 *24) + ); + } + + foreach ($dates as $date) { + if ($date['startDate'] <= $other && $other <= $date['endDate']) { + return 0; + } + } + + return $ret; + + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Parameter/RepeatedParam.php b/core/lib/Thelia/Coupon/Parameter/RepeatedParam.php new file mode 100644 index 000000000..ed5dcbf03 --- /dev/null +++ b/core/lib/Thelia/Coupon/Parameter/RepeatedParam.php @@ -0,0 +1,236 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Coupon\Parameter; + +use DateInterval; +use DatePeriod; +use DateTime; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Allow to set the way a parameter can be repeated across the time + * + * @package Coupon + * @author Guillaume MOREL + * + */ +abstract class RepeatedParam implements Comparable +{ + /** @var DateTime The start date of the period. */ + protected $from = null; + + /** @var DateInterval The interval between recurrences within the period. */ + protected $interval = null; + + /** @var int The number of recurrences. */ + protected $recurrences = null; + + /** @var DatePeriod dates recurring at regular intervals, over a given period */ + protected $datePeriod = null; + + /** + * Generate default repetition + * Every 1 week 100 times from now + * + * @return $this + */ + protected function defaultConstructor() + { + $this->from = new \DateTime(); + $this->interval = new \DateInterval('P1W'); // 1 week + $this->recurrences = 100; + $this->generateDatePeriod(); + + return $this; + } + + /** + * Generate DatePeriod from class attributes + * Will repeat every DatePeriod + * + * @return $this + */ + protected function generateDatePeriod() + { + $this->datePeriod = new DatePeriod( + $this->from, + $this->interval, + $this->recurrences + ); + + return $this; + } + + /** + * Set the Object to be repeated every days + * Ex : $obj->repeatEveryDay() will be repeated every days indefinitely + * $obj->repeatEveryDay(10) will be repeated every 10 days indefinitely + * $obj->repeatEveryDay(10, 4) will be repeated every 10 days only 4 times + * + * @param int $frequency Frequency the object will be repeated + * @param int $nbRepetition Time the object will be repeated (0 = infinite) + * + * @return $this + */ + public function repeatEveryDay($frequency = 1, $nbRepetition = 0) + { + $this->_repeatEveryPeriod($period = 'D', $frequency, $nbRepetition); + + return $this; + } + + /** + * Set the Object to be repeated every week + * Ex : $obj->repeatEveryWeek() will be repeated every week indefinitely + * $obj->repeatEveryWeek(10) will be repeated every 10 weeks (70days) indefinitely + * $obj->repeatEveryWeek(10, 4) will be repeated every 10 weeks (70days) only 4 times + * + * @param int $frequency Frequency the object will be repeated + * @param int $nbRepetition Time the object will be repeated (0 = infinite) + * + * @return $this + */ + public function repeatEveryWeek($frequency = 1, $nbRepetition = null) + { + $this->_repeatEveryPeriod($period = 'W', $frequency, $nbRepetition); + + return $this; + } + + /** + * Set the Object to be repeated every month + * Ex : $obj->repeatEveryWeek() will be repeated every month indefinitely + * $obj->repeatEveryWeek(10) will be repeated every 10 month (70days) indefinitely + * $obj->repeatEveryWeek(10, 4) will be repeated every 10 month (70days) only 4 times + * + * @param int $frequency Frequency the object will be repeated + * @param int $nbRepetition Time the object will be repeated (0 = infinite) + * + * @return $this + */ + public function repeatEveryMonth($frequency = 1, $nbRepetition = null) + { + $this->_repeatEveryPeriod($period = 'M', $frequency, $nbRepetition); + + return $this; + } + + /** + * Set the Object to be repeated every year + * Ex : $obj->repeatEveryWeek() will be repeated every year indefinitely + * $obj->repeatEveryWeek(10) will be repeated every 10 year indefinitely + * $obj->repeatEveryWeek(10, 4) will be repeated every 10 year only 4 times + * + * @param int $frequency Frequency the object will be repeated + * @param int $nbRepetition Time the object will be repeated + * + * @return $this + */ + public function repeatEveryYear($frequency = 1, $nbRepetition = null) + { + $this->_repeatEveryPeriod($period = 'Y', $frequency, $nbRepetition); + + return $this; + } + + /** + * Set the Object to be repeated every Period + * Ex : $obj->repeatEveryPeriod('D') will be repeated every day once + * $obj->repeatEveryPeriod('W', 10) will be repeated every 10 week once + * $obj->repeatEveryPeriod('M', 10, 4) will be repeated every 10 month only 4 times + * + * @param string $period Period Y|M||D|W + * @param int $frequency Frequency the object will be repeated + * @param int $nbRepetition Time the object will be repeated + * + * @return $this + */ + private function _repeatEveryPeriod($period, $frequency = 1, $nbRepetition = null) + { + if (is_numeric($frequency) && $frequency > 0) { + $this->interval = new \DateInterval('P' . $frequency . $period); + } + + if (is_numeric($nbRepetition) && $nbRepetition > 0) { + $this->recurrences = $nbRepetition; + } + + $this->generateDatePeriod(); + + return $this; + } + + + + /** + * Set Start time + * + * @param \DateTime $from Start time + * + * @return $this + */ + public function setFrom($from) + { + $this->from = $from; + + return $this; + } + + /** + * Get Start time + * + * @return \DateTime + */ + public function getFrom() + { + return clone $this->from; + } + + /** + * Set DatePeriod + * + * @param DatePeriod $datePeriod DatePeriod + * + * @return $this + */ + public function setDatePeriod(DatePeriod $datePeriod) + { + $this->datePeriod = $datePeriod; + + return $this; + } + + /** + * Get date DatePeriod + * + * @return DatePeriod + */ + public function getDatePeriod() + { + return clone $this->datePeriod; + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Rule/AvailableForXArticles.php b/core/lib/Thelia/Coupon/Rule/AvailableForXArticles.php new file mode 100644 index 000000000..1fac12f94 --- /dev/null +++ b/core/lib/Thelia/Coupon/Rule/AvailableForXArticles.php @@ -0,0 +1,77 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Coupon\Rule; + +use Thelia\Type\IntType; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Check a Checkout against its Product number + * + * @package Coupon + * @author Guillaume MOREL + * + */ +class AvailableForXArticles extends CouponRuleAbstract +{ + /** + * @inheritdoc + */ + public function checkBackOfficeIntput() + { + $ret = false; + $validator = new IntType(); + $firstParam = reset($this->validators); + if ($firstParam) { + $ret = $validator->isValid($firstParam); + } + + return $ret; + } + + public function checkCheckoutInput() + { + $ret = false; + $validator = new IntType(); + $firstParam = reset($this->validated); + if ($firstParam) { + $ret = $validator->isValid($firstParam); + } + + return $ret; + } + + public function isMatching() + { + if ($this->checkBackOfficeIntput() && $this->checkCheckoutInput()) { + $firstValidatorsParam = reset($this->validators); + $firstValidatedParam = reset($this->validated); +// if($firstValidatedParam >= $firstValidatedParam) + } + } + +} \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Rule/CouponRuleAbstract.php b/core/lib/Thelia/Coupon/Rule/CouponRuleAbstract.php index 1c30f0321..4a01494ae 100644 --- a/core/lib/Thelia/Coupon/Rule/CouponRuleAbstract.php +++ b/core/lib/Thelia/Coupon/Rule/CouponRuleAbstract.php @@ -36,6 +36,24 @@ namespace Thelia\Coupon\Rule; */ class CouponRuleAbstract implements CuponRuleInterface { + /** @var array Parameters validating $validated against */ + protected $validators = array(); + + /** @var array Parameters to be validated */ + protected $validated = array(); + + /** + * Constructor + * + * @param array $validators Parameters validating $validated against + * @param array $validated Parameters to be validated + */ + public function __construct(array $validators, array $validated) + { + $this->validators = $validators; + $this->validated = $validated; + } + /** * Check if backoffice inputs are relevant or not * diff --git a/core/lib/Thelia/Tests/Coupon/Parameter/DateParamTest.php b/core/lib/Thelia/Tests/Coupon/Parameter/DateParamTest.php new file mode 100644 index 000000000..7ba6610df --- /dev/null +++ b/core/lib/Thelia/Tests/Coupon/Parameter/DateParamTest.php @@ -0,0 +1,96 @@ +compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\DateParam::compareTo + * + */ + public function testEquelsDate() + { + $dateValidator = new \DateTime("2012-07-08"); + $dateToValidate = new \DateTime("2012-07-08"); + + $dateParam = new DateParam($dateValidator); + + $expected = 0; + $actual = $dateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\DateParam::compareTo + * + */ + public function testSuperiorDate() + { + $dateValidator = new \DateTime("2012-07-08"); + $dateToValidate = new \DateTime("2012-07-09"); + + $dateParam = new DateParam($dateValidator); + + $expected = -1; + $actual = $dateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Coupon\Parameter\DateParam::compareTo + * @expectedException InvalidArgumentException + */ + public function testInvalidArgumentException() + { + $dateValidator = new \DateTime("2012-07-08"); + $dateToValidate = 1377012588; + + $dateParam = new DateParam($dateValidator); + + $dateParam->compareTo($dateToValidate); + } + + + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + +} diff --git a/core/lib/Thelia/Tests/Coupon/Parameter/IntervalParamTest.php b/core/lib/Thelia/Tests/Coupon/Parameter/IntervalParamTest.php new file mode 100644 index 000000000..0c1018af5 --- /dev/null +++ b/core/lib/Thelia/Tests/Coupon/Parameter/IntervalParamTest.php @@ -0,0 +1,121 @@ +compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo + * + */ + public function testEqualsDate() + { + $dateValidatorStart = new \DateTime("2012-07-08"); + $dateValidatorInterval = new \DateInterval("P1M"); //1month + $dateToValidate = new \DateTime("2012-07-08"); + + echo '1 ' . date_format($dateValidatorStart, 'g:ia \o\n l jS F Y') . "\n"; + echo '2 ' . date_format($dateToValidate, 'g:ia \o\n l jS F Y') . "\n"; + + $dateParam = new IntervalParam($dateValidatorStart, $dateValidatorInterval); + + $expected = 0; + $actual = $dateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo + * + */ + public function testEqualsDate2() + { + $dateValidatorStart = new \DateTime("2012-07-08"); + $dateValidatorInterval = new \DateInterval("P1M"); //1month + $dateToValidate = new \DateTime("2012-08-08"); + + $dateParam = new IntervalParam($dateValidatorStart, $dateValidatorInterval); + + $expected = 0; + $actual = $dateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo + * + */ + public function testSuperiorDate() + { + $dateValidatorStart = new \DateTime("2012-07-08"); + $dateValidatorInterval = new \DateInterval("P1M"); //1month + $dateToValidate = new \DateTime("2012-08-09"); + + $dateParam = new IntervalParam($dateValidatorStart, $dateValidatorInterval); + + $expected = -1; + $actual = $dateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Coupon\Parameter\DateParam::compareTo + * @expectedException InvalidArgumentException + */ + public function testInvalidArgumentException() + { + $dateValidatorStart = new \DateTime("2012-07-08"); + $dateValidatorInterval = new \DateInterval("P1M"); //1month + $dateToValidate = 1377012588; + + $dateParam = new IntervalParam($dateValidatorStart, $dateValidatorInterval); + + $dateParam->compareTo($dateToValidate); + } + + + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + +} diff --git a/core/lib/Thelia/Tests/Coupon/Parameter/RepeatedDateParamTest.php b/core/lib/Thelia/Tests/Coupon/Parameter/RepeatedDateParamTest.php new file mode 100644 index 000000000..5d5f1badc --- /dev/null +++ b/core/lib/Thelia/Tests/Coupon/Parameter/RepeatedDateParamTest.php @@ -0,0 +1,238 @@ +setFrom($startDateValidator); + $repeatedDateParam->repeatEveryMonth(); + + $expected = -1; + $actual = $repeatedDateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo + * + */ + public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriod() + { + $startDateValidator = new \DateTime("2012-07-08"); + $dateToValidate = new \DateTime("2012-07-08"); + + $repeatedDateParam = new RepeatedDateParam(); + $repeatedDateParam->setFrom($startDateValidator); + $repeatedDateParam->repeatEveryMonth(); + + $expected = 0; + $actual = $repeatedDateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo + * + */ + public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriod() + { + $startDateValidator = new \DateTime("2012-07-08"); + $dateToValidate = new \DateTime("2012-08-08"); + + $repeatedDateParam = new RepeatedDateParam(); + $repeatedDateParam->setFrom($startDateValidator); + $repeatedDateParam->repeatEveryMonth(); + + $expected = 0; + $actual = $repeatedDateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo + * + */ + public function testEqualsDateRepeatEveryMonthTenTimesThirdPeriod() + { + $startDateValidator = new \DateTime("2012-07-08"); + $dateToValidate = new \DateTime("2012-09-08"); + + $repeatedDateParam = new RepeatedDateParam(); + $repeatedDateParam->setFrom($startDateValidator); + $repeatedDateParam->repeatEveryMonth(1, 10); + + $expected = 0; + $actual = $repeatedDateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo + * + */ + public function testEqualsDateRepeatEveryMonthTenTimesTensPeriod() + { + $startDateValidator = new \DateTime("2012-07-08"); + $dateToValidate = new \DateTime("2013-05-08"); + + $repeatedDateParam = new RepeatedDateParam(); + $repeatedDateParam->setFrom($startDateValidator); + $repeatedDateParam->repeatEveryMonth(1, 10); + + $expected = 0; + $actual = $repeatedDateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo + * + */ + public function testEqualsDateRepeatEveryFourMonthTwoTimesSecondPeriod() + { + $startDateValidator = new \DateTime("2012-07-08"); + $dateToValidate = new \DateTime("2012-11-08"); + + $repeatedDateParam = new RepeatedDateParam(); + $repeatedDateParam->setFrom($startDateValidator); + $repeatedDateParam->repeatEveryMonth(4, 2); + + $expected = 0; + $actual = $repeatedDateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo + * + */ + public function testEqualsDateRepeatEveryFourMonthTwoTimesLastPeriod() + { + $startDateValidator = new \DateTime("2012-07-08"); + $dateToValidate = new \DateTime("2013-03-08"); + + $repeatedDateParam = new RepeatedDateParam(); + $repeatedDateParam->setFrom($startDateValidator); + $repeatedDateParam->repeatEveryMonth(4, 2); + + $expected = 0; + $actual = $repeatedDateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo + * + */ + public function testNotEqualsDateRepeatEveryFourMonthTwoTimes1() + { + $startDateValidator = new \DateTime("2012-07-08"); + $dateToValidate = new \DateTime("2012-08-08"); + + $repeatedDateParam = new RepeatedDateParam(); + $repeatedDateParam->setFrom($startDateValidator); + $repeatedDateParam->repeatEveryMonth(4, 2); + + $expected = -1; + $actual = $repeatedDateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo + * + */ + public function testNotEqualsDateRepeatEveryFourMonthTwoTimes2() + { + $startDateValidator = new \DateTime("2012-07-08"); + $dateToValidate = new \DateTime("2012-12-08"); + + $repeatedDateParam = new RepeatedDateParam(); + $repeatedDateParam->setFrom($startDateValidator); + $repeatedDateParam->repeatEveryMonth(4, 2); + + $expected = -1; + $actual = $repeatedDateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo + * + */ + public function testSuperiorDateRepeatEveryFourMonthTwoTimes() + { + $startDateValidator = new \DateTime("2012-07-08"); + $dateToValidate = new \DateTime("2013-03-09"); + + $repeatedDateParam = new RepeatedDateParam(); + $repeatedDateParam->setFrom($startDateValidator); + $repeatedDateParam->repeatEveryMonth(4, 2); + + $expected = -1; + $actual = $repeatedDateParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * @covers Thelia\Coupon\Parameter\DateParam::compareTo + * @expectedException InvalidArgumentException + */ + public function testInvalidArgumentException() + { + $startDateValidator = new \DateTime("2012-07-08"); + $dateToValidate = 1377012588; + + $repeatedDateParam = new RepeatedDateParam(); + $repeatedDateParam->setFrom($startDateValidator); + $repeatedDateParam->repeatEveryMonth(4, 2); + + $repeatedDateParam->compareTo($dateToValidate); + } + + + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + +} diff --git a/core/lib/Thelia/Tests/Coupon/Parameter/RepeatedIntervalParamTest.php b/core/lib/Thelia/Tests/Coupon/Parameter/RepeatedIntervalParamTest.php new file mode 100644 index 000000000..0783bac3e --- /dev/null +++ b/core/lib/Thelia/Tests/Coupon/Parameter/RepeatedIntervalParamTest.php @@ -0,0 +1,327 @@ +setFrom($startDateValidator); + $RepeatedIntervalParam->setDurationInDays($duration); + + $RepeatedIntervalParam->repeatEveryMonth(); + + $expected = -1; + $actual = $RepeatedIntervalParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo + * + */ + public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodBegining() + { + $startDateValidator = new \DateTime("2012-07-08"); + $dateToValidate = new \DateTime("2012-07-08"); + $duration = 10; + + $RepeatedIntervalParam = new RepeatedIntervalParam(); + $RepeatedIntervalParam->setFrom($startDateValidator); + $RepeatedIntervalParam->setDurationInDays($duration); + $RepeatedIntervalParam->repeatEveryMonth(); + + $expected = 0; + $actual = $RepeatedIntervalParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo + * + */ + public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodMiddle() + { + $startDateValidator = new \DateTime("2012-07-08"); + $dateToValidate = new \DateTime("2012-07-13"); + $duration = 10; + + $RepeatedIntervalParam = new RepeatedIntervalParam(); + $RepeatedIntervalParam->setFrom($startDateValidator); + $RepeatedIntervalParam->setDurationInDays($duration); + $RepeatedIntervalParam->repeatEveryMonth(); + + $expected = 0; + $actual = $RepeatedIntervalParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo + * + */ + public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodEnding() + { + $startDateValidator = new \DateTime("2012-07-08"); + $dateToValidate = new \DateTime("2012-07-18"); + $duration = 10; + + $RepeatedIntervalParam = new RepeatedIntervalParam(); + $RepeatedIntervalParam->setFrom($startDateValidator); + $RepeatedIntervalParam->setDurationInDays($duration); + $RepeatedIntervalParam->repeatEveryMonth(); + + $expected = 0; + $actual = $RepeatedIntervalParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo + * + */ + public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodBegining() + { + $startDateValidator = new \DateTime("2012-08-08"); + $dateToValidate = new \DateTime("2012-08-08"); + $duration = 10; + + $RepeatedIntervalParam = new RepeatedIntervalParam(); + $RepeatedIntervalParam->setFrom($startDateValidator); + $RepeatedIntervalParam->setDurationInDays($duration); + $RepeatedIntervalParam->repeatEveryMonth(); + + $expected = 0; + $actual = $RepeatedIntervalParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo + * + */ + public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodMiddle() + { + $startDateValidator = new \DateTime("2012-08-08"); + $dateToValidate = new \DateTime("2012-08-13"); + $duration = 10; + + $RepeatedIntervalParam = new RepeatedIntervalParam(); + $RepeatedIntervalParam->setFrom($startDateValidator); + $RepeatedIntervalParam->setDurationInDays($duration); + $RepeatedIntervalParam->repeatEveryMonth(); + + $expected = 0; + $actual = $RepeatedIntervalParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo + * + */ + public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodEnding() + { + $startDateValidator = new \DateTime("2012-08-08"); + $dateToValidate = new \DateTime("2012-08-18"); + $duration = 10; + + $RepeatedIntervalParam = new RepeatedIntervalParam(); + $RepeatedIntervalParam->setFrom($startDateValidator); + $RepeatedIntervalParam->setDurationInDays($duration); + $RepeatedIntervalParam->repeatEveryMonth(); + + $expected = 0; + $actual = $RepeatedIntervalParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo + * + */ + public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodBegining() + { + $startDateValidator = new \DateTime("2012-10-08"); + $dateToValidate = new \DateTime("2012-10-08"); + $duration = 10; + + $RepeatedIntervalParam = new RepeatedIntervalParam(); + $RepeatedIntervalParam->setFrom($startDateValidator); + $RepeatedIntervalParam->setDurationInDays($duration); + $RepeatedIntervalParam->repeatEveryMonth(1, 4); + + $expected = 0; + $actual = $RepeatedIntervalParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo + * + */ + public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodMiddle() + { + $startDateValidator = new \DateTime("2012-10-08"); + $dateToValidate = new \DateTime("2012-10-13"); + $duration = 10; + + $RepeatedIntervalParam = new RepeatedIntervalParam(); + $RepeatedIntervalParam->setFrom($startDateValidator); + $RepeatedIntervalParam->setDurationInDays($duration); + $RepeatedIntervalParam->repeatEveryMonth(1, 4); + + $expected = 0; + $actual = $RepeatedIntervalParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo + * + */ + public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodEnding() + { + $startDateValidator = new \DateTime("2012-10-08"); + $dateToValidate = new \DateTime("2012-10-18"); + $duration = 10; + + $RepeatedIntervalParam = new RepeatedIntervalParam(); + $RepeatedIntervalParam->setFrom($startDateValidator); + $RepeatedIntervalParam->setDurationInDays($duration); + $RepeatedIntervalParam->repeatEveryMonth(1, 4); + + $expected = 0; + $actual = $RepeatedIntervalParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo + * + */ + public function testNotEqualsDateRepeatEveryMonthFourTimeInTheBegining() + { + $startDateValidator = new \DateTime("2012-10-08"); + $dateToValidate = new \DateTime("2012-07-19"); + $duration = 10; + + $RepeatedIntervalParam = new RepeatedIntervalParam(); + $RepeatedIntervalParam->setFrom($startDateValidator); + $RepeatedIntervalParam->setDurationInDays($duration); + $RepeatedIntervalParam->repeatEveryMonth(1, 4); + + $expected = -1; + $actual = $RepeatedIntervalParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo + * + */ + public function testNotEqualsDateRepeatEveryMonthFourTimeInTheMiddle() + { + $startDateValidator = new \DateTime("2012-10-08"); + $dateToValidate = new \DateTime("2012-08-01"); + $duration = 10; + + $RepeatedIntervalParam = new RepeatedIntervalParam(); + $RepeatedIntervalParam->setFrom($startDateValidator); + $RepeatedIntervalParam->setDurationInDays($duration); + $RepeatedIntervalParam->repeatEveryMonth(1, 4); + + $expected = -1; + $actual = $RepeatedIntervalParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo + * + */ + public function testNotEqualsDateRepeatEveryMonthFourTimeInTheEnd() + { + $startDateValidator = new \DateTime("2012-10-08"); + $dateToValidate = new \DateTime("2012-08-07"); + $duration = 10; + + $RepeatedIntervalParam = new RepeatedIntervalParam(); + $RepeatedIntervalParam->setFrom($startDateValidator); + $RepeatedIntervalParam->setDurationInDays($duration); + $RepeatedIntervalParam->repeatEveryMonth(1, 4); + + $expected = -1; + $actual = $RepeatedIntervalParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + + + /** + * + * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo + * + */ + public function testSuperiorDateRepeatEveryMonthFourTime() + { + $startDateValidator = new \DateTime("2012-10-08"); + $dateToValidate = new \DateTime("2012-10-19"); + $duration = 10; + + $RepeatedIntervalParam = new RepeatedIntervalParam(); + $RepeatedIntervalParam->setFrom($startDateValidator); + $RepeatedIntervalParam->setDurationInDays($duration); + $RepeatedIntervalParam->repeatEveryMonth(1, 4); + + $expected = -1; + $actual = $RepeatedIntervalParam->compareTo($dateToValidate); + $this->assertEquals($expected, $actual); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + +} diff --git a/core/lib/Thelia/Tests/Coupon/Rule/AvailableForNbArticlesTest.php b/core/lib/Thelia/Tests/Coupon/Rule/AvailableForNbArticlesTest.php deleted file mode 100644 index ed8a57833..000000000 --- a/core/lib/Thelia/Tests/Coupon/Rule/AvailableForNbArticlesTest.php +++ /dev/null @@ -1,26 +0,0 @@ -getMock( + 'CouponBaseAdapter', + array('getNbArticlesInTheCart'), + array() + ); + $stubTheliaAdapater->expects($this->any()) + ->method('getNbArticlesInTheCart') + ->will($this->returnValue(4)); + + return $stubTheliaAdapater; + } + + /** + * + * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeIntput + * + */ + public function testValidBackOfficeInput() + { + /** @var CouponAdapterInterface $stubTheliaAdapater */ + $stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock(); + + $validators = array(4); + $validated = array($stubTheliaAdapater->getNbArticlesInTheCart()); + $rule = new AvailableForXArticles($validators, $validated); + + $expected = true; + $actual = $rule->checkBackOfficeIntput(); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeIntput + * + */ + public function testInValidBackOfficeInput() + { + /** @var CouponAdapterInterface $stubTheliaAdapater */ + $stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock(); + + $validators = array(4.5); + $validated = array($stubTheliaAdapater->getNbArticlesInTheCart()); + $rule = new AvailableForXArticles($validators, $validated); + + $expected = false; + $actual = $rule->checkBackOfficeIntput(); + $this->assertEquals($expected, $actual); + + $validators = array(-1); + $validated = array($stubTheliaAdapater->getNbArticlesInTheCart()); + $rule = new AvailableForXArticles($validators, $validated); + + $expected = false; + $actual = $rule->checkBackOfficeIntput(); + $this->assertEquals($expected, $actual); + + $validators = array('bad'); + $validated = array($stubTheliaAdapater->getNbArticlesInTheCart()); + $rule = new AvailableForXArticles($validators, $validated); + + $expected = false; + $actual = $rule->checkBackOfficeIntput(); + $this->assertEquals($expected, $actual); + } + + + + /** + * + * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput + * + */ + public function testValidCheckoutInput() + { + /** @var CouponAdapterInterface $stubTheliaAdapater */ + $stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock(); + + $validators = array(4); + $validated = array($stubTheliaAdapater->getNbArticlesInTheCart()); + $rule = new AvailableForXArticles($validators, $validated); + + $expected = true; + $actual = $rule->checkCheckoutInput(); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput + * + */ + public function testInValidCheckoutInput() + { + /** @var CouponAdapterInterface $stubTheliaAdapater */ + $stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock(); + + $validators = array(4.5); + $validated = array($stubTheliaAdapater->getNbArticlesInTheCart()); + $rule = new AvailableForXArticles($validators, $validated); + + $expected = false; + $actual = $rule->checkCheckoutInput(); + $this->assertEquals($expected, $actual); + + $validators = array(-1); + $validated = array($stubTheliaAdapater->getNbArticlesInTheCart()); + $rule = new AvailableForXArticles($validators, $validated); + + $expected = false; + $actual = $rule->checkCheckoutInput(); + $this->assertEquals($expected, $actual); + + $validators = array('bad'); + $validated = array($stubTheliaAdapater->getNbArticlesInTheCart()); + $rule = new AvailableForXArticles($validators, $validated); + + $expected = false; + $actual = $rule->checkCheckoutInput(); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching + * + */ + public function testMatchingRuleEqual() + { + /** @var CouponAdapterInterface $stubTheliaAdapater */ + $stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock(); + + $validators = array(4); + $validated = array($stubTheliaAdapater->getNbArticlesInTheCart()); + $rule = new AvailableForXArticles($validators, $validated); + + $expected = true; + $actual = $rule->isMatching(); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching + * + */ + public function testMatchingRuleSuperior() + { + /** @var CouponAdapterInterface $stubTheliaAdapater */ + $stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock(); + + $validators = array(5); + $validated = array($stubTheliaAdapater->getNbArticlesInTheCart()); + $rule = new AvailableForXArticles($validators, $validated); + + $expected = true; + $actual = $rule->isMatching(); + $this->assertEquals($expected, $actual); + } + + /** + * + * @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching + * + */ + public function testNotMatchingRule() + { + /** @var CouponAdapterInterface $stubTheliaAdapater */ + $stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock(); + + $validators = array(3); + $validated = array($stubTheliaAdapater->getNbArticlesInTheCart()); + $rule = new AvailableForXArticles($validators, $validated); + + $expected = false; + $actual = $rule->isMatching(); + $this->assertEquals($expected, $actual); + } + + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + +}