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']);
}
}
?>
phpunit ArrayHasKeyTest PHPUnit 5.6.0 by Sebastian Bergmann and contributors. F Time: 0 seconds, Memory: 5.00Mb There was 1 failure: 1) ArrayHasKeyTest::testFailure Failed asserting that an array has the key 'foo'. /home/sb/ArrayHasKeyTest.php:6 FAILURES! Tests: 1, Assertions: 1, Failures: 1.
Please login to continue.