Skip to content

Commit 6a0810c

Browse files
committed
ITT: assertEloquentHasMany minor refactorings.
1 parent 7c7955e commit 6a0810c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Asserts/EloquentAsserts.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ protected function assertEloquentHasMany($class, $relation)
4747
{
4848
$this->assertMethodExists($class, $relation);
4949

50-
$parent = factory($class)->create();
51-
$hasManyRelation = $parent->{$relation}();
50+
$hasManyRelation = (new $class)->{$relation}();
5251
$this->assertInstanceOf(HasMany::class, $hasManyRelation);
5352

54-
$parentKey = $parent->getKeyName();
53+
$parentKey = $hasManyRelation->getParent()->getKeyName();
5554
$childModel = $hasManyRelation->getRelated();
5655
$childKey = $childModel->getKeyName();
5756

5857
/* @laravel-versions */
5958
$childForeignKey = method_exists($hasManyRelation, 'getForeignKeyName')
6059
? $hasManyRelation->getForeignKeyName() : last(explode('.', $hasManyRelation->getForeignKey()));
6160

61+
$parent = factory($class)->create();
6262
$children = factory(get_class($childModel), 3)->create([$childForeignKey => $parent->{$parentKey}]);
6363

6464
$this->assertCollectionsEqual($children, $parent->{$relation}, $childKey);

0 commit comments

Comments
 (0)