From e22ec121427b4b1f3a6baa59129e577918639be3 Mon Sep 17 00:00:00 2001 From: Choraimy Kroonstuiver <3661474+axlon@users.noreply.github.com> Date: Thu, 10 Feb 2022 19:01:17 +0100 Subject: [PATCH] Add additional type checks for calling factories with a closure --- types/Database/Eloquent/Factories/Factory.php | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/types/Database/Eloquent/Factories/Factory.php b/types/Database/Eloquent/Factories/Factory.php index a994f318686e..816b03815390 100644 --- a/types/Database/Eloquent/Factories/Factory.php +++ b/types/Database/Eloquent/Factories/Factory.php @@ -28,8 +28,12 @@ public function definition() } } -$factory = UserFactory::new(); -assertType('UserFactory', $factory); +assertType('UserFactory', $factory = UserFactory::new()); +assertType('UserFactory', UserFactory::new(['string' => 'string'])); +assertType('UserFactory', UserFactory::new(function ($attributes) { +// assertType('array', $attributes); + return ['string' => 'string']; +})); assertType('array', $factory->definition()); @@ -39,16 +43,28 @@ public function definition() assertType('array', $factory->raw()); assertType('array', $factory->raw(['string' => 'string'])); +assertType('array', $factory->raw(function ($attributes) { +// assert('array', $attributes); + return ['string' => 'string']; +})); // assertType('User', $factory->createOne()); // assertType('User', $factory->createOne(['string' => 'string'])); assertType('Illuminate\Database\Eloquent\Model', $factory->createOne()); assertType('Illuminate\Database\Eloquent\Model', $factory->createOne(['string' => 'string'])); +assertType('Illuminate\Database\Eloquent\Model', $factory->createOne(function ($attributes) { +// assertType('array', $attributes); + return ['string' => 'string']; +})); // assertType('User', $factory->createOneQuietly()); // assertType('User', $factory->createOneQuietly(['string' => 'string'])); assertType('Illuminate\Database\Eloquent\Model', $factory->createOneQuietly()); assertType('Illuminate\Database\Eloquent\Model', $factory->createOneQuietly(['string' => 'string'])); +assertType('Illuminate\Database\Eloquent\Model', $factory->createOneQuietly(function ($attributes) { +// assertType('array', $attributes); + return ['string' => 'string']; +})); // assertType('Illuminate\Database\Eloquent\Collection', $factory->createMany([['string' => 'string']])); assertType('Illuminate\Database\Eloquent\Collection', $factory->createMany( @@ -68,6 +84,10 @@ public function definition() assertType('Illuminate\Database\Eloquent\Collection|Illuminate\Database\Eloquent\Model', $factory->create([ 'string' => 'string', ])); +assertType('Illuminate\Database\Eloquent\Collection|Illuminate\Database\Eloquent\Model', $factory->create(function ($attributes) { +// assertType('array', $attributes); + return ['string' => 'string']; +})); // assertType('Illuminate\Database\Eloquent\Collection|User', $factory->createQuietly()); // assertType('Illuminate\Database\Eloquent\Collection|User', $factory->createQuietly([ @@ -95,6 +115,10 @@ public function definition() assertType('Illuminate\Database\Eloquent\Model', $factory->makeOne([ 'string' => 'string', ])); +assertType('Illuminate\Database\Eloquent\Model', $factory->makeOne(function ($attributes) { +// assert('array', $attributes); + return ['string' => 'string']; +})); // assertType('Illuminate\Database\Eloquent\Collection|User', $factory->make()); // assertType('Illuminate\Database\Eloquent\Collection|User', $factory->make([ @@ -104,6 +128,10 @@ public function definition() assertType('Illuminate\Database\Eloquent\Collection|Illuminate\Database\Eloquent\Model', $factory->make([ 'string' => 'string', ])); +assertType('Illuminate\Database\Eloquent\Collection|Illuminate\Database\Eloquent\Model', $factory->make(function ($attributes) { +// assert('array', $attributes); + return ['string' => 'string']; +})); assertType('UserFactory', $factory->state(['string' => 'string'])); assertType('UserFactory', $factory->state(function () {