forked from larastan/larastan
/
ModelFactory.php
125 lines (101 loc) · 3.01 KB
/
ModelFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
declare(strict_types=1);
namespace Tests\Features\ReturnTypes;
use App\Post;
use App\User;
use Database\Factories\PostFactory;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Collection;
class ModelFactory
{
public function testFactoryWithParentModelUsingFactory(): UserFactory
{
return User::factory();
}
public function testNewWithParentModelUsingFactory(): UserFactory
{
return User::factory()->new();
}
public function testCreateOneWithParentModelUsingFactory(): User
{
return User::factory()->createOne();
}
/** @phpstan-return Collection<int, User> */
public function testCreateManyWithParentModelUsingFactory(): Collection
{
return User::factory()->createMany([]);
}
/** @phpstan-return Collection<int, User>|User */
public function testCreateWithParentModelUsingFactory()
{
return User::factory()->create();
}
public function testMakeOneWithParentModelUsingFactory(): User
{
return User::factory()->makeOne();
}
/** @phpstan-return Collection<int, User>|User */
public function testMakeWithParentModelUsingFactory()
{
return User::factory()->make();
}
public function testStateWithParentModelUsingFactory(): UserFactory
{
return User::factory()->unverified();
}
public function testAfterMakingWithParentModelUsingFactory(): UserFactory
{
return User::factory()->afterMaking(fn (User $user) => $user);
}
public function testAfterCreatingWithParentModelUsingFactory(): UserFactory
{
return User::factory()->afterCreating(fn (User $user) => $user);
}
public function testFactoryWithModelInNestedNamespace(): \Database\Factories\Domain\Foo\UserFactory
{
return \App\Domain\Foo\User::factory();
}
public function testFactory(): PostFactory
{
return Post::factory();
}
public function testNew(): PostFactory
{
return Post::factory()->new();
}
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
{
return Post::factory()->createMany([]);
}
/** @phpstan-return Collection<int, Post>|Post */
public function testCreate()
{
return Post::factory()->create();
}
public function testMakeOne(): Post
{
return Post::factory()->makeOne();
}
/** @phpstan-return Collection<int, Post>|Post */
public function testMake()
{
return Post::factory()->make();
}
public function testAfterMaking(): PostFactory
{
return Post::factory()->afterMaking(fn (Post $post) => $post);
}
public function testAfterCreating(): PostFactory
{
return Post::factory()->afterCreating(fn (Post $post) => $post);
}
}