@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

The XML Configuration File

PHPUnit The attributes of the <phpunit> element can be used to configure PHPUnit's core functionality. <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd" backupGlobals="true" backupStaticAttributes="false" <!--bootstrap="/path/to/bootstrap.php"--> cacheTokens="false" colors="false" convertErrorsToExceptions="true"

The Command-Line Test Runner

The PHPUnit command-line test runner can be invoked through the phpunit command. The following code shows how to run tests with the PHPUnit command-line test runner: phpunit ArrayTest PHPUnit 5.6.0 by Sebastian Bergmann and contributors. .. Time: 0 seconds OK (2 tests, 2 assertions) When invoked as shown above, the PHPUnit command-line test runner will look for a ArrayTest.php sourcefile in the current working directory, load it, and expect to find a ArrayTest test case class. It will th

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

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

assertCount()

assertCount() assertCount($expectedCount, $haystack[, string $message = '']) Reports an error identified by $message if the number of elements in $haystack is not $expectedCount. assertNotCount() is the inverse of this assertion and takes the same arguments. Example A.10: Usage of assertCount() <?php use PHPUnit\Framework\TestCase; class CountTest extends TestCase { public function testFailure() { $this->assertCount(0, ['foo']); } } ?> phpunit CountTest PHPUnit 5

assertTrue()

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

assertStringEndsWith()

assertStringEndsWith() assertStringEndsWith(string $suffix, string $string[, string $message = '']) Reports an error identified by $message if the $string does not end with $suffix. assertStringEndsNotWith() is the inverse of this assertion and takes the same arguments. Example A.46: Usage of assertStringEndsWith() <?php use PHPUnit\Framework\TestCase; class StringEndsWithTest extends TestCase { public function testFailure() { $this->assertStringEndsWith('suffix', 'foo'

assertJsonStringEqualsJsonFile()

assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonFile(mixed $expectedFile, mixed $actualJson[, string $message = '']) Reports an error identified by $message if the value of $actualJson does not match the value of $expectedFile. Example A.34: Usage of assertJsonStringEqualsJsonFile() <?php use PHPUnit\Framework\TestCase; class JsonStringEqualsJsonFileTest extends TestCase { public function testFailure() { $this->assertJsonStringEqualsJsonFile( 'p

assertFileIsWritable()

assertFileIsWritable() assertFileIsWritable(string $filename[, string $message = '']) Reports an error identified by $message if the file specified by $filename is not a file or is not writable. assertFileNotIsWritable() is the inverse of this assertion and takes the same arguments. Example A.25: Usage of assertFileIsWritable() <?php use PHPUnit\Framework\TestCase; class FileIsWritableTest extends TestCase { public function testFailure() { $this->assertFileIsWritable('/