Skip to content

Commit

Permalink
[8.x] Fix model factories (#32865)
Browse files Browse the repository at this point in the history
* Fix docblocks

* parameter of count is nullable

* Fix dockblock

* Fix docblock
  • Loading branch information
bastien-phi authored May 18, 2020
1 parent b3453e8 commit 0f9d607
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BelongsToManyRelationship
* Create a new attached relationship definition.
*
* @param \Illuminate\Database\Eloquent\Factories\Factory $factory
* @param callable\array $pivot
* @param callable|array $pivot
* @param string $relationship
* @return void
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Eloquent/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function __construct($count = null,
/**
* Define the model's default state.
*
* @return static
* @return array
*/
abstract public function definition();

Expand Down Expand Up @@ -488,10 +488,10 @@ protected function callAfterCreating(Collection $instances, ?Model $parent = nul
/**
* Specify how many models should be generated.
*
* @param int $count
* @param int|null $count
* @return static
*/
public function count(int $count)
public function count(?int $count)
{
return $this->newInstance(['count' => $count]);
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Database/DatabaseEloquentFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public function test_basic_model_can_be_created()
$user = FactoryTestUserFactory::new()->create();
$this->assertInstanceOf(Eloquent::class, $user);

$user = FactoryTestUserFactory::new()->createOne();
$this->assertInstanceOf(Eloquent::class, $user);

$user = FactoryTestUserFactory::new()->create(['name' => 'Taylor Otwell']);
$this->assertInstanceOf(Eloquent::class, $user);
$this->assertEquals('Taylor Otwell', $user->name);
Expand All @@ -96,6 +99,9 @@ public function test_basic_model_can_be_created()

public function test_make_creates_unpersisted_model_instance()
{
$user = FactoryTestUserFactory::new()->makeOne();
$this->assertInstanceOf(Eloquent::class, $user);

$user = FactoryTestUserFactory::new()->make(['name' => 'Taylor Otwell']);

$this->assertInstanceOf(Eloquent::class, $user);
Expand Down

0 comments on commit 0f9d607

Please sign in to comment.