Skip to content

Commit

Permalink
Merge branch '9.2' into 9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 16, 2020
2 parents 42ce870 + cebcd4e commit 2edd7d0
Show file tree
Hide file tree
Showing 9 changed files with 399 additions and 446 deletions.
98 changes: 53 additions & 45 deletions src/annotations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,23 @@ that should be called after each test method in a test case class.

.. code-block:: php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
final class MyTest extends TestCase
{
/**
* @after
*/
public function tearDownSomeFixtures()
public function tearDownSomeFixtures(): void
{
// ...
}
/**
* @after
*/
public function tearDownSomeOtherFixtures()
public function tearDownSomeOtherFixtures(): void
{
// ...
}
Expand All @@ -75,22 +76,23 @@ class have been run to clean up shared fixtures.

.. code-block:: php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
final class MyTest extends TestCase
{
/**
* @afterClass
*/
public static function tearDownSomeSharedFixtures()
public static function tearDownSomeSharedFixtures(): void
{
// ...
}
/**
* @afterClass
*/
public static function tearDownSomeOtherSharedFixtures()
public static function tearDownSomeOtherSharedFixtures(): void
{
// ...
}
Expand All @@ -107,12 +109,13 @@ The ``@backupGlobals enabled`` annotation can be used on the class level to enab

.. code-block:: php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* @backupGlobals enabled
*/
class MyTest extends TestCase
final class MyTest extends TestCase
{
// ...
}
Expand All @@ -123,12 +126,13 @@ backup and restore operations:

.. code-block:: php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* @backupGlobals enabled
*/
class MyTest extends TestCase
final class MyTest extends TestCase
{
public function testThatInteractsWithGlobalVariables()
{
Expand All @@ -138,7 +142,7 @@ backup and restore operations:
/**
* @backupGlobals disabled
*/
public function testThatDoesNotInteractWithGlobalVariables()
public function testThatDoesNotInteractWithGlobalVariables(): void
{
// ...
}
Expand All @@ -155,12 +159,13 @@ The ``@backupStaticAttributes enabled`` annotation can be used on the class leve

.. code-block:: php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* @backupStaticAttributes enabled
*/
class MyTest extends TestCase
final class MyTest extends TestCase
{
// ...
}
Expand All @@ -178,15 +183,15 @@ backup and restore operations:
*/
class MyTest extends TestCase
{
public function testThatInteractsWithStaticAttributes()
public function testThatInteractsWithStaticAttributes(): void
{
// ...
}
/**
* @backupStaticAttributes disabled
*/
public function testThatDoesNotInteractWithStaticAttributes()
public function testThatDoesNotInteractWithStaticAttributes(): void
{
// ...
}
Expand All @@ -210,22 +215,23 @@ that should be called before each test method in a test case class.

.. code-block:: php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
final class MyTest extends TestCase
{
/**
* @before
*/
public function setupSomeFixtures()
public function setupSomeFixtures(): void
{
// ...
}
/**
* @before
*/
public function setupSomeOtherFixtures()
public function setupSomeOtherFixtures(): void
{
// ...
}
Expand All @@ -242,22 +248,23 @@ class are run to set up shared fixtures.

.. code-block:: php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
final class MyTest extends TestCase
{
/**
* @beforeClass
*/
public static function setUpSomeSharedFixtures()
public static function setUpSomeSharedFixtures(): void
{
// ...
}
/**
* @beforeClass
*/
public static function setUpSomeOtherSharedFixtures()
public static function setUpSomeOtherSharedFixtures(): void
{
// ...
}
Expand Down Expand Up @@ -288,7 +295,7 @@ specify which parts of the code it is supposed to test:
/**
* @covers \BankAccount
*/
public function testBalanceIsInitiallyZero()
public function testBalanceIsInitiallyZero(): void
{
$this->assertSame(0, $this->ba->getBalance());
}
Expand Down Expand Up @@ -364,18 +371,18 @@ backslash (even if this not required for the annotation to work correctly).
:caption: Using @coversDefaultClass to shorten annotations
:name: appendixes.annotations.examples.CoversDefaultClassTest.php
<?php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \Foo\CoveredClass
*/
class CoversDefaultClassTest extends TestCase
final class CoversDefaultClassTest extends TestCase
{
/**
* @covers ::publicMethod
*/
public function testSomething()
public function testSomething(): void
{
$o = new Foo\CoveredClass;
$o->publicMethod();
Expand Down Expand Up @@ -445,22 +452,23 @@ A test can be tagged as belonging to one or more groups using the

.. code-block:: php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
final class MyTest extends TestCase
{
/**
* @group specification
*/
public function testSomething()
public function testSomething(): void
{
}
/**
* @group regression
* @group bug2204
*/
public function testSomethingElse()
public function testSomethingElse(): void
{
}
}
Expand Down Expand Up @@ -517,15 +525,16 @@ PHPUnit from preserving global state with the

.. code-block:: php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
final class MyTest extends TestCase
{
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testInSeparateProcess()
public function testInSeparateProcess(): void
{
// ...
}
Expand All @@ -552,12 +561,13 @@ PHP process.

.. code-block:: php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* @runTestsInSeparateProcesses
*/
class MyTest extends TestCase
final class MyTest extends TestCase
{
// ...
}
Expand All @@ -578,14 +588,15 @@ Indicates that a test should be run in a separate PHP process.

.. code-block:: php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
class MyTest extends TestCase
final class MyTest extends TestCase
{
/**
* @runInSeparateProcess
*/
public function testInSeparateProcess()
public function testInSeparateProcess(): void
{
// ...
}
Expand Down Expand Up @@ -632,7 +643,7 @@ annotation in a method's DocBlock to mark it as a test method.
/**
* @test
*/
public function initialBalanceShouldBe0()
public function initialBalanceShouldBe0(): void
{
$this->assertSame(0, $this->ba->getBalance());
}
Expand All @@ -649,15 +660,18 @@ The ``@testdox`` annotation can be applied to both test classes and test methods

.. code-block:: php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* @testdox A bank account
*/
class BankAccountTest extends TestCase
final class BankAccountTest extends TestCase
{
/**
* @testdox has an initial balance of zero
*/
public function balanceIsInitiallyZero()
public function balanceIsInitiallyZero(): void
{
$this->assertSame(0, $this->ba->getBalance());
}
Expand Down Expand Up @@ -710,13 +724,10 @@ more about passing a set of data to a test.
.. code-block:: php
/**
* @param string $input
* @param int $expectedLength
*
* @testWith ["test", 4]
* ["longer-string", 13]
* @testWith ["test", 4]
* ["longer-string", 13]
*/
public function testStringLength(string $input, int $expectedLength)
public function testStringLength(string $input, int $expectedLength): void
{
$this->assertSame($expectedLength, strlen($input));
}
Expand All @@ -726,12 +737,9 @@ An object representation in JSON will be converted into an associative array.
.. code-block:: php
/**
* @param array $array
* @param array $keys
*
* @testWith [{"day": "monday", "conditions": "sunny"}, ["day", "conditions"]]
* @testWith [{"day": "monday", "conditions": "sunny"}, ["day", "conditions"]]
*/
public function testArrayKeys($array, $keys)
public function testArrayKeys(array $array, array $keys): void
{
$this->assertSame($keys, array_keys($array));
}
Expand Down Expand Up @@ -760,7 +768,7 @@ example is a value object which is necessary for testing a unit of code.
* @covers \BankAccount
* @uses \Money
*/
public function testMoneyCanBeDepositedInAccount()
public function testMoneyCanBeDepositedInAccount(): void
{
// ...
}
Expand Down
Loading

0 comments on commit 2edd7d0

Please sign in to comment.