File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66use App \Models \TimeInterval ;
77use App \Models \User ;
88use Carbon \Carbon ;
9- use Faker \Factory as FakerFactory ;
109use Tests \Facades \TaskFactory ;
1110use Tests \Facades \UserFactory ;
1211
@@ -26,7 +25,7 @@ public function createRandomModelDataWithRelation(): array
2625
2726 public function createRandomModelData (): array
2827 {
29- $ randomDateTime = FakerFactory:: create ()->unique ()->dateTimeThisYear ();
28+ $ randomDateTime = fake ()->unique ()->dateTimeThisYear ();
3029 $ randomDateTime = Carbon::instance ($ randomDateTime );
3130
3231 return [
Original file line number Diff line number Diff line change 33namespace Tests \Factories ;
44
55use App \Models \Invitation ;
6- use Faker \Factory as FakerFactory ;
76use Illuminate \Database \Eloquent \Model ;
87
98class InvitationFactory extends Factory
@@ -17,7 +16,7 @@ protected function getModelInstance(): Model
1716
1817 public function createRequestData (): array
1918 {
20- $ faker = FakerFactory:: create ();
19+ $ faker = fake ();
2120
2221 return [
2322 'users ' => [
@@ -31,7 +30,7 @@ public function createRequestData(): array
3130
3231 public function createRandomModelData (): array
3332 {
34- $ faker = FakerFactory:: create ();
33+ $ faker = fake ();
3534
3635 return [
3736 'email ' => $ faker ->unique ()->email ,
Original file line number Diff line number Diff line change 44
55use App \Models \Project ;
66use App \Enums \ScreenshotsState ;
7- use Faker \Factory as FakerFactory ;
87use Tests \Facades \TaskFactory ;
98
109class ProjectFactory extends Factory
@@ -62,7 +61,7 @@ public function forUsers(array $users): self
6261
6362 public function createRandomModelData (): array
6463 {
65- $ faker = FakerFactory:: create ();
64+ $ faker = fake ();
6665
6766 return [
6867 'company_id ' => self ::COMPANY_ID ,
Original file line number Diff line number Diff line change 77use App \Models \Status ;
88use App \Models \Task ;
99use App \Models \User ;
10- use Faker \Factory as FakerFactory ;
1110use Illuminate \Database \Eloquent \Model ;
1211use Tests \Facades \IntervalFactory ;
1312use Tests \Facades \ProjectFactory ;
@@ -77,7 +76,7 @@ public function create(array $attributes = []): Task
7776
7877 public function createRandomModelData (): array
7978 {
80- $ faker = FakerFactory:: create ();
79+ $ faker = fake ();
8180
8281 return [
8382 'task_name ' => $ faker ->jobTitle ,
Original file line number Diff line number Diff line change 55use App \Enums \ScreenshotsState ;
66use App \Models \User ;
77use Carbon \Carbon ;
8- use Faker \Factory as FakerFactory ;
98use Illuminate \Database \Eloquent \Model ;
109
1110class UserFactory extends Factory
@@ -52,7 +51,7 @@ public function create(): User
5251
5352 public function createRandomModelData (): array
5453 {
55- $ faker = FakerFactory:: create ();
54+ $ faker = fake ();
5655
5756 $ fullName = $ faker ->name ;
5857
@@ -80,7 +79,7 @@ public function createRandomModelData(): array
8079
8180 public function createRandomRegistrationModelData (): array
8281 {
83- $ faker = FakerFactory:: create ();
82+ $ faker = fake ();
8483
8584 return [
8685 'full_name ' => $ faker ->name ,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Feature \Factories ;
4+
5+ use Tests \Facades \InvitationFactory ;
6+ use Tests \Facades \UserFactory ;
7+ use Tests \TestCase ;
8+
9+ /**
10+ * The test factories in tests/Factories used to create a new Faker generator on every call, so
11+ * `unique()` only applied within one call and users created in the same test could get the same
12+ * e-mail (an intermittent unique-key violation, e.g. in ProjectMembers\ShowTest). They now share
13+ * the application's generator, which is reset together with the application for every test.
14+ */
15+ class TestFactoryUniquenessTest extends TestCase
16+ {
17+ // Large enough that independent generators almost surely repeat a safeEmail, small enough to stay fast.
18+ private const SAMPLES = 1000 ;
19+
20+ public function test_user_emails_are_unique_across_factory_calls (): void
21+ {
22+ $ emails = [];
23+ for ($ i = 0 ; $ i < self ::SAMPLES ; $ i ++) {
24+ $ emails [] = UserFactory::createRandomModelData ()['email ' ];
25+ $ emails [] = UserFactory::createRandomRegistrationModelData ()['email ' ];
26+ }
27+
28+ $ this ->assertSameSize ($ emails , array_unique ($ emails ));
29+ }
30+
31+ public function test_invitation_emails_are_unique_across_factory_calls (): void
32+ {
33+ $ emails = [];
34+ for ($ i = 0 ; $ i < self ::SAMPLES ; $ i ++) {
35+ $ emails [] = InvitationFactory::createRandomModelData ()['email ' ];
36+ }
37+
38+ $ this ->assertSameSize ($ emails , array_unique ($ emails ));
39+ }
40+ }
Original file line number Diff line number Diff line change 66use Illuminate \Foundation \Testing \WithFaker ;
77use Tests \Facades \UserFactory ;
88use Tests \TestCase ;
9- use Faker \Factory as FakerFactory ;
109
1110class EditTest extends TestCase
1211{
@@ -80,7 +79,7 @@ public function test_edit_as_user(): void
8079
8180 public function test_edit_as_your_own_user (): void
8281 {
83- $ faker = FakerFactory:: create ();
82+ $ faker = fake ();
8483 $ user = clone $ this ->user ;
8584
8685 $ user ->full_name = $ faker ->unique ()->firstName ;
You can’t perform that action at this time.
0 commit comments