Refactor removing Manager notion

This commit is contained in:
gmorel
2013-11-23 20:18:04 +01:00
parent 8ce1030178
commit 90b5fbde05
34 changed files with 442 additions and 411 deletions

View File

@@ -25,9 +25,9 @@ namespace Thelia\Coupon;
use Thelia\Condition\ConditionCollection;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\ConditionFactory;
use Thelia\Condition\Implementation\MatchForTotalAmountManager;
use Thelia\Condition\Implementation\MatchForTotalAmount;
use Thelia\Condition\Operators;
use Thelia\Coupon\Type\RemoveXAmountManager;
use Thelia\Coupon\Type\RemoveXAmount;
use Thelia\Model\Coupon;
use Thelia\Model\CurrencyQuery;
@@ -131,25 +131,25 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
$date = new \DateTime();
$coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 3 months")));
$condition1 = new MatchForTotalAmountManager($facade);
$condition1 = new MatchForTotalAmount($facade);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
MatchForTotalAmount::INPUT1 => Operators::SUPERIOR,
MatchForTotalAmount::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 40.00,
MatchForTotalAmountManager::INPUT2 => 'EUR'
MatchForTotalAmount::INPUT1 => 40.00,
MatchForTotalAmount::INPUT2 => 'EUR'
);
$condition1->setValidatorsFromForm($operators, $values);
$condition2 = new MatchForTotalAmountManager($facade);
$condition2 = new MatchForTotalAmount($facade);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
MatchForTotalAmount::INPUT1 => Operators::INFERIOR,
MatchForTotalAmount::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR'
MatchForTotalAmount::INPUT1 => 400.00,
MatchForTotalAmount::INPUT2 => 'EUR'
);
$condition2->setValidatorsFromForm($operators, $values);
@@ -178,36 +178,67 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
}
/**
* @covers Thelia\Coupon\CouponFactory::buildCouponFromCode
* @covers Thelia\Coupon\CouponFactory::buildCouponManagerFromCode
*/
public function testBuildCouponFromCode()
{
$stubFacade = $this->generateFacadeStub();
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
->disableOriginalConstructor()
->getMock();
$stubContainer = $this->getMock('\Symfony\Component\DependencyInjection\Container');
$conditionFactory = new ConditionFactory($stubContainer);
$expected = $this->generateCouponModel($stubFacade, $conditionFactory);
$couponModel = $this->generateCouponModel($stubFacade, $conditionFactory);
$stubFacade->expects($this->any())
->method('findOneCouponByCode')
->will($this->returnValue($expected));
$stubContainer->expects($this->at(0))
->method('get')
->will($this->returnValue($stubFacade));
->will($this->returnValue($couponModel));
$couponManager = new RemoveXAmountManager();
$stubContainer->expects($this->at(1))
$couponManager = new RemoveXAmount($stubFacade);
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::INPUT1 => Operators::SUPERIOR,
MatchForTotalAmount::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::INPUT1 => 40.00,
MatchForTotalAmount::INPUT2 => 'EUR'
);
$condition1->setValidatorsFromForm($operators, $values);
$condition2 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::INPUT1 => Operators::INFERIOR,
MatchForTotalAmount::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::INPUT1 => 400.00,
MatchForTotalAmount::INPUT2 => 'EUR'
);
$condition2->setValidatorsFromForm($operators, $values);
$conditions = new ConditionCollection();
$conditions->add($condition1);
$conditions->add($condition2);
$stubConditionFactory = $this->getMockBuilder('\Thelia\Condition\ConditionFactory')
->disableOriginalConstructor()
->getMock();
$stubConditionFactory->expects($this->any())
->method('unserializeConditionCollection')
->will($this->returnValue($conditions));
$stubContainer->expects($this->any())
->method('get')
->will($this->returnValue($couponManager));
->will($this->onConsecutiveCalls($stubFacade, $couponManager, $stubConditionFactory));
$stubContainer->expects($this->any())
->method('has')
->will($this->returnValue(true));
$factory = new CouponFactory($stubContainer);
$actual = $factory->buildCouponFromCode('XMAS');
$expected = $couponManager;
$actual = $factory->buildCouponManagerFromCode('XMAS');
$this->assertEquals($expected, $actual);
}

View File

@@ -28,17 +28,17 @@ namespace Thelia\Coupon\Type;
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test RemoveXAmountManager Class
* Unit Test RemoveXAmount Class
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-11-17 at 18:59:24.
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class RemoveXAmountManagerTest extends \PHPUnit_Framework_TestCase
class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
{
/**
* @var RemoveXAmountManager
* @var RemoveXAmount
*/
protected $object;
@@ -48,7 +48,7 @@ class RemoveXAmountManagerTest extends \PHPUnit_Framework_TestCase
*/
protected function setUp()
{
// $this->object = new RemoveXAmountManager;
// $this->object = new RemoveXAmount;
}
/**
@@ -60,7 +60,7 @@ class RemoveXAmountManagerTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers Thelia\Coupon\Type\RemoveXAmountManager::set
* @covers Thelia\Coupon\Type\RemoveXAmount::set
* @todo Implement testSet().
*/
public function testSet()
@@ -72,7 +72,7 @@ class RemoveXAmountManagerTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers Thelia\Coupon\Type\RemoveXAmountManager::getName
* @covers Thelia\Coupon\Type\RemoveXAmount::getName
* @todo Implement testGetName().
*/
public function testGetName()
@@ -84,7 +84,7 @@ class RemoveXAmountManagerTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers Thelia\Coupon\Type\RemoveXAmountManager::getToolTip
* @covers Thelia\Coupon\Type\RemoveXAmount::getToolTip
* @todo Implement testGetToolTip().
*/
public function testGetToolTip()

View File

@@ -28,17 +28,17 @@ namespace Thelia\Coupon\Type;
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test RemoveXPercentManager Class
* Unit Test RemoveXPercent Class
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-11-17 at 18:59:24.
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class RemoveXPercentManagerTest extends \PHPUnit_Framework_TestCase
class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
{
/**
* @var RemoveXPercentManager
* @var RemoveXPercent
*/
protected $object;
@@ -48,7 +48,7 @@ class RemoveXPercentManagerTest extends \PHPUnit_Framework_TestCase
*/
protected function setUp()
{
// $this->object = new RemoveXPercentManager;
// $this->object = new RemoveXPercent;
}
/**
@@ -60,7 +60,7 @@ class RemoveXPercentManagerTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers Thelia\Coupon\Type\RemoveXPercentManager::set
* @covers Thelia\Coupon\Type\RemoveXPercent::set
* @todo Implement testSet().
*/
public function testSet()
@@ -72,7 +72,7 @@ class RemoveXPercentManagerTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers Thelia\Coupon\Type\RemoveXPercentManager::exec
* @covers Thelia\Coupon\Type\RemoveXPercent::exec
* @todo Implement testExec().
*/
public function testExec()
@@ -84,7 +84,7 @@ class RemoveXPercentManagerTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers Thelia\Coupon\Type\RemoveXPercentManager::getName
* @covers Thelia\Coupon\Type\RemoveXPercent::getName
* @todo Implement testGetName().
*/
public function testGetName()
@@ -96,7 +96,7 @@ class RemoveXPercentManagerTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers Thelia\Coupon\Type\RemoveXPercentManager::getToolTip
* @covers Thelia\Coupon\Type\RemoveXPercent::getToolTip
* @todo Implement testGetToolTip().
*/
public function testGetToolTip()