From 04685bdaef3871afde9a95bdae4516029dac5670 Mon Sep 17 00:00:00 2001 From: Jon Acker Date: Fri, 14 Mar 2014 14:17:55 +0000 Subject: [PATCH] Don't add stock_data attribute if is_in_stock was not specified --- .../MagentoExtension/Context/MagentoContext.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/MageTest/MagentoExtension/Context/MagentoContext.php b/src/MageTest/MagentoExtension/Context/MagentoContext.php index 0bb8ede..99b9794 100644 --- a/src/MageTest/MagentoExtension/Context/MagentoContext.php +++ b/src/MageTest/MagentoExtension/Context/MagentoContext.php @@ -167,12 +167,18 @@ public function theProductsExist(TableNode $table) $hash = $table->getHash(); $fixtureGenerator = $this->factory->create('product'); foreach ($hash as $row) { - $row['stock_data'] = array(); if (isset($row['is_in_stock'])) { - $row['stock_data']['is_in_stock'] = $row['is_in_stock']; - } - if (isset($row['is_in_stock'])) { - $row['stock_data']['qty'] = $row['qty']; + if (!isset($row['qty'])) { + throw new \InvalidArgumentException('You have specified is_in_stock but not qty, please add value for qty.'); + }; + + $row['stock_data'] = array( + 'is_in_stock' => $row['is_in_stock'], + 'qty' => $row['qty'] + ); + + unset($row['is_in_stock']); + unset($row['qty']); } $fixtureGenerator->create($row);