@requires

@requires The @requires annotation can be used to skip tests when common preconditions, like the PHP Version or installed extensions, are not met. A complete list of possibilities and examples can be found at Table 7.3

@runInSeparateProcess

@runInSeparateProcess Indicates that a test should be run in a separate PHP process. use PHPUnit\Framework\TestCase; class MyTest extends TestCase { /** * @runInSeparateProcess */ public function testInSeparateProcess() { // ... } } Note: By default, PHPUnit will attempt to preserve the global state from the parent process by serializing all globals in the parent process and unserializing them in the child process. This can cause problems if the parent pro

@group

@group A test can be tagged as belonging to one or more groups using the @group annotation like this use PHPUnit\Framework\TestCase; class MyTest extends TestCase { /** * @group specification */ public function testSomething() { } /** * @group regresssion * @group bug2204 */ public function testSomethingElse() { } } Tests can be selected for execution based on groups using the --group and --exclude-group options of the command-line

@expectedExceptionMessageRegExp

@expectedExceptionMessageRegExp The expected message can also be specified as a regular expression using the @expectedExceptionMessageRegExp annotation. This is helpful for situations where a substring is not adequate for matching a given message. use PHPUnit\Framework\TestCase; class MyTest extends TestCase { /** * @expectedException MyException * @expectedExceptionMessageRegExp /Argument \d+ can not be an? \w+/ */ public function testExceptionHasRi

@expectedExceptionCode

@expectedExceptionCode The @expectedExceptionCode annotation, in conjunction with the @expectedException allows making assertions on the error code of a thrown exception thus being able to narrow down a specific exception. use PHPUnit\Framework\TestCase; class MyTest extends TestCase { /** * @expectedException MyException * @expectedExceptionCode 20 */ public function testExceptionHasErrorcode20() { throw new MyException('Some Message', 20); } } T

@expectedExceptionMessage

@expectedExceptionMessage The @expectedExceptionMessage annotation works similar to @expectedExceptionCode as it lets you make an assertion on the error message of an exception. use PHPUnit\Framework\TestCase; class MyTest extends TestCase { /** * @expectedException MyException * @expectedExceptionMessage Some Message */ public function testExceptionHasRightMessage() { throw new MyException('Some Message', 20); } } The expected message can be a

@dataProvider

@dataProvider A test method can accept arbitrary arguments. These arguments are to be provided by a data provider method (provider() in Example 2.5). The data provider method to be used is specified using the @dataProvider annotation. See the section called “Data Providers” for more details.

@depends

@depends PHPUnit supports the declaration of explicit dependencies between test methods. Such dependencies do not define the order in which the test methods are to be executed but they allow the returning of an instance of the test fixture by a producer and passing it to the dependent consumers. Example 2.2 shows how to use the @depends annotation to express dependencies between test methods. See the section called “Test Dependencies” for more details.

@expectedException

@expectedException Example 2.10 shows how to use the @expectedException annotation to test whether an exception is thrown inside the tested code. See the section called “Testing Exceptions” for more details.

@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() { // ... } }