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:

assertDirectoryIsWritable()

assertDirectoryIsWritable() assertDirectoryIsWritable(string $directory[, string $message = '']) Reports an error identified by $message if the directory specified by $directory is not a directory or is not writable. assertDirectoryNotIsWritable() is the inverse of this assertion and takes the same arguments. Example A.13: Usage of assertDirectoryIsWritable() <?php use PHPUnit\Framework\TestCase; class DirectoryIsWritableTest extends TestCase { public function testFailure() {

assertInternalType()

assertInternalType() assertInternalType($expected, $actual[, $message = '']) Reports an error identified by $message if $actual is not of the $expected type. assertNotInternalType() is the inverse of this assertion and takes the same arguments. assertAttributeInternalType() and assertAttributeNotInternalType() are convenience wrappers that can be applied to a public, protected, or private attribute of a class or object. Example A.30: Usage of assertInternalType() <?php use PHPUnit\Framewor

@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

assertInfinite()

assertInfinite() assertInfinite(mixed $variable[, string $message = '']) Reports an error identified by $message if $variable is not INF. assertFinite() is the inverse of this assertion and takes the same arguments. Example A.28: Usage of assertInfinite() <?php use PHPUnit\Framework\TestCase; class InfiniteTest extends TestCase { public function testFailure() { $this->assertInfinite(1); } } ?> phpunit InfiniteTest PHPUnit 5.6.0 by Sebastian Bergmann and contribut

assertNull()

assertNull() assertNull(mixed $variable[, string $message = '']) Reports an error identified by $message if $variable is not null. assertNotNull() is the inverse of this assertion and takes the same arguments. Example A.39: Usage of assertNull() <?php use PHPUnit\Framework\TestCase; class NullTest extends TestCase { public function testFailure() { $this->assertNull('foo'); } } ?> phpunit NotNullTest PHPUnit 5.6.0 by Sebastian Bergmann and contributors. F Time:

assertContainsOnlyInstancesOf()

assertContainsOnlyInstancesOf() assertContainsOnlyInstancesOf(string $classname, Traversable|array $haystack[, string $message = '']) Reports an error identified by $message if $haystack does not contain only instances of class $classname. Example A.9: Usage of assertContainsOnlyInstancesOf() <?php use PHPUnit\Framework\TestCase; class ContainsOnlyInstancesOfTest extends TestCase { public function testFailure() { $this->assertContainsOnlyInstancesOf( Foo::cl

@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