-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from shaffe-fr/feat/immutable
Make factories immutable by default
- Loading branch information
Showing
4 changed files
with
130 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace ExampleAppTests\Factories; | ||
|
||
use App\Models\Recipe; | ||
use Christophrumpel\LaravelFactoriesReloaded\BaseFactory; | ||
use Faker\Generator; | ||
|
||
class RecipeFactoryImmutable extends BaseFactory | ||
{ | ||
protected string $modelClass = Recipe::class; | ||
|
||
protected bool $immutable = true; | ||
|
||
public function create(array $extra = []): Recipe | ||
{ | ||
return $this->build($extra); | ||
} | ||
|
||
public function make(array $extra = []): Recipe | ||
{ | ||
return $this->build($extra, 'make'); | ||
} | ||
|
||
public function getDefaults(Generator $faker): array | ||
{ | ||
return [ | ||
'name' => 'Lasagne', | ||
'description' => 'Our family lasagne recipe.', | ||
]; | ||
} | ||
|
||
public function pasta(): self | ||
{ | ||
return $this->overwriteDefaults([ | ||
'name' => 'Pasta', | ||
]); | ||
} | ||
|
||
public function pizza(): self | ||
{ | ||
return $this->overwriteDefaults([ | ||
'name' => 'Pizza', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters