Skip to content

Commit

Permalink
Avoiding issues when the fixture is empty
Browse files Browse the repository at this point in the history
This happens for cases where the user wants to drop/truncate the collection and not insert any data.
  • Loading branch information
jrbasso committed Feb 17, 2017
1 parent 4e99268 commit 0c37b11
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion examples/PizzaTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class PizzaTraitTest extends \PHPUnit_Framework_TestCase {
'orders' => [
['size' => 'large', 'toppings' => ['cheese', 'ham']],
['size' => 'medium', 'toppings' => ['cheese']]
]
],
'carts' => [
// Intentionally empty
],
];

/**
Expand Down
4 changes: 3 additions & 1 deletion src/DataSet/DataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0c37b11

Please sign in to comment.