@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.

assertFalse()

assertFalse() assertFalse(bool $condition[, string $message = '']) Reports an error identified by $message if $condition is true. assertNotFalse() is the inverse of this assertion and takes the same arguments. Example A.21: Usage of assertFalse() <?php use PHPUnit\Framework\TestCase; class FalseTest extends TestCase { public function testFailure() { $this->assertFalse(true); } } ?> phpunit FalseTest PHPUnit 5.6.0 by Sebastian Bergmann and contributors. F Time:

@preserveGlobalState

@preserveGlobalState When a test is run in a separate process, 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 process contains globals that are not serializable. To fix this, you can prevent PHPUnit from preserving global state with the @preserveGlobalState annotation. use PHPUnit\Framework\TestCase; class MyTest extends TestCase {

Risky Tests

PHPUnit can perform the additional checks documented below while it executes the tests. Useless Tests PHPUnit can be strict about tests that do not test anything. This check can be enabled by using the --report-useless-tests option on the commandline or by setting beStrictAboutTestsThatDoNotTestAnything="true" in PHPUnit's XML configuration file. A test that does not perform an assertion will be marked as risky when this check is enabled. Expectations on mock objects or annotations such as

assertDirectoryExists()

assertDirectoryExists() assertDirectoryExists(string $directory[, string $message = '']) Reports an error identified by $message if the directory specified by $directory does not exist. assertDirectoryNotExists() is the inverse of this assertion and takes the same arguments. Example A.11: Usage of assertDirectoryExists() <?php use PHPUnit\Framework\TestCase; class DirectoryExistsTest extends TestCase { public function testFailure() { $this->assertDirectoryExists('/path/

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

@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

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

@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.

assertLessThanOrEqual()

assertLessThanOrEqual() assertLessThanOrEqual(mixed $expected, mixed $actual[, string $message = '']) Reports an error identified by $message if the value of $actual is not less than or equal to the value of $expected. assertAttributeLessThanOrEqual() is a convenience wrapper that uses a public, protected, or private attribute of a class or object as the actual value. Example A.37: Usage of assertLessThanOrEqual() <?php use PHPUnit\Framework\TestCase; class LessThanOrEqualTest extends Tes