|
2 | 2 |
|
3 | 3 | declare(strict_types=1); |
4 | 4 | use Carbon\CarbonImmutable; |
| 5 | +use Contexts\Authorization\Domain\Factories\RoleFactory; |
5 | 6 | use Contexts\Authorization\Domain\Role\Exceptions\RoleNotFoundException; |
6 | 7 | use Contexts\Authorization\Domain\Role\Models\Role; |
7 | 8 | use Contexts\Authorization\Domain\Role\Models\RoleId; |
8 | 9 | use Contexts\Authorization\Domain\Role\Models\RoleStatus; |
| 10 | +use Contexts\Authorization\Domain\Services\RoleLabelUniquenessService; |
9 | 11 | use Contexts\Authorization\Infrastructure\Persistence\RolePersistence; |
10 | 12 | use Contexts\Authorization\Infrastructure\Records\RoleRecord; |
11 | | -use Contexts\Authorization\Domain\Factories\RoleFactory; |
12 | | -use Contexts\Authorization\Domain\Services\RoleLabelUniquenessService; |
13 | 13 |
|
14 | 14 | beforeEach(function () { |
15 | 15 | $this->roleLabelUniquenessService = mock(RoleLabelUniquenessService::class); |
|
19 | 19 |
|
20 | 20 | it('can persist role data correctly', function () { |
21 | 21 | $role = $this->roleFactory->create(RoleId::null(), 'My Role'); |
22 | | - $rolePersistence = new RolePersistence(); |
| 22 | + $rolePersistence = new RolePersistence; |
23 | 23 |
|
24 | 24 | $rolePersistence->create($role); |
25 | 25 |
|
|
32 | 32 | it('can retrieve an role by ID', function () { |
33 | 33 | // Create a test role in the database |
34 | 34 | $createdRole = $this->roleFactory->create(RoleId::null(), 'Test Role'); |
35 | | - $rolePersistence = new RolePersistence(); |
| 35 | + $rolePersistence = new RolePersistence; |
36 | 36 | $savedRole = $rolePersistence->create($createdRole); |
37 | 37 |
|
38 | 38 | // Retrieve the role using getById |
|
46 | 46 |
|
47 | 47 | it('can retrieve multiple roles by IDs', function () { |
48 | 48 | // Create multiple test roles in the database |
49 | | - $rolePersistence = new RolePersistence(); |
| 49 | + $rolePersistence = new RolePersistence; |
50 | 50 |
|
51 | 51 | $role1 = $this->roleFactory->create(RoleId::null(), 'Role 1'); |
52 | 52 | $role2 = $this->roleFactory->create(RoleId::null(), 'Role 2'); |
|
71 | 71 | }); |
72 | 72 |
|
73 | 73 | it('throws an exception when retrieving a non-existent role', function () { |
74 | | - $rolePersistence = new RolePersistence(); |
| 74 | + $rolePersistence = new RolePersistence; |
75 | 75 |
|
76 | 76 | // Attempt to retrieve a non-existent role |
77 | 77 | $rolePersistence->getById(RoleId::fromInt(999)); |
|
80 | 80 | it('can update an role', function () { |
81 | 81 | // Create a test role in the database |
82 | 82 | $createdRole = $this->roleFactory->create(RoleId::null(), 'Original Label'); |
83 | | - $rolePersistence = new RolePersistence(); |
| 83 | + $rolePersistence = new RolePersistence; |
84 | 84 | $savedRole = $rolePersistence->create($createdRole); |
85 | 85 |
|
86 | 86 | // Create an updated version of the role |
|
105 | 105 | }); |
106 | 106 |
|
107 | 107 | it('throws an exception when updating a non-existent role', function () { |
108 | | - $rolePersistence = new RolePersistence(); |
| 108 | + $rolePersistence = new RolePersistence; |
109 | 109 |
|
110 | 110 | // Attempt to update a non-existent role |
111 | 111 | $rolePersistence->update($this->roleFactory->create(RoleId::fromInt(999), 'Updated Label')); |
112 | 112 | })->throws(RoleNotFoundException::class); |
113 | 113 |
|
114 | 114 | it('can paginate roles', function () { |
115 | 115 | // Create multiple test roles |
116 | | - $rolePersistence = new RolePersistence(); |
| 116 | + $rolePersistence = new RolePersistence; |
117 | 117 |
|
118 | 118 | // Create 5 roles |
119 | 119 | for ($i = 1; $i <= 5; $i++) { |
120 | 120 | $role = $this->roleFactory->create( |
121 | 121 | RoleId::null(), |
122 | 122 | "Role $i", |
123 | | - new CarbonImmutable() |
| 123 | + new CarbonImmutable |
124 | 124 | ); |
125 | 125 | $rolePersistence->create($role); |
126 | 126 | } |
|
146 | 146 | }); |
147 | 147 |
|
148 | 148 | it('can filter roles with search criteria', function () { |
149 | | - $rolePersistence = new RolePersistence(); |
| 149 | + $rolePersistence = new RolePersistence; |
150 | 150 |
|
151 | 151 | // Create roles with specific labels |
152 | 152 | $role1 = $this->roleFactory->create( |
153 | 153 | RoleId::null(), |
154 | 154 | 'Laravel Role', |
155 | | - new CarbonImmutable() |
| 155 | + new CarbonImmutable |
156 | 156 | ); |
157 | 157 | $rolePersistence->create($role1); |
158 | 158 |
|
159 | 159 | $role2 = $this->roleFactory->create( |
160 | 160 | RoleId::null(), |
161 | 161 | 'PHP Tutorial', |
162 | | - new CarbonImmutable() |
| 162 | + new CarbonImmutable |
163 | 163 | ); |
164 | 164 | $role2->subspend(); |
165 | 165 | $rolePersistence->create($role2); |
166 | 166 |
|
167 | 167 | $role3 = $this->roleFactory->create( |
168 | 168 | RoleId::null(), |
169 | 169 | 'Laravel Tips', |
170 | | - new CarbonImmutable() |
| 170 | + new CarbonImmutable |
171 | 171 | ); |
172 | 172 | $role3->subspend(); |
173 | 173 | $rolePersistence->create($role3); |
|
205 | 205 | it('can delete an role', function () { |
206 | 206 | // Create a test role in the database |
207 | 207 | $createdRole = $this->roleFactory->create(RoleId::null(), 'Test Role'); |
208 | | - $rolePersistence = new RolePersistence(); |
| 208 | + $rolePersistence = new RolePersistence; |
209 | 209 | $savedRole = $rolePersistence->create($createdRole); |
210 | 210 |
|
211 | 211 | // Delete the role |
|
218 | 218 | }); |
219 | 219 |
|
220 | 220 | it('throws an exception when deleting a non-existent role', function () { |
221 | | - $rolePersistence = new RolePersistence(); |
| 221 | + $rolePersistence = new RolePersistence; |
222 | 222 |
|
223 | 223 | // Attempt to delete a non-existent role |
224 | 224 | $rolePersistence->delete($this->roleFactory->create(RoleId::fromInt(999), 'Test Role')); |
225 | 225 | })->throws(RoleNotFoundException::class); |
226 | 226 |
|
227 | | - |
228 | 227 | it('returns true when role exists with given label', function () { |
229 | 228 | // Create a test role in the database with a specific label |
230 | 229 | $createdRole = $this->roleFactory->create(RoleId::null(), 'Unique Label'); |
231 | | - $rolePersistence = new RolePersistence(); |
| 230 | + $rolePersistence = new RolePersistence; |
232 | 231 | $rolePersistence->create($createdRole); |
233 | 232 |
|
234 | 233 | // Check if the method correctly detects the existing label |
|
238 | 237 | }); |
239 | 238 |
|
240 | 239 | it('returns false when role does not exist with given label', function () { |
241 | | - $rolePersistence = new RolePersistence(); |
| 240 | + $rolePersistence = new RolePersistence; |
242 | 241 |
|
243 | 242 | // Test with a label that doesn't exist in the database |
244 | 243 | $result = $rolePersistence->existsByLabel('Non-Existent Label'); |
|
248 | 247 |
|
249 | 248 | it('can retrieve roles by labels', function () { |
250 | 249 | // Create roles with specific labels |
251 | | - $rolePersistence = new RolePersistence(); |
| 250 | + $rolePersistence = new RolePersistence; |
252 | 251 |
|
253 | 252 | $role1 = $this->roleFactory->create(RoleId::null(), 'Admin Role'); |
254 | 253 | $role2 = $this->roleFactory->create(RoleId::null(), 'Editor Role'); |
|
270 | 269 | }); |
271 | 270 |
|
272 | 271 | it('returns empty collection when no roles match the given labels', function () { |
273 | | - $rolePersistence = new RolePersistence(); |
| 272 | + $rolePersistence = new RolePersistence; |
274 | 273 |
|
275 | 274 | // Retrieve with non-existent labels |
276 | 275 | $retrievedRoles = $rolePersistence->getByLabels(['Non-Existent Label']); |
|
0 commit comments