Adding/Refactoring unit test

This commit is contained in:
gmorel
2013-11-17 19:59:29 +01:00
parent 274e667103
commit a2b97707cf
19 changed files with 1154 additions and 28 deletions

View File

@@ -0,0 +1,96 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Condition;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Thelia\Condition\ConditionManagerInterface;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Manage a set of ConditionManagerInterface
*
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class ConditionCollection
{
/** @var array Array of ConditionManagerInterface */
protected $conditions = array();
/**
* Get Conditions
*
* @return array Array of ConditionManagerInterface
*/
public function getConditions()
{
return $this->conditions;
}
/**
* Add a ConditionManagerInterface to the Collection
*
* @param ConditionManagerInterface $condition Condition
*
* @return $this
*/
public function add(ConditionManagerInterface $condition)
{
$this->conditions[] = $condition;
return $this;
}
/**
* Check if there is at least one condition in the collection
*
* @return bool
*/
public function isEmpty()
{
return (empty($this->conditions));
}
/**
* Allow to compare 2 set of conditions
*
* @return string Jsoned data
*/
public function __toString()
{
$arrayToSerialize = array();
/** @var ConditionManagerInterface $condition */
foreach ($this->getConditions() as $condition) {
$arrayToSerialize[] = $condition->getSerializableCondition();
}
return json_encode($arrayToSerialize);
}
}

View File

@@ -25,7 +25,7 @@ namespace Thelia\Condition;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Thelia\Condition\Operators;
use Thelia\Coupon\ConditionCollection;
use Thelia\Condition\ConditionCollection;
/**

View File

@@ -25,7 +25,7 @@ namespace Thelia\Condition;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Thelia\Coupon\FacadeInterface;
use Thelia\Coupon\ConditionCollection;
use Thelia\Condition\ConditionCollection;
/**

View File

@@ -0,0 +1,51 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Condition;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Manage how Condition could interact with each others
*
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class ConditionOrganizer implements ConditionOrganizerInterface
{
/**
* Organize ConditionManagerInterface
*
* @param array $conditions Array of ConditionManagerInterface
*
* @return array Array of ConditionManagerInterface sorted
*/
public function organize(array $conditions)
{
// @todo: Implement organize() method.
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Condition;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Manage how Condition could interact with each other
*
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
interface ConditionOrganizerInterface
{
/**
* Organize ConditionManagerInterface
*
* @param array $conditions Array of ConditionManagerInterface
*
* @return array Array of ConditionManagerInterface sorted
*/
public function organize(array $conditions);
}

View File

@@ -0,0 +1,74 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Coupon;
use Thelia\Condition\ConditionOrganizer;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test ConditionOrganizer Class
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-11-17 at 18:59:24.
*
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class ConditionOrganizerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ConditionOrganizer
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->object = new ConditionOrganizer;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
* @covers Thelia\Coupon\RuleOrganizer::organize
* @todo Implement testOrganize().
*/
public function testOrganize()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}

View File

@@ -146,15 +146,6 @@ class MatchForTotalAmountManager extends ConditionManagerAbstract
*/
public function isMatching()
{
$isOperator1Legit = $this->isOperatorLegit(
$this->operators[self::INPUT1],
$this->availableOperators[self::INPUT1]
);
$isOperator2Legit = $this->isOperatorLegit(
$this->operators[self::INPUT2],
$this->availableOperators[self::INPUT2]
);
$condition1 = $this->conditionValidator->variableOpComparison(
$this->facade->getCartTotalPrice(),
$this->operators[self::INPUT1],