Skip to content

Commit 2edd7d0

Browse files
Merge branch '9.2' into 9.3
2 parents 42ce870 + cebcd4e commit 2edd7d0

9 files changed

+399
-446
lines changed

src/annotations.rst

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,23 @@ that should be called after each test method in a test case class.
4343

4444
.. code-block:: php
4545
46+
<?php declare(strict_types=1);
4647
use PHPUnit\Framework\TestCase;
4748
48-
class MyTest extends TestCase
49+
final class MyTest extends TestCase
4950
{
5051
/**
5152
* @after
5253
*/
53-
public function tearDownSomeFixtures()
54+
public function tearDownSomeFixtures(): void
5455
{
5556
// ...
5657
}
5758
5859
/**
5960
* @after
6061
*/
61-
public function tearDownSomeOtherFixtures()
62+
public function tearDownSomeOtherFixtures(): void
6263
{
6364
// ...
6465
}
@@ -75,22 +76,23 @@ class have been run to clean up shared fixtures.
7576

7677
.. code-block:: php
7778
79+
<?php declare(strict_types=1);
7880
use PHPUnit\Framework\TestCase;
7981
80-
class MyTest extends TestCase
82+
final class MyTest extends TestCase
8183
{
8284
/**
8385
* @afterClass
8486
*/
85-
public static function tearDownSomeSharedFixtures()
87+
public static function tearDownSomeSharedFixtures(): void
8688
{
8789
// ...
8890
}
8991
9092
/**
9193
* @afterClass
9294
*/
93-
public static function tearDownSomeOtherSharedFixtures()
95+
public static function tearDownSomeOtherSharedFixtures(): void
9496
{
9597
// ...
9698
}
@@ -107,12 +109,13 @@ The ``@backupGlobals enabled`` annotation can be used on the class level to enab
107109

108110
.. code-block:: php
109111
112+
<?php declare(strict_types=1);
110113
use PHPUnit\Framework\TestCase;
111114
112115
/**
113116
* @backupGlobals enabled
114117
*/
115-
class MyTest extends TestCase
118+
final class MyTest extends TestCase
116119
{
117120
// ...
118121
}
@@ -123,12 +126,13 @@ backup and restore operations:
123126

124127
.. code-block:: php
125128
129+
<?php declare(strict_types=1);
126130
use PHPUnit\Framework\TestCase;
127131
128132
/**
129133
* @backupGlobals enabled
130134
*/
131-
class MyTest extends TestCase
135+
final class MyTest extends TestCase
132136
{
133137
public function testThatInteractsWithGlobalVariables()
134138
{
@@ -138,7 +142,7 @@ backup and restore operations:
138142
/**
139143
* @backupGlobals disabled
140144
*/
141-
public function testThatDoesNotInteractWithGlobalVariables()
145+
public function testThatDoesNotInteractWithGlobalVariables(): void
142146
{
143147
// ...
144148
}
@@ -155,12 +159,13 @@ The ``@backupStaticAttributes enabled`` annotation can be used on the class leve
155159

156160
.. code-block:: php
157161
162+
<?php declare(strict_types=1);
158163
use PHPUnit\Framework\TestCase;
159164
160165
/**
161166
* @backupStaticAttributes enabled
162167
*/
163-
class MyTest extends TestCase
168+
final class MyTest extends TestCase
164169
{
165170
// ...
166171
}
@@ -178,15 +183,15 @@ backup and restore operations:
178183
*/
179184
class MyTest extends TestCase
180185
{
181-
public function testThatInteractsWithStaticAttributes()
186+
public function testThatInteractsWithStaticAttributes(): void
182187
{
183188
// ...
184189
}
185190
186191
/**
187192
* @backupStaticAttributes disabled
188193
*/
189-
public function testThatDoesNotInteractWithStaticAttributes()
194+
public function testThatDoesNotInteractWithStaticAttributes(): void
190195
{
191196
// ...
192197
}
@@ -210,22 +215,23 @@ that should be called before each test method in a test case class.
210215

211216
.. code-block:: php
212217
218+
<?php declare(strict_types=1);
213219
use PHPUnit\Framework\TestCase;
214220
215-
class MyTest extends TestCase
221+
final class MyTest extends TestCase
216222
{
217223
/**
218224
* @before
219225
*/
220-
public function setupSomeFixtures()
226+
public function setupSomeFixtures(): void
221227
{
222228
// ...
223229
}
224230
225231
/**
226232
* @before
227233
*/
228-
public function setupSomeOtherFixtures()
234+
public function setupSomeOtherFixtures(): void
229235
{
230236
// ...
231237
}
@@ -242,22 +248,23 @@ class are run to set up shared fixtures.
242248

243249
.. code-block:: php
244250
251+
<?php declare(strict_types=1);
245252
use PHPUnit\Framework\TestCase;
246253
247-
class MyTest extends TestCase
254+
final class MyTest extends TestCase
248255
{
249256
/**
250257
* @beforeClass
251258
*/
252-
public static function setUpSomeSharedFixtures()
259+
public static function setUpSomeSharedFixtures(): void
253260
{
254261
// ...
255262
}
256263
257264
/**
258265
* @beforeClass
259266
*/
260-
public static function setUpSomeOtherSharedFixtures()
267+
public static function setUpSomeOtherSharedFixtures(): void
261268
{
262269
// ...
263270
}
@@ -288,7 +295,7 @@ specify which parts of the code it is supposed to test:
288295
/**
289296
* @covers \BankAccount
290297
*/
291-
public function testBalanceIsInitiallyZero()
298+
public function testBalanceIsInitiallyZero(): void
292299
{
293300
$this->assertSame(0, $this->ba->getBalance());
294301
}
@@ -364,18 +371,18 @@ backslash (even if this not required for the annotation to work correctly).
364371
:caption: Using @coversDefaultClass to shorten annotations
365372
:name: appendixes.annotations.examples.CoversDefaultClassTest.php
366373
367-
<?php
374+
<?php declare(strict_types=1);
368375
use PHPUnit\Framework\TestCase;
369376
370377
/**
371378
* @coversDefaultClass \Foo\CoveredClass
372379
*/
373-
class CoversDefaultClassTest extends TestCase
380+
final class CoversDefaultClassTest extends TestCase
374381
{
375382
/**
376383
* @covers ::publicMethod
377384
*/
378-
public function testSomething()
385+
public function testSomething(): void
379386
{
380387
$o = new Foo\CoveredClass;
381388
$o->publicMethod();
@@ -445,22 +452,23 @@ A test can be tagged as belonging to one or more groups using the
445452

446453
.. code-block:: php
447454
455+
<?php declare(strict_types=1);
448456
use PHPUnit\Framework\TestCase;
449457
450-
class MyTest extends TestCase
458+
final class MyTest extends TestCase
451459
{
452460
/**
453461
* @group specification
454462
*/
455-
public function testSomething()
463+
public function testSomething(): void
456464
{
457465
}
458466
459467
/**
460468
* @group regression
461469
* @group bug2204
462470
*/
463-
public function testSomethingElse()
471+
public function testSomethingElse(): void
464472
{
465473
}
466474
}
@@ -517,15 +525,16 @@ PHPUnit from preserving global state with the
517525

518526
.. code-block:: php
519527
528+
<?php declare(strict_types=1);
520529
use PHPUnit\Framework\TestCase;
521530
522-
class MyTest extends TestCase
531+
final class MyTest extends TestCase
523532
{
524533
/**
525534
* @runInSeparateProcess
526535
* @preserveGlobalState disabled
527536
*/
528-
public function testInSeparateProcess()
537+
public function testInSeparateProcess(): void
529538
{
530539
// ...
531540
}
@@ -552,12 +561,13 @@ PHP process.
552561

553562
.. code-block:: php
554563
564+
<?php declare(strict_types=1);
555565
use PHPUnit\Framework\TestCase;
556566
557567
/**
558568
* @runTestsInSeparateProcesses
559569
*/
560-
class MyTest extends TestCase
570+
final class MyTest extends TestCase
561571
{
562572
// ...
563573
}
@@ -578,14 +588,15 @@ Indicates that a test should be run in a separate PHP process.
578588

579589
.. code-block:: php
580590
591+
<?php declare(strict_types=1);
581592
use PHPUnit\Framework\TestCase;
582593
583-
class MyTest extends TestCase
594+
final class MyTest extends TestCase
584595
{
585596
/**
586597
* @runInSeparateProcess
587598
*/
588-
public function testInSeparateProcess()
599+
public function testInSeparateProcess(): void
589600
{
590601
// ...
591602
}
@@ -632,7 +643,7 @@ annotation in a method's DocBlock to mark it as a test method.
632643
/**
633644
* @test
634645
*/
635-
public function initialBalanceShouldBe0()
646+
public function initialBalanceShouldBe0(): void
636647
{
637648
$this->assertSame(0, $this->ba->getBalance());
638649
}
@@ -649,15 +660,18 @@ The ``@testdox`` annotation can be applied to both test classes and test methods
649660

650661
.. code-block:: php
651662
663+
<?php declare(strict_types=1);
664+
use PHPUnit\Framework\TestCase;
665+
652666
/**
653667
* @testdox A bank account
654668
*/
655-
class BankAccountTest extends TestCase
669+
final class BankAccountTest extends TestCase
656670
{
657671
/**
658672
* @testdox has an initial balance of zero
659673
*/
660-
public function balanceIsInitiallyZero()
674+
public function balanceIsInitiallyZero(): void
661675
{
662676
$this->assertSame(0, $this->ba->getBalance());
663677
}
@@ -710,13 +724,10 @@ more about passing a set of data to a test.
710724
.. code-block:: php
711725
712726
/**
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]
718729
*/
719-
public function testStringLength(string $input, int $expectedLength)
730+
public function testStringLength(string $input, int $expectedLength): void
720731
{
721732
$this->assertSame($expectedLength, strlen($input));
722733
}
@@ -726,12 +737,9 @@ An object representation in JSON will be converted into an associative array.
726737
.. code-block:: php
727738
728739
/**
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"]]
733741
*/
734-
public function testArrayKeys($array, $keys)
742+
public function testArrayKeys(array $array, array $keys): void
735743
{
736744
$this->assertSame($keys, array_keys($array));
737745
}
@@ -760,7 +768,7 @@ example is a value object which is necessary for testing a unit of code.
760768
* @covers \BankAccount
761769
* @uses \Money
762770
*/
763-
public function testMoneyCanBeDepositedInAccount()
771+
public function testMoneyCanBeDepositedInAccount(): void
764772
{
765773
// ...
766774
}

0 commit comments

Comments
 (0)