/** * Test decrease from 10 by 20. */ public function testDecreaseUnderZero() { $item = new InventoryItem(); $item->setQuantity(10); $form = $this->createForm($item); $form->submit(['modifyOperator' => InventoryItem::MODIFY_OPERATOR_DECREASE, 'modifyAmount' => 20]); $this->assertFalse($form->isValid()); }
/** * create new products and inventory items * @param array $data * @return Product $product */ private function createProduct(array $data) { $product = new Product(); $product->setSku($data['sku']); $product->setPrice($data['price']); $product->setName($data['name']); $inventoryItem = new InventoryItem(); $inventoryItem->setProduct($product); $inventoryItem->setWarehouse($this->defaultWarehouse); $inventoryItem->setQuantity($data['stock_level']); $product->getInventoryItems()->add($inventoryItem); $status = $this->getReference('product_status_' . $data['status']); $product->setStatus($status); $channels = explode(';', $data['channel']); foreach ($channels as $channelId) { $channel = $this->getReference('marello_sales_channel_' . (int) $channelId); $product->addChannel($channel); } $this->manager->persist($product); return $product; }