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

@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

@ticket

@ticket

@testdox

@testdox

@test

@test As an alternative to prefixing your test method names with test, you can use the @test annotation in a method's DocBlock to mark it as a test method. /** * @test */ public function initialBalanceShouldBe0() { $this->assertEquals(0, $this->ba->getBalance()); }

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

@runTestsInSeparateProcesses

@runTestsInSeparateProcesses Indicates that all tests in a test class should be run in a separate PHP process. use PHPUnit\Framework\TestCase; /** * @runTestsInSeparateProcesses */ class MyTest extends TestCase { // ... } 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 process contains globals that are not seri

@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

@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

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