Permalink
Browse files

allow the Product to be set when an Item is constructed

  • Loading branch information...
1 parent 7794691 commit c414c061f4843f1988079cd2f0cd262ba0ea6e43 @iampersistent iampersistent committed Jul 17, 2012
Showing with 21 additions and 3 deletions.
  1. +7 −1 lib/Vespolina/Entity/Order/Item.php
  2. +14 −2 tests/Entity/Order/ItemTest.php
@@ -8,8 +8,9 @@
namespace Vespolina\Entity\Order;
-use Vespolina\Entity\Exception\InvalidOptionsException;
+use Vespolina\Exception\InvalidOptionsException;
use Vespolina\Entity\Order\ItemInterface;
+use Vespolina\Entity\ProductInterface;
/**
* Item is a class for items in an order
@@ -25,6 +26,11 @@ class Item implements ItemInterface
protected $quantity;
protected $state;
+ public function __construct(ProductInterface $product = null)
+ {
+ $this->product = $product;
+ }
+
/**
* @inheritdoc
*/
@@ -1,11 +1,23 @@
<?php
use Vespolina\Entity\Order\Item;
+use Vespolina\Entity\Product;
+
/**
* @author Richard Shank <develop@zestic.com>
*/
class ItemTest extends \PHPUnit_Framework_TestCase
{
+ public function testConstruct()
+ {
+ $item = new Item();
+ $this->assertNull($item->getProduct(), 'its ok if no product is passed in');
+
+ $product = new Product();
+ $item = new Item($product);
+ $this->assertSame($product, $item->getProduct(), 'the construct should set the product, if its passed in');
+ }
+
public function testOptionMethods()
{
$item = new Item();
@@ -33,7 +45,7 @@ public function testOptionMethods()
$rmClearOptions->setAccessible(true);
$rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate(false)));
- $this->setExpectedException('Vespolina\Entity\Exception\InvalidOptionsException');
+ $this->setExpectedException('Vespolina\Exception\InvalidOptionsException');
$rmClearOptions->invoke($item);
$this->assertSame($options, $item->getOptions(), 'nothing should have been removed if the validation fails');
@@ -42,7 +54,7 @@ public function testOptionMethods()
$this->assertEmpty($item->getOptions());
$rmSetProduct->invokeArgs($item, array($this->createProductOptionValidate(false)));
- $this->setExpectedException('Vespolina\Entity\Exception\InvalidOptionsException');
+ $this->setExpectedException('Vespolina\Exception\InvalidOptionsException');
$rmSetOptions->invokeArgs($item, array('failure' => 0));
$this->assertEmpty($item->getOptions(), 'nothing should be added if the validation fails');
}

0 comments on commit c414c06

Please sign in to comment.