Skip to content

Commit 8e202b4

Browse files
authored
fix: TypeError FactoryCollection::create() when calling many with 0 (#925)
1 parent 1e94ca1 commit 8e202b4

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/FactoryCollection.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ public function create(array|callable $attributes = []): array
150150
$lastFactory = \array_pop($factories);
151151
// @phpstan-ignore method.notFound (phpstan does not understand that we only have persistent factories here)
152152
$factories = \array_map(static fn(Factory $f) => $f->notRootFactory(), $factories);
153-
$factories[] = $lastFactory;
153+
154+
if ($lastFactory !== null) {
155+
$factories[] = $lastFactory;
156+
}
154157
}
155158

156159
return \array_map(static fn(Factory $f) => $f->create($attributes), $factories);

tests/Integration/ORM/EntityRelationship/EntityFactoryRelationshipTestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,19 @@ static function() {
751751
static::categoryFactory()::assert()->count(2);
752752
}
753753

754+
/** @test */
755+
#[Test]
756+
#[DataProvider('provideCascadeRelationshipsCombinations')]
757+
#[UsingRelationships(Contact::class, ['category'])]
758+
public function call_many_with_zero_do_nothing(): void
759+
{
760+
static::contactFactory()
761+
->many(0)
762+
->create();
763+
764+
static::contactFactory()::assert()->count(0);
765+
}
766+
754767
/** @return PersistentObjectFactory<Contact> */
755768
protected static function contactFactoryWithoutCategory(): PersistentObjectFactory
756769
{

0 commit comments

Comments
 (0)