PHPUnit_Framework_Assert::assertArrayHasKey PHP Method

assertArrayHasKey() public static method

Asserts that an array has a specified key.
public static assertArrayHasKey ( mixed $key, array | ArrayAccess $array, string $message = '' )
$key mixed
$array array | ArrayAccess
$message string
    public static function assertArrayHasKey($key, $array, $message = '')
    {
        if (!(is_integer($key) || is_string($key))) {
            throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer or string');
        }
        if (!(is_array($array) || $array instanceof ArrayAccess)) {
            throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'array or ArrayAccess');
        }
        $constraint = new PHPUnit_Framework_Constraint_ArrayHasKey($key);
        static::assertThat($array, $constraint, $message);
    }

Usage Example

Example #1
1
 /**
  * @param string $property
  * @param string $format
  *
  * @return mixed[]
  */
 private function decodeByProperty($property, $format)
 {
     return array_map(function ($entry) use($property) {
         \PHPUnit_Framework_Assert::assertInternalType('array', $entry);
         \PHPUnit_Framework_Assert::assertArrayHasKey($property, $entry);
         return $entry[$property];
     }, $this->decode($format));
 }
All Usage Examples Of PHPUnit_Framework_Assert::assertArrayHasKey
PHPUnit_Framework_Assert