Skip to content

Commit

Permalink
Merge pull request #40 from jon-acker/product-fixture-use-default-sto…
Browse files Browse the repository at this point in the history
…ck-quantity

Don't add stock_data attribute if is_in_stock was not specified
  • Loading branch information
debo committed Mar 20, 2014
2 parents f400055 + 04685bd commit d2cf871
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/MageTest/MagentoExtension/Context/MagentoContext.php
Expand Up @@ -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);
Expand Down

0 comments on commit d2cf871

Please sign in to comment.