@small

@small The @small annotation is an alias for @group small. A small test must not depend on a test marked as @medium or @large. If the PHP_Invoker package is installed and strict mode is enabled, a small test will fail if it takes longer than 1 second to execute. This timeout is configurable via the timeoutForSmallTests attribute in the XML configuration file. Tests need to be explicitly annotated by either @small, @medium, or @large to enable run time limits.

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

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

@backupGlobals

@backupGlobals The backup and restore operations for global variables can be completely disabled for all tests of a test case class like this use PHPUnit\Framework\TestCase; /** * @backupGlobals disabled */ class MyTest extends TestCase { // ... } The @backupGlobals annotation can also be used on the test method level. This allows for a fine-grained configuration of the backup and restore operations: use PHPUnit\Framework\TestCase; /** * @backupGlobals disabled */ class MyTest e

assertXmlStringEqualsXmlString()

assertXmlStringEqualsXmlString() assertXmlStringEqualsXmlString(string $expectedXml, string $actualXml[, string $message = '']) Reports an error identified by $message if the XML document in $actualXml is not equal to the XML document in $expectedXml. assertXmlStringNotEqualsXmlString() is the inverse of this assertion and takes the same arguments. Example A.53: Usage of assertXmlStringEqualsXmlString() <?php use PHPUnit\Framework\TestCase; class XmlStringEqualsXmlStringTest extends TestC

@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

@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

assertContains()

assertContains() assertContains(mixed $needle, Iterator|array $haystack[, string $message = '']) Reports an error identified by $message if $needle is not an element of $haystack. assertNotContains() is the inverse of this assertion and takes the same arguments. assertAttributeContains() and assertAttributeNotContains() are convenience wrappers that use a public, protected, or private attribute of a class or object as the haystack. Example A.5: Usage of assertContains() <?php use PHPUnit\F

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

assertFileEquals()

assertFileEquals() assertFileEquals(string $expected, string $actual[, string $message = '']) Reports an error identified by $message if the file specified by $expected does not have the same contents as the file specified by $actual. assertFileNotEquals() is the inverse of this assertion and takes the same arguments. Example A.22: Usage of assertFileEquals() <?php use PHPUnit\Framework\TestCase; class FileEqualsTest extends TestCase { public function testFailure() { $this