From 0c37b11b5d2419a4d3dbc0aa1162ffd17602e248 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Thu, 16 Feb 2017 19:32:54 -0500 Subject: [PATCH] Avoiding issues when the fixture is empty This happens for cases where the user wants to drop/truncate the collection and not insert any data. --- examples/PizzaTraitTest.php | 5 ++++- src/DataSet/DataSet.php | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/PizzaTraitTest.php b/examples/PizzaTraitTest.php index 9f217bd..a327f2c 100644 --- a/examples/PizzaTraitTest.php +++ b/examples/PizzaTraitTest.php @@ -32,7 +32,10 @@ class PizzaTraitTest extends \PHPUnit_Framework_TestCase { 'orders' => [ ['size' => 'large', 'toppings' => ['cheese', 'ham']], ['size' => 'medium', 'toppings' => ['cheese']] - ] + ], + 'carts' => [ + // Intentionally empty + ], ]; /** diff --git a/src/DataSet/DataSet.php b/src/DataSet/DataSet.php index 709ce0c..b7cd865 100644 --- a/src/DataSet/DataSet.php +++ b/src/DataSet/DataSet.php @@ -66,7 +66,9 @@ public function dropAllCollections() { */ public function buildCollections() { foreach ($this->fixture as $collection => $data) { - $this->connection->collection($collection)->insertMany($data); + if (!empty($data)) { + $this->connection->collection($collection)->insertMany($data); + } } return $this; }