2
2
3
3
namespace Illuminated \Testing \Asserts ;
4
4
5
+ use Illuminate \Database \Eloquent \Factories \Factory ;
5
6
use Illuminate \Database \Eloquent \Relations \BelongsTo ;
6
7
use Illuminate \Database \Eloquent \Relations \HasMany ;
7
8
use Illuminate \Support \Str ;
@@ -186,8 +187,10 @@ protected function assertEloquentHasMany(string $class, string $relation)
186
187
$ childKey = $ childModel ->getKeyName ();
187
188
$ childForeignKey = $ hasManyRelation ->getForeignKeyName ();
188
189
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 }]);
191
194
192
195
$ this ->assertCollectionsEqual ($ children , $ parent ->{$ relation }, $ childKey );
193
196
}
@@ -212,9 +215,9 @@ protected function assertEloquentHasCreateFor(string $class, string $relation, s
212
215
$ this ->assertMethodExists ($ class , $ createMethod );
213
216
214
217
/** @var \Illuminate\Database\Eloquent\Model $child */
215
- $ parent = factory ($ class )->create ();
218
+ $ parent = Factory:: factoryForModel ($ class )->create ();
216
219
$ child = $ parent ->{$ createMethod }(
217
- factory (get_class ($ hasManyRelation ->getRelated ()))
220
+ Factory:: factoryForModel (get_class ($ hasManyRelation ->getRelated ()))
218
221
->make ()
219
222
->toArray ()
220
223
);
@@ -244,9 +247,10 @@ protected function assertEloquentHasCreateManyFor(string $class, string $relatio
244
247
$ childModel = $ hasManyRelation ->getRelated ();
245
248
$ childKey = $ childModel ->getKeyName ();
246
249
247
- $ parent = factory ($ class )->create ();
250
+ $ parent = Factory:: factoryForModel ($ class )->create ();
248
251
$ children = $ parent ->{$ createManyMethod }(
249
- factory (get_class ($ childModel ), 3 )
252
+ Factory::factoryForModel (get_class ($ childModel ))
253
+ ->count (3 )
250
254
->make ()
251
255
->toArray ()
252
256
);
@@ -273,8 +277,8 @@ protected function assertEloquentBelongsTo(string $class, string $relation)
273
277
$ parentKey = $ parentModel ->getKeyName ();
274
278
$ childForeignKey = $ belongsToRelation ->getForeignKeyName ();
275
279
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 }]);
278
282
279
283
$ this ->assertEquals ($ parent ->fresh ()->toArray (), $ child ->{$ relation }->toArray ());
280
284
}
0 commit comments