Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updates to pricing

  • Loading branch information...
commit 6a69e4ed58998ff20d7974a145981fdc917dbf70 1 parent 194a89a
@iampersistent iampersistent authored
View
40 lib/Vespolina/Entity/Pricing/Element/RecurringElement.php
@@ -11,57 +11,55 @@
class RecurringElement extends PricingElement
{
- protected $cycles;
- protected $interval;
- protected $processed = true;
- protected $startsIn;
+ public function __construct()
+ {
+ $attribute['cycles'] = '';
+ $attribute['interval'] = '';
+ $attribute['startsIn'] = null;
+
+ parent::__construct();
+ }
public function setCycles($cycles)
{
- $this->cycles = $cycles;
+ $this->attributes['cycles'] = $cycles;
return $this;
}
public function getCycles()
{
- return $this->cycles;
+ return $this->attributes['cycles'];
}
public function setInterval($interval)
{
- $this->interval = $interval;
+ $this->attributes['interval'] = $interval;
return $this;
}
public function getInterval()
{
- return $this->interval;
+ return $this->attributes['interval'];
}
- public function setProcessed($processed)
+ public function setStartsIn($startsIn)
{
- $this->processed = $processed;
+ $this->attributes['startsIn'] = $startsIn;
return $this;
}
- public function getProcessed()
+ public function getStartsIn()
{
- return $this->processed;
+ return $this->attributes['startsIn'];
}
- public function setStartsIn($startsIn)
+ protected function doProcess($context, $processed)
{
- $this->startsIn = $startsIn;
+ $processed['netValue'] = $this->attribute['netValue'];
- return $this;
- }
-
- public function getStartsIn()
- {
- return $this->startsIn;
+ return $processed;
}
-
}
View
47 lib/Vespolina/Entity/Pricing/PricingElement.php
@@ -12,29 +12,21 @@
class PricingElement implements PricingElementInterface
{
- protected $netValue;
- protected $order;
- protected $processed;
- protected $value;
+ protected $attributes;
+ protected $position;
+ protected $type;
- public function setNetValue($netValue)
+ public function __construct()
{
- $this->netValue = $netValue;
-
- return $this;
- }
-
- public function getNetValue()
- {
- return $this->netValue;
+ $attribute['netValue'] = '';
}
/**
* @inheritdoc
*/
- public function setOrder($order)
+ public function setPosition($position)
{
- $this->order = $order;
+ $this->position = $position;
return $this;
}
@@ -42,35 +34,20 @@ public function setOrder($order)
/**
* @inheritdoc
*/
- public function getOrder()
+ public function getPosition()
{
- return $this->order;
+ return $this->position;
}
- public function setValue($value)
- {
- $this->value = $value;
-
- return $this;
- }
-
- public function getValue()
- {
- return $this->value;
- }
/**
* @inheritdoc
*/
- public function process()
+ public function process($context)
{
- if (!$this->processed) {
- return $this->doProcess();
- }
-
- return true;
+ return $this->doProcess($context);
}
- protected function doProcess()
+ protected function doProcess($context)
{
throw new FunctionNotSupportedException('process() has not been implemented in ' . get_class($this));
}
View
20 lib/Vespolina/Entity/Pricing/PricingElementInterface.php
@@ -11,33 +11,19 @@
interface PricingElementInterface
{
/**
- * Return the net value of this PricingElement.
- *
- * @return mixed
- */
- function getNetValue();
-
- /**
* Set the order of this element being processed. If the order is not set, it is saved until the end of the
* processing to be executed. The higher the number, the later it is executed.
*
- * @param integer $order
+ * @param integer $position
*/
- function setOrder($order);
+ function setPosition($position);
/**
* Return the order of this element's execution
*
* @return integer
*/
- function getOrder();
-
- /**
- * Return the processed value of this PricingElement.
- *
- * @return mixed
- */
- function getValue();
+ function getPosition();
/**
* Process this pricing element. The results are passed back and also available with a call to getValue(). A null is
View
4 lib/Vespolina/Entity/Pricing/PricingSetInterface.php
@@ -10,7 +10,7 @@
interface PricingSetInterface
{
- function all();
+ function getNetValue();
+ function getTotalValue();
function get($name);
- function set($name, $value);
}
View
45 tests/Entity/Pricing/PricingSetTest.php
@@ -0,0 +1,45 @@
+<?php
+
+use Vespolina\Entity\Pricing\PricingElement;
+use Vespolina\Entity\Pricing\PricingSet;
+
+class PricingSetTest extends \PHPUnit_Framework_TestCase
+{
+ public function testAddElements()
+ {
+ $pricingSet = new PricingSet();
+
+ $this->assertNull($pricingSet->getElements(), 'the elements should start empty');
+
+ $element1 = new PricingElement();
+ $pricingSet->addElement($element1);
+ $this->assertCount(1, $pricingSet->getElements());
+
+ $element2 = new PricingElement();
+ $pricingSet->addElement($element2);
+ $this->assertCount(2, $pricingSet->getElements());
+ }
+
+ public function testProcess()
+ {
+ $pricingSet = new PricingSet();
+
+ $elementNetValue = $this->getMock('Vespolina\Entity\Pricing\PricingElement', array('process'));
+ $elementNetValue->expects($this->any())
+ ->method('process')
+ ->will($this->returnValue(array('netValue' => '9.99')));
+ $elementDiscount = $this->getMock('Vespolina\Entity\Pricing\PricingElement', array('process'));
+ $elementDiscount->expects($this->any())
+ ->method('process')
+ ->will($this->returnValue(array('discount' => '.99')));
+
+ $pricingSet->process();
+
+ $this->assertEqual('9.99', $pricingSet->getNetValue(), 'the final value should be 9.99');
+ $this->assertEqual('.99', $pricingSet->getDiscount(), 'the final value should be .99');
+ $this->assertEqual('9.00', $pricingSet->getValue(), 'the final value should be 9.00');
+
+ $this->markTestIncomplete('test all default returns');
+ $this->markTestIncomplete('test custom returns');
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.