Skip to content

Commit ac56d09

Browse files
♻️ Use PHPUnit's attributes in place of annotations (#884) (#904)
1 parent e80e411 commit ac56d09

File tree

127 files changed

+1447
-1168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+1447
-1168
lines changed

contribution/generator/src/TestGenerator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ public function createTestsFor(
5353
$method = $this->builderFactory->method($methodName)
5454
->makePublic()
5555
->setReturnType('void')
56-
->setDocComment("/**\n * uuid: {$case->uuid}\n * @testdox {$description}\n */")
56+
->setDocComment("/** uuid: {$case->uuid} */")
57+
->addAttribute(new Node\Attribute(
58+
new Node\Name(\PHPUnit\Framework\Attributes\TestDox::class),
59+
[new Node\Arg(new Node\Scalar\String_($description))],
60+
))
5761
->addStmt(
5862
$this->builderFactory->funcCall(
5963
'$this->markTestIncomplete',

exercises/concept/annalyns-infiltration/AnnalynsInfiltrationTest.php

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<?php
22

3-
class AnnalynsInfiltrationTest extends PHPUnit\Framework\TestCase
3+
use PHPUnit\Framework\TestCase;
4+
use PHPUnit\Framework\Attributes\TestDox;
5+
6+
class AnnalynsInfiltrationTest extends TestCase
47
{
58
public static function setUpBeforeClass(): void
69
{
710
require_once 'AnnalynsInfiltration.php';
811
}
912

1013
/**
11-
* @testdox cannot fast attack when the knight is awake
1214
* @task_id 1
1315
*/
16+
#[TestDox('cannot fast attack when the knight is awake')]
1417
public function testCannotFastAttackWhenKnightIsAwake()
1518
{
1619
$infiltration = new AnnalynsInfiltration();
@@ -20,9 +23,9 @@ public function testCannotFastAttackWhenKnightIsAwake()
2023
}
2124

2225
/**
23-
* @testdox can fast attack when the knight is asleep
2426
* @task_id 1
2527
*/
28+
#[TestDox('can fast attack when the knight is asleep')]
2629
public function testCanFastAttackWhenKnightIsAsleep()
2730
{
2831
$infiltration = new AnnalynsInfiltration();
@@ -32,9 +35,9 @@ public function testCanFastAttackWhenKnightIsAsleep()
3235
}
3336

3437
/**
35-
* @testdox cannot spy when everyone is asleep
3638
* @task_id 2
3739
*/
40+
#[TestDox('cannot spy when everyone is asleep')]
3841
public function testCannotSpyWhenEveryoneAsleep()
3942
{
4043
$infiltration = new AnnalynsInfiltration();
@@ -48,9 +51,9 @@ public function testCannotSpyWhenEveryoneAsleep()
4851
}
4952

5053
/**
51-
* @testdox can spy when only the prisoner is awake
5254
* @task_id 2
5355
*/
56+
#[TestDox('can spy when only the prisoner is awake')]
5457
public function testCanSpyWhenOnlyPrisonerAwake()
5558
{
5659
$infiltration = new AnnalynsInfiltration();
@@ -64,9 +67,9 @@ public function testCanSpyWhenOnlyPrisonerAwake()
6467
}
6568

6669
/**
67-
* @testdox can spy when only the archer is awake
6870
* @task_id 2
6971
*/
72+
#[TestDox('can spy when only the archer is awake')]
7073
public function testCanSpyWhenOnlyArcherAwake()
7174
{
7275
$infiltration = new AnnalynsInfiltration();
@@ -80,9 +83,9 @@ public function testCanSpyWhenOnlyArcherAwake()
8083
}
8184

8285
/**
83-
* @testdox can spy when only the knight is awake
8486
* @task_id 2
8587
*/
88+
#[TestDox('can spy when only the knight is awake')]
8689
public function testCanSpyWhenOnlyKnightAwake()
8790
{
8891
$infiltration = new AnnalynsInfiltration();
@@ -96,9 +99,9 @@ public function testCanSpyWhenOnlyKnightAwake()
9699
}
97100

98101
/**
99-
* @testdox can spy when only the knight is asleep
100102
* @task_id 2
101103
*/
104+
#[TestDox('can spy when only the knight is asleep')]
102105
public function testCanSpyWhenOnlyKnightAsleep()
103106
{
104107
$infiltration = new AnnalynsInfiltration();
@@ -112,9 +115,9 @@ public function testCanSpyWhenOnlyKnightAsleep()
112115
}
113116

114117
/**
115-
* @testdox can spy when only the prisoner is asleep
116118
* @task_id 2
117119
*/
120+
#[TestDox('can spy when only the prisoner is asleep')]
118121
public function testCanSpyWhenOnlyPrisonerAsleep()
119122
{
120123
$infiltration = new AnnalynsInfiltration();
@@ -128,9 +131,9 @@ public function testCanSpyWhenOnlyPrisonerAsleep()
128131
}
129132

130133
/**
131-
* @testdox can spy when only the archer is asleep
132134
* @task_id 2
133135
*/
136+
#[TestDox('can spy when only the archer is asleep')]
134137
public function testCanSpyWhenOnlyArcherAsleep()
135138
{
136139
$infiltration = new AnnalynsInfiltration();
@@ -144,9 +147,9 @@ public function testCanSpyWhenOnlyArcherAsleep()
144147
}
145148

146149
/**
147-
* @testdox can spy when everyone is awake
148150
* @task_id 2
149151
*/
152+
#[TestDox('can spy when everyone is awake')]
150153
public function testCanSpyWhenEveryoneAwake()
151154
{
152155
$infiltration = new AnnalynsInfiltration();
@@ -160,9 +163,9 @@ public function testCanSpyWhenEveryoneAwake()
160163
}
161164

162165
/**
163-
* @testdox cannot signal the prisoner when everyone is asleep
164166
* @task_id 3
165167
*/
168+
#[TestDox('cannot signal the prisoner when everyone is asleep')]
166169
public function testCannotSignalWhenAllAsleep()
167170
{
168171
$infiltration = new AnnalynsInfiltration();
@@ -175,9 +178,9 @@ public function testCannotSignalWhenAllAsleep()
175178
}
176179

177180
/**
178-
* @testdox can signal the prisoner when archer is asleep
179181
* @task_id 3
180182
*/
183+
#[TestDox('can signal the prisoner when archer is asleep')]
181184
public function testCanSignalWhenArcherAsleep()
182185
{
183186
$infiltration = new AnnalynsInfiltration();
@@ -190,9 +193,9 @@ public function testCanSignalWhenArcherAsleep()
190193
}
191194

192195
/**
193-
* @testdox cannot signal the prisoner when prisoner is asleep
194196
* @task_id 3
195197
*/
198+
#[TestDox('cannot signal the prisoner when prisoner is asleep')]
196199
public function testCannotSignalWhenPrisonerAsleep()
197200
{
198201
$infiltration = new AnnalynsInfiltration();
@@ -205,9 +208,9 @@ public function testCannotSignalWhenPrisonerAsleep()
205208
}
206209

207210
/**
208-
* @testdox cannot signal the prisoner when no one is asleep
209211
* @task_id 3
210212
*/
213+
#[TestDox('cannot signal the prisoner when no one is asleep')]
211214
public function testCannotSignalWhenNoOneAsleep()
212215
{
213216
$infiltration = new AnnalynsInfiltration();
@@ -220,9 +223,9 @@ public function testCannotSignalWhenNoOneAsleep()
220223
}
221224

222225
/**
223-
* @testdox can liberate the prisoner when no one is awake but dog present
224226
* @task_id 4
225227
*/
228+
#[TestDox('can liberate the prisoner when no one is awake but dog present')]
226229
public function testCanLiberateWhenAllAsleepAndDogPresent()
227230
{
228231
$infiltration = new AnnalynsInfiltration();
@@ -237,9 +240,9 @@ public function testCanLiberateWhenAllAsleepAndDogPresent()
237240
}
238241

239242
/**
240-
* @testdox can liberate the prisoner when prisoner is awake with dog
241243
* @task_id 4
242244
*/
245+
#[TestDox('can liberate the prisoner when prisoner is awake with dog')]
243246
public function testCanLiberateWhenPrisonerAwakeWithDog()
244247
{
245248
$infiltration = new AnnalynsInfiltration();
@@ -254,9 +257,9 @@ public function testCanLiberateWhenPrisonerAwakeWithDog()
254257
}
255258

256259
/**
257-
* @testdox cannot liberate the prisoner when archer is awake with dog
258260
* @task_id 4
259261
*/
262+
#[TestDox('cannot liberate the prisoner when archer is awake with dog')]
260263
public function testCannotLiberateWhenArcherAwakeWithDog()
261264
{
262265
$infiltration = new AnnalynsInfiltration();
@@ -271,9 +274,9 @@ public function testCannotLiberateWhenArcherAwakeWithDog()
271274
}
272275

273276
/**
274-
* @testdox can liberate the prisoner when only knight awake with dog
275277
* @task_id 4
276278
*/
279+
#[TestDox('can liberate the prisoner when only knight awake with dog')]
277280
public function testCanLiberateWhenKnightAwakeWithDog()
278281
{
279282
$infiltration = new AnnalynsInfiltration();
@@ -288,9 +291,9 @@ public function testCanLiberateWhenKnightAwakeWithDog()
288291
}
289292

290293
/**
291-
* @testdox cannot liberate the prisoner when prisoner asleep with dog
292294
* @task_id 4
293295
*/
296+
#[TestDox('cannot liberate the prisoner when prisoner asleep with dog')]
294297
public function testCannotLiberateWhenPrisonerAsleepWithDog()
295298
{
296299
$infiltration = new AnnalynsInfiltration();
@@ -305,9 +308,9 @@ public function testCannotLiberateWhenPrisonerAsleepWithDog()
305308
}
306309

307310
/**
308-
* @testdox can liberate the prisoner when only archer asleep with dog
309311
* @task_id 4
310312
*/
313+
#[TestDox('can liberate the prisoner when only archer asleep with dog')]
311314
public function testCanLiberateWhenArcherAsleepWithDog()
312315
{
313316
$infiltration = new AnnalynsInfiltration();
@@ -322,9 +325,9 @@ public function testCanLiberateWhenArcherAsleepWithDog()
322325
}
323326

324327
/**
325-
* @testdox cannot liberate the prisoner when knight asleep with dog
326328
* @task_id 4
327329
*/
330+
#[TestDox('cannot liberate the prisoner when knight asleep with dog')]
328331
public function testCannotLiberateWhenKnightAsleepWithDog()
329332
{
330333
$infiltration = new AnnalynsInfiltration();
@@ -339,9 +342,9 @@ public function testCannotLiberateWhenKnightAsleepWithDog()
339342
}
340343

341344
/**
342-
* @testdox cannot liberate the prisoner when all awake with dog
343345
* @task_id 4
344346
*/
347+
#[TestDox('cannot liberate the prisoner when all awake with dog')]
345348
public function testCannotLiberateWhenAllAwakeWithDog()
346349
{
347350
$infiltration = new AnnalynsInfiltration();
@@ -356,9 +359,9 @@ public function testCannotLiberateWhenAllAwakeWithDog()
356359
}
357360

358361
/**
359-
* @testdox cannot liberate the prisoner when no one is awake and no dog present
360362
* @task_id 4
361363
*/
364+
#[TestDox('cannot liberate the prisoner when no one is awake and no dog present')]
362365
public function testCannotLiberateWhenAllAsleepAndNoDogPresent()
363366
{
364367
$infiltration = new AnnalynsInfiltration();
@@ -373,9 +376,9 @@ public function testCannotLiberateWhenAllAsleepAndNoDogPresent()
373376
}
374377

375378
/**
376-
* @testdox can liberate the prisoner when prisoner is awake without dog
377379
* @task_id 4
378380
*/
381+
#[TestDox('can liberate the prisoner when prisoner is awake without dog')]
379382
public function testCanLiberateWhenPrisonerAwakeWithoutDog()
380383
{
381384
$infiltration = new AnnalynsInfiltration();
@@ -390,9 +393,9 @@ public function testCanLiberateWhenPrisonerAwakeWithoutDog()
390393
}
391394

392395
/**
393-
* @testdox cannot liberate the prisoner when archer is awake without dog
394396
* @task_id 4
395397
*/
398+
#[TestDox('cannot liberate the prisoner when archer is awake without dog')]
396399
public function testCannotLiberateWhenArcherAwakeWithoutDog()
397400
{
398401
$infiltration = new AnnalynsInfiltration();
@@ -407,9 +410,9 @@ public function testCannotLiberateWhenArcherAwakeWithoutDog()
407410
}
408411

409412
/**
410-
* @testdox cannot liberate the prisoner when only knight awake without dog
411413
* @task_id 4
412414
*/
415+
#[TestDox('cannot liberate the prisoner when only knight awake without dog')]
413416
public function testCannotLiberateWhenKnightAwakeWithoutDog()
414417
{
415418
$infiltration = new AnnalynsInfiltration();
@@ -424,9 +427,9 @@ public function testCannotLiberateWhenKnightAwakeWithoutDog()
424427
}
425428

426429
/**
427-
* @testdox cannot liberate the prisoner when prisoner asleep without dog
428430
* @task_id 4
429431
*/
432+
#[TestDox('cannot liberate the prisoner when prisoner asleep without dog')]
430433
public function testCannotLiberateWhenPrisonerAsleepWithoutDog()
431434
{
432435
$infiltration = new AnnalynsInfiltration();
@@ -441,9 +444,9 @@ public function testCannotLiberateWhenPrisonerAsleepWithoutDog()
441444
}
442445

443446
/**
444-
* @testdox cannot liberate the prisoner when only archer asleep without dog
445447
* @task_id 4
446448
*/
449+
#[TestDox('cannot liberate the prisoner when only archer asleep without dog')]
447450
public function testCannotLiberateWhenArcherAsleepWithoutDog()
448451
{
449452
$infiltration = new AnnalynsInfiltration();
@@ -458,9 +461,9 @@ public function testCannotLiberateWhenArcherAsleepWithoutDog()
458461
}
459462

460463
/**
461-
* @testdox cannot liberate the prisoner when knight asleep without dog
462464
* @task_id 4
463465
*/
466+
#[TestDox('cannot liberate the prisoner when knight asleep without dog')]
464467
public function testCannotLiberateWhenKnightAsleepWithoutDog()
465468
{
466469
$infiltration = new AnnalynsInfiltration();
@@ -475,9 +478,9 @@ public function testCannotLiberateWhenKnightAsleepWithoutDog()
475478
}
476479

477480
/**
478-
* @testdox cannot liberate the prisoner when all awake without dog
479481
* @task_id 4
480482
*/
483+
#[TestDox('cannot liberate the prisoner when all awake without dog')]
481484
public function testCannotLiberateWhenAllAwakeWithoutDog()
482485
{
483486
$infiltration = new AnnalynsInfiltration();

exercises/concept/bootstrap.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@ PHP_STUB
7070
cat <<- PHP_STUB >> "${base_dir}/${test_file}"
7171
<?php
7272
73-
class ${new_classname}Test extends PHPUnit\Framework\TestCase
73+
use PHPUnit\Framework\TestCase;
74+
use PHPUnit\Framework\Attributes\TestDox;
75+
76+
class ${new_classname}Test extends TestCase
7477
{
7578
public static function setUpBeforeClass(): void
7679
{
7780
require_once '${new_classname}.php';
7881
}
7982
80-
/**
81-
* @testdox some test stub
82-
* @task_id 1
83-
*/
83+
/** @task_id 1 */
84+
#[TestDox('some test stub')]
8485
public function testStub()
8586
{
8687
\$class = new ${new_classname}();

0 commit comments

Comments
 (0)