Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove option functionality except set and clear. It doesn't make sen…

…se to partially set options and it also prevents option validation
  • Loading branch information...
commit d256a145ca9a601eb82f42dd92dd1bf17c28db68 1 parent 6382516
@iampersistent iampersistent authored
View
14 lib/Vespolina/Entity/Exception/InvalidOptionsException.php
@@ -0,0 +1,14 @@
+<?php
+/**
+ * (c) 2012 Vespolina Project http://www.vespolina-project.org
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace Vespolina\Entity\Exception;
+
+class InvalidOptionsException extends \Exception
+{
+
+}
View
63 tests/Entity/Order/ItemTest.php
@@ -12,64 +12,47 @@ public function testOptionMethods()
$rmSetProduct = new \ReflectionMethod($item, 'setProduct');
$rmSetProduct->setAccessible(true);
- $rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate()));
$this->assertNull($item->getOption('noOption'));
- $rmAddOption = new \ReflectionMethod($item, 'addOption');
- $rmAddOption->setAccessible(true);
- $rmAddOption->invokeArgs($item, array('option1', 1));
- $this->assertCount(1, $item->getOptions());
- $this->assertSame(1, $item->getOption('option1'));
-
- $rmAddOption->invokeArgs($item, array('option2', 2));
- $this->assertCount(2, $item->getOptions());
- $this->assertSame(2, $item->getOption('option2'));
-
- $rmRemoveOption = new \ReflectionMethod($item, 'removeOption');
- $rmRemoveOption->setAccessible(true);
- $rmRemoveOption->invoke($item, 'option2');
- $this->assertCount(1, $item->getOptions(), 'remove by option');
- $this->assertNull($item->getOption('option2'));
-
- $options = array(
- 'option2' => 2,
- 'option3' => 3
- );
-
- $rmAddOptions = new \ReflectionMethod($item, 'addOptions');
- $rmAddOptions->setAccessible(true);
- $rmAddOptions->invoke($item, $options);
- $this->assertCount(3, $item->getOptions());
- $this->assertSame(2, $item->getOption('option2'));
- $this->assertSame(3, $item->getOption('option3'));
-
$rmSetOptions = new \ReflectionMethod($item, 'setOptions');
$rmSetOptions->setAccessible(true);
- $rmSetOptions->invoke($item, $options);
- $this->assertCount(2, $item->getOptions());
- $this->assertNull($item->getOption('option1'));
- $this->assertSame(2, $item->getOption('option2'));
- $this->assertSame(3, $item->getOption('option3'));
- $rmRemoveOption->invoke($item, 'option3');
- $this->assertCount(1, $item->getOptions(), 'option should be removed by type');
+ $rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate()));
+ $rmSetOptions->invoke($item, array(
+ 'option2' => 2,
+ 'option3' => 3
+ ));
- $rmRemoveOption->invoke($item, 'nada');
- $this->assertCount(1, $item->getOptions());
+ $options = $item->getOptions();
+ $this->assertCount(2, $options);
+ $this->assertArrayHasKey('option2', $options);
+ $this->assertArrayHasKey('option3', $options);
$rmClearOptions = new \ReflectionMethod($item, 'clearOptions');
$rmClearOptions->setAccessible(true);
+
+ $rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate(false)));
+ $this->setExpectedException('Vespolina\Entity\Exception\InvalidOptionsException');
+ $rmClearOptions->invoke($item);
+ $this->assertSame($options, $item->getOptions(), 'nothing should have been removed if the validation fails');
+
+ $rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate()));
$rmClearOptions->invoke($item);
$this->assertEmpty($item->getOptions());
+
+ $rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate(false)));
+ $this->setExpectedException('Vespolina\Entity\Exception\InvalidOptionsException');
+ $rmSetOptions->invokeArgs($item, array('failure' => 0));
+ $this->assertEmpty($item->getOptions(), 'nothing should be added if the validation fails');
}
- protected function createProductOptionValidate()
+ protected function createProductOptionValidate($returns = true)
{
$product = $this->getMock('Vespolina\Entity\Product');
$product->expects($this->atLeastOnce())
->method('validateOptions')
- ->will($this->returnValue(true));
+ ->will($this->returnValue($returns));
return $product;
}
Please sign in to comment.
Something went wrong with that request. Please try again.