Пример #1
0
 /**
  * @param array $data
  * @return ItemModel
  */
 public function getItemModel($data)
 {
     if (empty($data) || !is_array($data)) {
         throw new \InvalidArgumentException("Item to add is either empty or not an array");
     }
     $itemValidator = new ItemValidator();
     $itemValidator->setData($data);
     $itemValidator->validate();
     $item = $this->generateModel($data);
     return $item;
 }
Пример #2
0
 public function testItemAddedIsValid()
 {
     $data = ['name' => 'Balloon', 'amount' => 10.99, 'quantity' => 2, 'uniqueId' => '1', 'currency' => 'GBP'];
     $this->validator->setData($data);
     $validate = $this->validator->validate();
     $this->assertTrue($validate);
     // Now let's check without the currency (optional field)
     $data = ['name' => 'Balloon', 'amount' => 12.95, 'quantity' => 2, 'uniqueId' => '1'];
     $this->validator->setData($data);
     $validate = $this->validator->validate();
     $this->assertTrue($validate);
 }