Permalink
Browse files

skip non scalars in plus()

  • Loading branch information...
iampersistent committed Feb 1, 2013
1 parent d78fd2a commit d768afe91e7fa960b54d7b25fe2add3ce2c4bbb3
Showing with 19 additions and 1 deletion.
  1. +9 −1 lib/ImmersiveLabs/Pricing/Entity/PricingSet.php
  2. +10 −0 tests/Entity/PricingSetTest.php
@@ -120,10 +120,18 @@ public function process($context = null)
public function plus($addSet)
{
$newSet = new self();
- $newSet->setProcessed($this->processed);
+ foreach ($this->getProcessed() as $key => $value) {
+ if (!is_scalar($value)) {
+ continue;
+ }
+ $newSet->set($key, $value);
+ }
if ($addSet instanceof PricingSetInterface) {
foreach ($addSet->getProcessed() as $key => $value) {
+ if (!is_scalar($value)) {
+ continue;
+ }
$total = $this->get($key) + $value;
$newSet->set($key, $total);
}
@@ -92,6 +92,16 @@ public function testPlus()
$this->assertEquals('10', $sumPricingSet->get('taxes'), 'the final value should be 10');
$this->assertEquals('10', $sumPricingSet->get('totalValue'), 'the final value should be 10');
+ $pricingSet1 = new PricingSet();
+ $pricingSet1->set('scalar', 5);
+ $pricingSet1->set('object', new PricingSet());
+ $pricingSet1->setProcessingState(PricingSet::PROCESSING_FINISHED);
+ $sumPricingSet = $pricingSet1->plus(null);
+ $this->assertInstanceOf('Vespolina\Entity\Pricing\PricingSetInterface', $sumPricingSet, 'a pricing set should be returned when nothing is added');
+ $this->assertNotSame($pricingSet1, $sumPricingSet, 'the new set should be a new object');
+ $this->assertEquals('5', $sumPricingSet->get('scalar'), 'a scalar value is set');
+ $this->assertNull($sumPricingSet->get('object'), 'a non scalar is skipped');
+
$this->markTestIncomplete('implement combining mismatched processed elements');
$this->markTestIncomplete('implement inclusions/exclusions from adding process by passing array (either white or black list?)');
}

0 comments on commit d768afe

Please sign in to comment.