Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
 /**
  * Test getting quantity.
  */
 public function testGetQty()
 {
     $this->assertEquals($this->pl->getQty(), 3);
 }