Exemplo n.º 1
0
 /**
  * Create the ProductList.
  * Add some products.
  */
 protected function setUp()
 {
     $this->pl = new ProductList();
     $this->pl->addProduct(new Product("First", "First Product", 2.5, 1000));
     $this->pl->addProduct(new Product("Second", "Second Product", 0.5, 2000));
     $this->pl->addProduct(new Product("Third", "Third Product", 10.0, 3550));
 }
Exemplo n.º 2
0
 /**
  * Create a ProductList from input data retrieved from a Gateway.
  *
  * @param array $input
  *
  * @throws MalformedDataException If data is malformed.
  *
  * @return ProductList
  */
 public function createList(array $data)
 {
     $pl = new ProductList();
     array_walk($data, function ($product) use($pl) {
         if (false === array_key_exists('title', $product)) {
             throw new MalformedDataException("Product must have a title.");
         }
         if (false === array_key_exists('description', $product)) {
             throw new MalformedDataException("Product must have a description.");
         }
         if (false === array_key_exists('unit_price', $product)) {
             throw new MalformedDataException("Product must have a price.");
         }
         if (false === array_key_exists('size', $product)) {
             throw new MalformedDataException("Product must have a size.");
         }
         $product = $this->create($product['title'], $product['description'], $product['unit_price'], $product['size']);
         $pl->addProduct($product);
     });
     return $pl;
 }