22
33namespace Illuminated \Testing \Asserts ;
44
5+ use Illuminate \Database \Eloquent \Factories \Factory ;
56use Illuminate \Database \Eloquent \Relations \BelongsTo ;
67use Illuminate \Database \Eloquent \Relations \HasMany ;
78use Illuminate \Support \Str ;
@@ -186,8 +187,10 @@ protected function assertEloquentHasMany(string $class, string $relation)
186187 $ childKey = $ childModel ->getKeyName ();
187188 $ childForeignKey = $ hasManyRelation ->getForeignKeyName ();
188189
189- $ parent = factory ($ class )->create ();
190- $ children = factory (get_class ($ childModel ), 3 )->create ([$ childForeignKey => $ parent ->{$ parentKey }]);
190+ $ parent = Factory::factoryForModel ($ class )->create ();
191+ $ children = Factory::factoryForModel (get_class ($ childModel ))
192+ ->count (3 )
193+ ->create ([$ childForeignKey => $ parent ->{$ parentKey }]);
191194
192195 $ this ->assertCollectionsEqual ($ children , $ parent ->{$ relation }, $ childKey );
193196 }
@@ -212,9 +215,9 @@ protected function assertEloquentHasCreateFor(string $class, string $relation, s
212215 $ this ->assertMethodExists ($ class , $ createMethod );
213216
214217 /** @var \Illuminate\Database\Eloquent\Model $child */
215- $ parent = factory ($ class )->create ();
218+ $ parent = Factory:: factoryForModel ($ class )->create ();
216219 $ child = $ parent ->{$ createMethod }(
217- factory (get_class ($ hasManyRelation ->getRelated ()))
220+ Factory:: factoryForModel (get_class ($ hasManyRelation ->getRelated ()))
218221 ->make ()
219222 ->toArray ()
220223 );
@@ -244,9 +247,10 @@ protected function assertEloquentHasCreateManyFor(string $class, string $relatio
244247 $ childModel = $ hasManyRelation ->getRelated ();
245248 $ childKey = $ childModel ->getKeyName ();
246249
247- $ parent = factory ($ class )->create ();
250+ $ parent = Factory:: factoryForModel ($ class )->create ();
248251 $ children = $ parent ->{$ createManyMethod }(
249- factory (get_class ($ childModel ), 3 )
252+ Factory::factoryForModel (get_class ($ childModel ))
253+ ->count (3 )
250254 ->make ()
251255 ->toArray ()
252256 );
@@ -273,8 +277,8 @@ protected function assertEloquentBelongsTo(string $class, string $relation)
273277 $ parentKey = $ parentModel ->getKeyName ();
274278 $ childForeignKey = $ belongsToRelation ->getForeignKeyName ();
275279
276- $ parent = factory (get_class ($ parentModel ))->create ();
277- $ child = factory ($ class )->create ([$ childForeignKey => $ parent ->{$ parentKey }]);
280+ $ parent = Factory:: factoryForModel (get_class ($ parentModel ))->create ();
281+ $ child = Factory:: factoryForModel ($ class )->create ([$ childForeignKey => $ parent ->{$ parentKey }]);
278282
279283 $ this ->assertEquals ($ parent ->fresh ()->toArray (), $ child ->{$ relation }->toArray ());
280284 }
0 commit comments