@coversDefaultClass

@coversDefaultClass The @coversDefaultClass annotation can be used to specify a default namespace or class name. That way long names don't need to be repeated for every @covers annotation. See Example B.1. Example B.1: Using @coversDefaultClass to shorten annotations <?php use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Foo\CoveredClass */ class CoversDefaultClassTest extends TestCase { /** * @covers ::publicMethod */ public function testSomething() {

@covers

@covers The @covers annotation can be used in the test code to specify which method(s) a test method wants to test: /** * @covers BankAccount::getBalance */ public function testBalanceIsInitiallyZero() { $this->assertEquals(0, $this->ba->getBalance()); } If provided, only the code coverage information for the specified method(s) will be considered. Table B.1 shows the syntax of the @covers annotation. Table B.1. Annotations for specifying which methods are covered by a t

@codeCoverageIgnore*

@codeCoverageIgnore* The @codeCoverageIgnore, @codeCoverageIgnoreStart and @codeCoverageIgnoreEnd annotations can be used to exclude lines of code from the coverage analysis. For usage see the section called “Ignoring Code Blocks”.

@beforeClass

@beforeClass The @beforeClass annotation can be used to specify static methods that should be called before any test methods in a test class are run to set up shared fixtures. use PHPUnit\Framework\TestCase; class MyTest extends TestCase { /** * @beforeClass */ public static function setUpSomeSharedFixtures() { // ... } /** * @beforeClass */ public static function setUpSomeOtherSharedFixtures() { // ... } }

@before

@before The @before annotation can be used to specify methods that should be called before each test method in a test case class. use PHPUnit\Framework\TestCase; class MyTest extends TestCase { /** * @before */ public function setupSomeFixtures() { // ... } /** * @before */ public function setupSomeOtherFixtures() { // ... } }

@backupStaticAttributes

@backupStaticAttributes The @backupStaticAttributes annotation can be used to back up all static property values in all declared classes before each test and restore them afterwards. It may be used at the test case class or test method level: use PHPUnit\Framework\TestCase; /** * @backupStaticAttributes enabled */ class MyTest extends TestCase { /** * @backupStaticAttributes disabled */ public function testThatInteractsWithStaticAttributes() { // ... } }

@backupGlobals

@backupGlobals The backup and restore operations for global variables can be completely disabled for all tests of a test case class like this use PHPUnit\Framework\TestCase; /** * @backupGlobals disabled */ class MyTest extends TestCase { // ... } The @backupGlobals annotation can also be used on the test method level. This allows for a fine-grained configuration of the backup and restore operations: use PHPUnit\Framework\TestCase; /** * @backupGlobals disabled */ class MyTest e

@author

@author The @author annotation is an alias for the @group annotation (see the section called “@group”) and allows to filter tests based on their authors.

@afterClass

@afterClass The @afterClass annotation can be used to specify static methods that should be called after all test methods in a test class have been run to clean up shared fixtures. use PHPUnit\Framework\TestCase; class MyTest extends TestCase { /** * @afterClass */ public static function tearDownSomeSharedFixtures() { // ... } /** * @afterClass */ public static function tearDownSomeOtherSharedFixtures() { // ... } }

@after

@after The @after annotation can be used to specify methods that should be called after each test method in a test case class. use PHPUnit\Framework\TestCase; class MyTest extends TestCase { /** * @after */ public function tearDownSomeFixtures() { // ... } /** * @after */ public function tearDownSomeOtherFixtures() { // ... } }