Skip to content

Commit 85da609

Browse files
committed
Add PHPUnit annotations, for future compatibility with PHPUnit 12
Annotations supported since PHPUnit 10 Docblock comments will be ignored in future In a later release of this package (probably `v7.0`), will remove PHPUnit 9 support and all associated doc-comments.
1 parent a6e35ee commit 85da609

33 files changed

+396
-30
lines changed

tests/BladeTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Spatie\Permission\Tests;
44

55
use Illuminate\Support\Facades\Artisan;
6+
use PHPUnit\Framework\Attributes\Test;
67
use Spatie\Permission\Contracts\Role;
78

89
class BladeTest extends TestCase
@@ -21,6 +22,7 @@ protected function setUp(): void
2122
}
2223

2324
/** @test */
25+
#[Test]
2426
public function all_blade_directives_will_evaluate_false_when_there_is_nobody_logged_in()
2527
{
2628
$permission = 'edit-articles';
@@ -40,6 +42,7 @@ public function all_blade_directives_will_evaluate_false_when_there_is_nobody_lo
4042
}
4143

4244
/** @test */
45+
#[Test]
4346
public function all_blade_directives_will_evaluate_false_when_somebody_without_roles_or_permissions_is_logged_in()
4447
{
4548
$permission = 'edit-articles';
@@ -59,6 +62,7 @@ public function all_blade_directives_will_evaluate_false_when_somebody_without_r
5962
}
6063

6164
/** @test */
65+
#[Test]
6266
public function all_blade_directives_will_evaluate_false_when_somebody_with_another_guard_is_logged_in()
6367
{
6468
$permission = 'edit-articles';
@@ -79,6 +83,7 @@ public function all_blade_directives_will_evaluate_false_when_somebody_with_anot
7983
}
8084

8185
/** @test */
86+
#[Test]
8287
public function the_can_directive_can_accept_a_guard_name()
8388
{
8489
$user = $this->getWriter();
@@ -109,6 +114,7 @@ public function the_can_directive_can_accept_a_guard_name()
109114
}
110115

111116
/** @test */
117+
#[Test]
112118
public function the_can_directive_will_evaluate_true_when_the_logged_in_user_has_the_permission()
113119
{
114120
$user = $this->getWriter();
@@ -121,6 +127,7 @@ public function the_can_directive_will_evaluate_true_when_the_logged_in_user_has
121127
}
122128

123129
/** @test */
130+
#[Test]
124131
public function the_haspermission_directive_will_evaluate_true_when_the_logged_in_user_has_the_permission()
125132
{
126133
$user = $this->getWriter();
@@ -145,6 +152,7 @@ public function the_haspermission_directive_will_evaluate_true_when_the_logged_i
145152
}
146153

147154
/** @test */
155+
#[Test]
148156
public function the_role_directive_will_evaluate_true_when_the_logged_in_user_has_the_role()
149157
{
150158
auth()->setUser($this->getWriter());
@@ -153,6 +161,7 @@ public function the_role_directive_will_evaluate_true_when_the_logged_in_user_ha
153161
}
154162

155163
/** @test */
164+
#[Test]
156165
public function the_elserole_directive_will_evaluate_true_when_the_logged_in_user_has_the_role()
157166
{
158167
auth()->setUser($this->getMember());
@@ -161,6 +170,7 @@ public function the_elserole_directive_will_evaluate_true_when_the_logged_in_use
161170
}
162171

163172
/** @test */
173+
#[Test]
164174
public function the_role_directive_will_evaluate_true_when_the_logged_in_user_has_the_role_for_the_given_guard()
165175
{
166176
auth('admin')->setUser($this->getSuperAdmin());
@@ -169,6 +179,7 @@ public function the_role_directive_will_evaluate_true_when_the_logged_in_user_ha
169179
}
170180

171181
/** @test */
182+
#[Test]
172183
public function the_hasrole_directive_will_evaluate_true_when_the_logged_in_user_has_the_role()
173184
{
174185
auth()->setUser($this->getWriter());
@@ -177,6 +188,7 @@ public function the_hasrole_directive_will_evaluate_true_when_the_logged_in_user
177188
}
178189

179190
/** @test */
191+
#[Test]
180192
public function the_hasrole_directive_will_evaluate_true_when_the_logged_in_user_has_the_role_for_the_given_guard()
181193
{
182194
auth('admin')->setUser($this->getSuperAdmin());
@@ -185,6 +197,7 @@ public function the_hasrole_directive_will_evaluate_true_when_the_logged_in_user
185197
}
186198

187199
/** @test */
200+
#[Test]
188201
public function the_unlessrole_directive_will_evaluate_true_when_the_logged_in_user_does_not_have_the_role()
189202
{
190203
auth()->setUser($this->getWriter());
@@ -193,6 +206,7 @@ public function the_unlessrole_directive_will_evaluate_true_when_the_logged_in_u
193206
}
194207

195208
/** @test */
209+
#[Test]
196210
public function the_unlessrole_directive_will_evaluate_true_when_the_logged_in_user_does_not_have_the_role_for_the_given_guard()
197211
{
198212
auth('admin')->setUser($this->getSuperAdmin());
@@ -202,6 +216,7 @@ public function the_unlessrole_directive_will_evaluate_true_when_the_logged_in_u
202216
}
203217

204218
/** @test */
219+
#[Test]
205220
public function the_hasanyrole_directive_will_evaluate_false_when_the_logged_in_user_does_not_have_any_of_the_required_roles()
206221
{
207222
$roles = ['writer', 'intern'];
@@ -213,6 +228,7 @@ public function the_hasanyrole_directive_will_evaluate_false_when_the_logged_in_
213228
}
214229

215230
/** @test */
231+
#[Test]
216232
public function the_hasanyrole_directive_will_evaluate_true_when_the_logged_in_user_does_have_some_of_the_required_roles()
217233
{
218234
$roles = ['member', 'writer', 'intern'];
@@ -224,6 +240,7 @@ public function the_hasanyrole_directive_will_evaluate_true_when_the_logged_in_u
224240
}
225241

226242
/** @test */
243+
#[Test]
227244
public function the_hasanyrole_directive_will_evaluate_true_when_the_logged_in_user_does_have_some_of_the_required_roles_for_the_given_guard()
228245
{
229246
$roles = ['super-admin', 'moderator'];
@@ -235,6 +252,7 @@ public function the_hasanyrole_directive_will_evaluate_true_when_the_logged_in_u
235252
}
236253

237254
/** @test */
255+
#[Test]
238256
public function the_hasanyrole_directive_will_evaluate_true_when_the_logged_in_user_does_have_some_of_the_required_roles_in_pipe()
239257
{
240258
$guard = 'admin';
@@ -245,6 +263,7 @@ public function the_hasanyrole_directive_will_evaluate_true_when_the_logged_in_u
245263
}
246264

247265
/** @test */
266+
#[Test]
248267
public function the_hasanyrole_directive_will_evaluate_false_when_the_logged_in_user_doesnt_have_some_of_the_required_roles_in_pipe()
249268
{
250269
$guard = '';
@@ -255,6 +274,7 @@ public function the_hasanyrole_directive_will_evaluate_false_when_the_logged_in_
255274
}
256275

257276
/** @test */
277+
#[Test]
258278
public function the_hasallroles_directive_will_evaluate_false_when_the_logged_in_user_does_not_have_all_required_roles()
259279
{
260280
$roles = ['member', 'writer'];
@@ -266,6 +286,7 @@ public function the_hasallroles_directive_will_evaluate_false_when_the_logged_in
266286
}
267287

268288
/** @test */
289+
#[Test]
269290
public function the_hasallroles_directive_will_evaluate_true_when_the_logged_in_user_does_have_all_required_roles()
270291
{
271292
$roles = ['member', 'writer'];
@@ -281,6 +302,7 @@ public function the_hasallroles_directive_will_evaluate_true_when_the_logged_in_
281302
}
282303

283304
/** @test */
305+
#[Test]
284306
public function the_hasallroles_directive_will_evaluate_true_when_the_logged_in_user_does_have_all_required_roles_for_the_given_guard()
285307
{
286308
$roles = ['super-admin', 'moderator'];
@@ -296,6 +318,7 @@ public function the_hasallroles_directive_will_evaluate_true_when_the_logged_in_
296318
}
297319

298320
/** @test */
321+
#[Test]
299322
public function the_hasallroles_directive_will_evaluate_true_when_the_logged_in_user_does_have_all_required_roles_in_pipe()
300323
{
301324
$guard = 'admin';
@@ -310,6 +333,7 @@ public function the_hasallroles_directive_will_evaluate_true_when_the_logged_in_
310333
}
311334

312335
/** @test */
336+
#[Test]
313337
public function the_hasallroles_directive_will_evaluate_false_when_the_logged_in_user_doesnt_have_all_required_roles_in_pipe()
314338
{
315339
$guard = '';
@@ -323,6 +347,7 @@ public function the_hasallroles_directive_will_evaluate_false_when_the_logged_in
323347
}
324348

325349
/** @test */
350+
#[Test]
326351
public function the_hasallroles_directive_will_evaluate_true_when_the_logged_in_user_does_have_all_required_roles_in_array()
327352
{
328353
$guard = 'admin';
@@ -337,6 +362,7 @@ public function the_hasallroles_directive_will_evaluate_true_when_the_logged_in_
337362
}
338363

339364
/** @test */
365+
#[Test]
340366
public function the_hasallroles_directive_will_evaluate_false_when_the_logged_in_user_doesnt_have_all_required_roles_in_array()
341367
{
342368
$guard = '';

tests/CacheTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Facades\Artisan;
66
use Illuminate\Support\Facades\DB;
7+
use PHPUnit\Framework\Attributes\Test;
78
use Spatie\Permission\Contracts\Permission;
89
use Spatie\Permission\Contracts\Role;
910
use Spatie\Permission\Exceptions\PermissionDoesNotExist;
@@ -42,6 +43,7 @@ protected function setUp(): void
4243
}
4344

4445
/** @test */
46+
#[Test]
4547
public function it_can_cache_the_permissions()
4648
{
4749
$this->resetQueryCount();
@@ -52,6 +54,7 @@ public function it_can_cache_the_permissions()
5254
}
5355

5456
/** @test */
57+
#[Test]
5558
public function it_flushes_the_cache_when_creating_a_permission()
5659
{
5760
app(Permission::class)->create(['name' => 'new']);
@@ -64,6 +67,7 @@ public function it_flushes_the_cache_when_creating_a_permission()
6467
}
6568

6669
/** @test */
70+
#[Test]
6771
public function it_flushes_the_cache_when_updating_a_permission()
6872
{
6973
$permission = app(Permission::class)->create(['name' => 'new']);
@@ -79,6 +83,7 @@ public function it_flushes_the_cache_when_updating_a_permission()
7983
}
8084

8185
/** @test */
86+
#[Test]
8287
public function it_flushes_the_cache_when_creating_a_role()
8388
{
8489
app(Role::class)->create(['name' => 'new']);
@@ -91,6 +96,7 @@ public function it_flushes_the_cache_when_creating_a_role()
9196
}
9297

9398
/** @test */
99+
#[Test]
94100
public function it_flushes_the_cache_when_updating_a_role()
95101
{
96102
$role = app(Role::class)->create(['name' => 'new']);
@@ -106,6 +112,7 @@ public function it_flushes_the_cache_when_updating_a_role()
106112
}
107113

108114
/** @test */
115+
#[Test]
109116
public function removing_a_permission_from_a_user_should_not_flush_the_cache()
110117
{
111118
$this->testUser->givePermissionTo('edit-articles');
@@ -122,6 +129,7 @@ public function removing_a_permission_from_a_user_should_not_flush_the_cache()
122129
}
123130

124131
/** @test */
132+
#[Test]
125133
public function removing_a_role_from_a_user_should_not_flush_the_cache()
126134
{
127135
$this->testUser->assignRole('testRole');
@@ -138,6 +146,7 @@ public function removing_a_role_from_a_user_should_not_flush_the_cache()
138146
}
139147

140148
/** @test */
149+
#[Test]
141150
public function it_flushes_the_cache_when_removing_a_role_from_a_permission()
142151
{
143152
$this->testUserPermission->assignRole('testRole');
@@ -154,6 +163,7 @@ public function it_flushes_the_cache_when_removing_a_role_from_a_permission()
154163
}
155164

156165
/** @test */
166+
#[Test]
157167
public function it_flushes_the_cache_when_assign_a_permission_to_a_role()
158168
{
159169
$this->testUserRole->givePermissionTo('edit-articles');
@@ -166,6 +176,7 @@ public function it_flushes_the_cache_when_assign_a_permission_to_a_role()
166176
}
167177

168178
/** @test */
179+
#[Test]
169180
public function user_creation_should_not_flush_the_cache()
170181
{
171182
$this->registrar->getPermissions();
@@ -181,6 +192,7 @@ public function user_creation_should_not_flush_the_cache()
181192
}
182193

183194
/** @test */
195+
#[Test]
184196
public function it_flushes_the_cache_when_giving_a_permission_to_a_role()
185197
{
186198
$this->testUserRole->givePermissionTo($this->testUserPermission);
@@ -193,6 +205,7 @@ public function it_flushes_the_cache_when_giving_a_permission_to_a_role()
193205
}
194206

195207
/** @test */
208+
#[Test]
196209
public function has_permission_to_should_use_the_cache()
197210
{
198211
$this->testUserRole->givePermissionTo(['edit-articles', 'edit-news', 'Edit News']);
@@ -217,6 +230,7 @@ public function has_permission_to_should_use_the_cache()
217230
}
218231

219232
/** @test */
233+
#[Test]
220234
public function the_cache_should_differentiate_by_guard_name()
221235
{
222236
$this->expectException(PermissionDoesNotExist::class);
@@ -235,6 +249,7 @@ public function the_cache_should_differentiate_by_guard_name()
235249
}
236250

237251
/** @test */
252+
#[Test]
238253
public function get_all_permissions_should_use_the_cache()
239254
{
240255
$this->testUserRole->givePermissionTo($expected = ['edit-articles', 'edit-news']);
@@ -253,6 +268,7 @@ public function get_all_permissions_should_use_the_cache()
253268
}
254269

255270
/** @test */
271+
#[Test]
256272
public function get_all_permissions_should_not_over_hydrate_roles()
257273
{
258274
$this->testUserRole->givePermissionTo(['edit-articles', 'edit-news']);
@@ -264,6 +280,7 @@ public function get_all_permissions_should_not_over_hydrate_roles()
264280
}
265281

266282
/** @test */
283+
#[Test]
267284
public function it_can_reset_the_cache_with_artisan_command()
268285
{
269286
Artisan::call('permission:create-permission', ['name' => 'new-permission']);

0 commit comments

Comments
 (0)