@@ -43,22 +43,23 @@ that should be called after each test method in a test case class.
43
43
44
44
.. code-block :: php
45
45
46
+ <?php declare(strict_types=1);
46
47
use PHPUnit\Framework\TestCase;
47
48
48
- class MyTest extends TestCase
49
+ final class MyTest extends TestCase
49
50
{
50
51
/**
51
52
* @after
52
53
*/
53
- public function tearDownSomeFixtures()
54
+ public function tearDownSomeFixtures(): void
54
55
{
55
56
// ...
56
57
}
57
58
58
59
/**
59
60
* @after
60
61
*/
61
- public function tearDownSomeOtherFixtures()
62
+ public function tearDownSomeOtherFixtures(): void
62
63
{
63
64
// ...
64
65
}
@@ -75,22 +76,23 @@ class have been run to clean up shared fixtures.
75
76
76
77
.. code-block :: php
77
78
79
+ <?php declare(strict_types=1);
78
80
use PHPUnit\Framework\TestCase;
79
81
80
- class MyTest extends TestCase
82
+ final class MyTest extends TestCase
81
83
{
82
84
/**
83
85
* @afterClass
84
86
*/
85
- public static function tearDownSomeSharedFixtures()
87
+ public static function tearDownSomeSharedFixtures(): void
86
88
{
87
89
// ...
88
90
}
89
91
90
92
/**
91
93
* @afterClass
92
94
*/
93
- public static function tearDownSomeOtherSharedFixtures()
95
+ public static function tearDownSomeOtherSharedFixtures(): void
94
96
{
95
97
// ...
96
98
}
@@ -107,12 +109,13 @@ The ``@backupGlobals enabled`` annotation can be used on the class level to enab
107
109
108
110
.. code-block :: php
109
111
112
+ <?php declare(strict_types=1);
110
113
use PHPUnit\Framework\TestCase;
111
114
112
115
/**
113
116
* @backupGlobals enabled
114
117
*/
115
- class MyTest extends TestCase
118
+ final class MyTest extends TestCase
116
119
{
117
120
// ...
118
121
}
@@ -123,12 +126,13 @@ backup and restore operations:
123
126
124
127
.. code-block :: php
125
128
129
+ <?php declare(strict_types=1);
126
130
use PHPUnit\Framework\TestCase;
127
131
128
132
/**
129
133
* @backupGlobals enabled
130
134
*/
131
- class MyTest extends TestCase
135
+ final class MyTest extends TestCase
132
136
{
133
137
public function testThatInteractsWithGlobalVariables()
134
138
{
@@ -138,7 +142,7 @@ backup and restore operations:
138
142
/**
139
143
* @backupGlobals disabled
140
144
*/
141
- public function testThatDoesNotInteractWithGlobalVariables()
145
+ public function testThatDoesNotInteractWithGlobalVariables(): void
142
146
{
143
147
// ...
144
148
}
@@ -155,12 +159,13 @@ The ``@backupStaticAttributes enabled`` annotation can be used on the class leve
155
159
156
160
.. code-block :: php
157
161
162
+ <?php declare(strict_types=1);
158
163
use PHPUnit\Framework\TestCase;
159
164
160
165
/**
161
166
* @backupStaticAttributes enabled
162
167
*/
163
- class MyTest extends TestCase
168
+ final class MyTest extends TestCase
164
169
{
165
170
// ...
166
171
}
@@ -178,15 +183,15 @@ backup and restore operations:
178
183
*/
179
184
class MyTest extends TestCase
180
185
{
181
- public function testThatInteractsWithStaticAttributes()
186
+ public function testThatInteractsWithStaticAttributes(): void
182
187
{
183
188
// ...
184
189
}
185
190
186
191
/**
187
192
* @backupStaticAttributes disabled
188
193
*/
189
- public function testThatDoesNotInteractWithStaticAttributes()
194
+ public function testThatDoesNotInteractWithStaticAttributes(): void
190
195
{
191
196
// ...
192
197
}
@@ -210,22 +215,23 @@ that should be called before each test method in a test case class.
210
215
211
216
.. code-block :: php
212
217
218
+ <?php declare(strict_types=1);
213
219
use PHPUnit\Framework\TestCase;
214
220
215
- class MyTest extends TestCase
221
+ final class MyTest extends TestCase
216
222
{
217
223
/**
218
224
* @before
219
225
*/
220
- public function setupSomeFixtures()
226
+ public function setupSomeFixtures(): void
221
227
{
222
228
// ...
223
229
}
224
230
225
231
/**
226
232
* @before
227
233
*/
228
- public function setupSomeOtherFixtures()
234
+ public function setupSomeOtherFixtures(): void
229
235
{
230
236
// ...
231
237
}
@@ -242,22 +248,23 @@ class are run to set up shared fixtures.
242
248
243
249
.. code-block :: php
244
250
251
+ <?php declare(strict_types=1);
245
252
use PHPUnit\Framework\TestCase;
246
253
247
- class MyTest extends TestCase
254
+ final class MyTest extends TestCase
248
255
{
249
256
/**
250
257
* @beforeClass
251
258
*/
252
- public static function setUpSomeSharedFixtures()
259
+ public static function setUpSomeSharedFixtures(): void
253
260
{
254
261
// ...
255
262
}
256
263
257
264
/**
258
265
* @beforeClass
259
266
*/
260
- public static function setUpSomeOtherSharedFixtures()
267
+ public static function setUpSomeOtherSharedFixtures(): void
261
268
{
262
269
// ...
263
270
}
@@ -288,7 +295,7 @@ specify which parts of the code it is supposed to test:
288
295
/**
289
296
* @covers \BankAccount
290
297
*/
291
- public function testBalanceIsInitiallyZero()
298
+ public function testBalanceIsInitiallyZero(): void
292
299
{
293
300
$this->assertSame(0, $this->ba->getBalance());
294
301
}
@@ -364,18 +371,18 @@ backslash (even if this not required for the annotation to work correctly).
364
371
:caption: Using @coversDefaultClass to shorten annotations
365
372
:name: appendixes.annotations.examples.CoversDefaultClassTest.php
366
373
367
- <?php
374
+ <?php declare(strict_types=1);
368
375
use PHPUnit\Framework\TestCase;
369
376
370
377
/**
371
378
* @coversDefaultClass \Foo\CoveredClass
372
379
*/
373
- class CoversDefaultClassTest extends TestCase
380
+ final class CoversDefaultClassTest extends TestCase
374
381
{
375
382
/**
376
383
* @covers ::publicMethod
377
384
*/
378
- public function testSomething()
385
+ public function testSomething(): void
379
386
{
380
387
$o = new Foo\CoveredClass;
381
388
$o->publicMethod();
@@ -445,22 +452,23 @@ A test can be tagged as belonging to one or more groups using the
445
452
446
453
.. code-block :: php
447
454
455
+ <?php declare(strict_types=1);
448
456
use PHPUnit\Framework\TestCase;
449
457
450
- class MyTest extends TestCase
458
+ final class MyTest extends TestCase
451
459
{
452
460
/**
453
461
* @group specification
454
462
*/
455
- public function testSomething()
463
+ public function testSomething(): void
456
464
{
457
465
}
458
466
459
467
/**
460
468
* @group regression
461
469
* @group bug2204
462
470
*/
463
- public function testSomethingElse()
471
+ public function testSomethingElse(): void
464
472
{
465
473
}
466
474
}
@@ -517,15 +525,16 @@ PHPUnit from preserving global state with the
517
525
518
526
.. code-block :: php
519
527
528
+ <?php declare(strict_types=1);
520
529
use PHPUnit\Framework\TestCase;
521
530
522
- class MyTest extends TestCase
531
+ final class MyTest extends TestCase
523
532
{
524
533
/**
525
534
* @runInSeparateProcess
526
535
* @preserveGlobalState disabled
527
536
*/
528
- public function testInSeparateProcess()
537
+ public function testInSeparateProcess(): void
529
538
{
530
539
// ...
531
540
}
@@ -552,12 +561,13 @@ PHP process.
552
561
553
562
.. code-block :: php
554
563
564
+ <?php declare(strict_types=1);
555
565
use PHPUnit\Framework\TestCase;
556
566
557
567
/**
558
568
* @runTestsInSeparateProcesses
559
569
*/
560
- class MyTest extends TestCase
570
+ final class MyTest extends TestCase
561
571
{
562
572
// ...
563
573
}
@@ -578,14 +588,15 @@ Indicates that a test should be run in a separate PHP process.
578
588
579
589
.. code-block :: php
580
590
591
+ <?php declare(strict_types=1);
581
592
use PHPUnit\Framework\TestCase;
582
593
583
- class MyTest extends TestCase
594
+ final class MyTest extends TestCase
584
595
{
585
596
/**
586
597
* @runInSeparateProcess
587
598
*/
588
- public function testInSeparateProcess()
599
+ public function testInSeparateProcess(): void
589
600
{
590
601
// ...
591
602
}
@@ -632,7 +643,7 @@ annotation in a method's DocBlock to mark it as a test method.
632
643
/**
633
644
* @test
634
645
*/
635
- public function initialBalanceShouldBe0()
646
+ public function initialBalanceShouldBe0(): void
636
647
{
637
648
$this->assertSame(0, $this->ba->getBalance());
638
649
}
@@ -649,15 +660,18 @@ The ``@testdox`` annotation can be applied to both test classes and test methods
649
660
650
661
.. code-block :: php
651
662
663
+ <?php declare(strict_types=1);
664
+ use PHPUnit\Framework\TestCase;
665
+
652
666
/**
653
667
* @testdox A bank account
654
668
*/
655
- class BankAccountTest extends TestCase
669
+ final class BankAccountTest extends TestCase
656
670
{
657
671
/**
658
672
* @testdox has an initial balance of zero
659
673
*/
660
- public function balanceIsInitiallyZero()
674
+ public function balanceIsInitiallyZero(): void
661
675
{
662
676
$this->assertSame(0, $this->ba->getBalance());
663
677
}
@@ -710,13 +724,10 @@ more about passing a set of data to a test.
710
724
.. code-block :: php
711
725
712
726
/**
713
- * @param string $input
714
- * @param int $expectedLength
715
- *
716
- * @testWith ["test", 4]
717
- * ["longer-string", 13]
727
+ * @testWith ["test", 4]
728
+ * ["longer-string", 13]
718
729
*/
719
- public function testStringLength(string $input, int $expectedLength)
730
+ public function testStringLength(string $input, int $expectedLength): void
720
731
{
721
732
$this->assertSame($expectedLength, strlen($input));
722
733
}
@@ -726,12 +737,9 @@ An object representation in JSON will be converted into an associative array.
726
737
.. code-block :: php
727
738
728
739
/**
729
- * @param array $array
730
- * @param array $keys
731
- *
732
- * @testWith [{"day": "monday", "conditions": "sunny"}, ["day", "conditions"]]
740
+ * @testWith [{"day": "monday", "conditions": "sunny"}, ["day", "conditions"]]
733
741
*/
734
- public function testArrayKeys($array, $keys)
742
+ public function testArrayKeys(array $array, array $keys): void
735
743
{
736
744
$this->assertSame($keys, array_keys($array));
737
745
}
@@ -760,7 +768,7 @@ example is a value object which is necessary for testing a unit of code.
760
768
* @covers \BankAccount
761
769
* @uses \Money
762
770
*/
763
- public function testMoneyCanBeDepositedInAccount()
771
+ public function testMoneyCanBeDepositedInAccount(): void
764
772
{
765
773
// ...
766
774
}
0 commit comments