assertFileExists()

assertFileExists() assertFileExists(string $filename[, string $message = '']) Reports an error identified by $message if the file specified by $filename does not exist. assertFileNotExists() is the inverse of this assertion and takes the same arguments. Example A.23: Usage of assertFileExists() <?php use PHPUnit\Framework\TestCase; class FileExistsTest extends TestCase { public function testFailure() { $this->assertFileExists('/path/to/file'); } } ?> phpunit File

Extending PHPUnit

PHPUnit can be extended in various ways to make the writing of tests easier and customize the feedback you get from running tests. Here are common starting points to extend PHPUnit. Subclass PHPUnit\Framework\TestCase Write custom assertions and utility methods in an abstract subclass of PHPUnit\Framework\TestCase and derive your test case classes from that class. This is one of the easiest ways to extend PHPUnit. Write custom assertions When writing custom assertions it is the best pract

assertNan()

assertNan() assertNan(mixed $variable[, string $message = '']) Reports an error identified by $message if $variable is not NAN. Example A.38: Usage of assertNan() <?php use PHPUnit\Framework\TestCase; class NanTest extends TestCase { public function testFailure() { $this->assertNan(1); } } ?> phpunit NanTest PHPUnit 5.6.0 by Sebastian Bergmann and contributors. F Time: 0 seconds, Memory: 5.00Mb There was 1 failure: 1) NanTest::testFailure Failed asserting tha

assertArrayHasKey()

assertArrayHasKey() assertArrayHasKey(mixed $key, array $array[, string $message = '']) Reports an error identified by $message if $array does not have the $key. assertArrayNotHasKey() is the inverse of this assertion and takes the same arguments. Example A.1: Usage of assertArrayHasKey() <?php use PHPUnit\Framework\TestCase; class ArrayHasKeyTest extends TestCase { public function testFailure() { $this->assertArrayHasKey('foo', ['bar' => 'baz']); } } ?> phpun

@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

@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

@uses

@uses The @uses annotation specifies code which will be executed by a test, but is not intended to be covered by the test. A good example is a value object which is necessary for testing a unit of code. /** * @covers BankAccount::deposit * @uses Money */ public function testMoneyCanBeDepositedInAccount() { // ... } This annotation is especially useful in strict coverage mode where unintentionally covered code will cause a test to fail. See the section called “Unintentionally Covere

assertIsReadable()

assertIsReadable() assertIsReadable(string $filename[, string $message = '']) Reports an error identified by $message if the file or directory specified by $filename is not readable. assertNotIsReadable() is the inverse of this assertion and takes the same arguments. Example A.31: Usage of assertIsReadable() <?php use PHPUnit\Framework\TestCase; class IsReadableTest extends TestCase { public function testFailure() { $this->assertIsReadable('/path/to/unreadable'); }

assertEqualXMLStructure()

assertEqualXMLStructure() assertEqualXMLStructure(DOMElement $expectedElement, DOMElement $actualElement[, boolean $checkAttributes = false, string $message = '']) Reports an error identified by $message if the XML Structure of the DOMElement in $actualElement is not equal to the XML structure of the DOMElement in $expectedElement. Example A.15: Usage of assertEqualXMLStructure() <?php use PHPUnit\Framework\TestCase; class EqualXMLStructureTest extends TestCase { public function testF

assertSame()

assertSame() assertSame(mixed $expected, mixed $actual[, string $message = '']) Reports an error identified by $message if the two variables $expected and $actual do not have the same type and value. assertNotSame() is the inverse of this assertion and takes the same arguments. assertAttributeSame() and assertAttributeNotSame() are convenience wrappers that use a public, protected, or private attribute of a class or object as the actual value. Example A.44: Usage of assertSame() <?php use