-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 #8671 from paulbalandan/fabricator-modifiers
feat: Support faker modifiers on Fabricator
- Loading branch information
Showing
7 changed files
with
188 additions
and
2 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
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
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,11 @@ | ||
<?php | ||
|
||
use App\Models\UserModel; | ||
use CodeIgniter\Test\Fabricator; | ||
|
||
$fabricator = new Fabricator(UserModel::class); | ||
$fabricator->setUnique('email'); // sets generated emails to be always unique | ||
$fabricator->setOptional('group_id'); // sets group id to be optional, with 50% chance to be `null` | ||
$fabricator->setValid('age', static fn (int $age): bool => $age >= 18); // sets age to be 18 and above only | ||
|
||
$users = $fabricator->make(10); |
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,20 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use CodeIgniter\Test\Fabricator; | ||
use Faker\Generator; | ||
|
||
class UserModel | ||
{ | ||
protected $table = 'users'; | ||
|
||
public function fake(Generator &$faker) | ||
{ | ||
return [ | ||
'first' => $faker->firstName(), | ||
'email' => $faker->unique()->email(), | ||
'group_id' => $faker->optional()->passthrough(mt_rand(1, Fabricator::getCount('groups'))), | ||
]; | ||
} | ||
} |