Skip to content

Commit

Permalink
feat: add createOneQuietly stub (#1462)
Browse files Browse the repository at this point in the history
  • Loading branch information
amooij committed Dec 1, 2022
1 parent 0c9c70f commit 00ab8c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 8 additions & 0 deletions stubs/Factory.stub
Expand Up @@ -30,6 +30,14 @@ class Factory
*/
public function createOne($attributes = []) {}

/**
* Create a single model and persist it to the database.
*
* @param array<model-property<TModel>, mixed> $attributes
* @return TModel
*/
public function createOneQuietly($attributes = []) {}

/**
* Create a collection of models and persist them to the database.
*
Expand Down
5 changes: 5 additions & 0 deletions tests/Features/ReturnTypes/ModelFactory.php
Expand Up @@ -85,6 +85,11 @@ public function testCreateOne(): Post
return Post::factory()->createOne();
}

public function testCreateOneQuietly(): Post
{
return Post::factory()->createOneQuietly();
}

/** @phpstan-return Collection<int, Post> */
public function testCreateMany(): Collection
{
Expand Down
9 changes: 5 additions & 4 deletions tests/Type/data/model-factories.php
Expand Up @@ -8,6 +8,7 @@
assertType('Database\Factories\UserFactory', User::factory());
assertType('Database\Factories\UserFactory', User::factory()->new());
assertType('App\User', User::factory()->createOne());
assertType('App\User', User::factory()->createOneQuietly());
assertType('Illuminate\Database\Eloquent\Collection<int, App\User>', User::factory()->createMany([]));
assertType('App\User', User::factory()->makeOne());

Expand All @@ -22,21 +23,21 @@
assertType('Illuminate\Database\Eloquent\Collection<int, App\User>', User::factory(2)->create());
assertType('Illuminate\Database\Eloquent\Collection<int, App\User>', User::factory(2)->createQuietly());
assertType('Illuminate\Database\Eloquent\Collection<int, App\User>', User::factory(2)->make());
assertType('App\User', User::factory(2)->createOneQuietly());

assertType('Illuminate\Database\Eloquent\Collection<int, App\User>', User::factory()->count(1)->create());
assertType('Illuminate\Database\Eloquent\Collection<int, App\User>', User::factory()->count(1)->createQuietly());
assertType('Illuminate\Database\Eloquent\Collection<int, App\User>', User::factory()->count(1)->make());
assertType('App\User', User::factory()->count(2)->createOneQuietly());

assertType('App\User', User::factory(2)->count(null)->create());
assertType('App\User', User::factory(2)->count(null)->createQuietly());
assertType('App\User', User::factory(2)->count(null)->make());

assertType('App\User', User::factory(2)->count(null)->create());
assertType('App\User', User::factory(2)->count(null)->createQuietly());
assertType('App\User', User::factory(2)->count(null)->createOneQuietly());
assertType('App\User', User::factory(2)->count(null)->make());

assertType('App\User', User::factory(2)->state(['foo'])->count(null)->create());
assertType('App\User', User::factory(2)->state(['foo'])->count(null)->createQuietly());
assertType('App\User', User::factory(2)->state(['foo'])->count(null)->createOneQuietly());
assertType('App\User', User::factory(2)->state(['foo'])->count(null)->make());

function foo(?int $foo): void
Expand Down

0 comments on commit 00ab8c5

Please sign in to comment.