Skip to content

Commit 98feaf6

Browse files
committed
ITT: assertEloquentHasCreateRelationMethod minor refactorings.
1 parent 6a0810c commit 98feaf6

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Asserts/EloquentAsserts.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,19 @@ protected function assertEloquentHasCreateRelationMethod($class, $relation)
6868
{
6969
$this->assertMethodExists($class, $relation);
7070

71-
$parent = factory($class)->create();
72-
$hasManyRelation = $parent->{$relation}();
71+
$hasManyRelation = (new $class)->{$relation}();
7372
$this->assertInstanceOf(HasMany::class, $hasManyRelation);
7473

7574
$createMethod = 'create' . title_case(str_singular($relation));
7675
$this->assertMethodExists($class, $createMethod);
7776

78-
$childModel = $hasManyRelation->getRelated();
79-
$childAttributes = factory(get_class($childModel))->make()->toArray();
80-
$child = $parent->{$createMethod}($childAttributes);
77+
$parent = factory($class)->create();
78+
$child = $parent->{$createMethod}(
79+
factory(get_class($hasManyRelation->getRelated()))
80+
->make()
81+
->toArray()
82+
);
83+
8184
$this->assertEquals($child->fresh()->toArray(), $parent->{$relation}->first()->toArray());
8285
}
8386

0 commit comments

Comments
 (0)