diff --git a/src/factories/Element.php b/src/factories/Element.php index 16b66f4..90908a7 100644 --- a/src/factories/Element.php +++ b/src/factories/Element.php @@ -71,8 +71,8 @@ public function resolveFactories(array $values, FieldInterface $field) // will go in to the model okay, but when you try to pull them back out to save them // you get an EntryQuery with no access to the raw array of unsaved entries. // Because of that we call ->create() here on all nested factories. - $values[$index] = $field instanceof Matrix ? collection_wrap($value->make())->map(function (\craft\elements\Entry $entry) { - return [ + $values[$index] = $field instanceof Matrix ? collection_wrap($value->make())->map(function (\craft\elements\Entry|array $entry) { + return is_array($entry) ? $entry : [ 'type' => $entry->getType()->handle, 'enabled' => true, 'collapsed' => false, diff --git a/tests/FactoryMatrixTest.php b/tests/FactoryMatrixTest.php index a8c8875..ee146c7 100644 --- a/tests/FactoryMatrixTest.php +++ b/tests/FactoryMatrixTest.php @@ -20,6 +20,18 @@ expect($entry->matrixField->all())->toHaveCount(2); }); +it('can use old Block factories', function () { + $entry = EntryFactory::factory() + ->section('posts') + ->matrixField( + BlockFactory::factory()->type('blockTypeOne')->fieldOne('foo'), + BlockFactory::factory()->type('blockTypeOne')->fieldOne('bar'), + ) + ->create(); + + expect($entry->matrixField->all())->toHaveCount(2); +}); + it('can fill matrix fields with multiple blocks', function () { $entry = EntryFactory::factory() ->section('posts')