You are here

public static function PHPUnit_Util_XML::assertValidKeys in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Util/XML.php \PHPUnit_Util_XML::assertValidKeys()

Validate list of keys in the associative array.

@since Method available since Release 3.3.0

Parameters

array $hash:

array $validKeys:

Return value

array

Throws

PHPUnit_Framework_Exception

7 calls to PHPUnit_Util_XML::assertValidKeys()
PHPUnit_Util_XML::findNodes in vendor/phpunit/phpunit/src/Util/XML.php
Parse out the options from the tag using DOM object tree.
Util_XMLTest::testAssertValidKeysDefaultValuesA in vendor/phpunit/phpunit/tests/Util/XMLTest.php
Util_XMLTest::testAssertValidKeysDefaultValuesB in vendor/phpunit/phpunit/tests/Util/XMLTest.php
Util_XMLTest::testAssertValidKeysInvalidKey in vendor/phpunit/phpunit/tests/Util/XMLTest.php
Util_XMLTest::testAssertValidKeysInvalidKeys in vendor/phpunit/phpunit/tests/Util/XMLTest.php

... See full list

File

vendor/phpunit/phpunit/src/Util/XML.php, line 265

Class

PHPUnit_Util_XML
XML helpers.

Code

public static function assertValidKeys(array $hash, array $validKeys) {
  $valids = array();

  // Normalize validation keys so that we can use both indexed and
  // associative arrays.
  foreach ($validKeys as $key => $val) {
    is_int($key) ? $valids[$val] = null : ($valids[$key] = $val);
  }
  $validKeys = array_keys($valids);

  // Check for invalid keys.
  foreach ($hash as $key => $value) {
    if (!in_array($key, $validKeys)) {
      $unknown[] = $key;
    }
  }
  if (!empty($unknown)) {
    throw new PHPUnit_Framework_Exception('Unknown key(s): ' . implode(', ', $unknown));
  }

  // Add default values for any valid keys that are empty.
  foreach ($valids as $key => $value) {
    if (!isset($hash[$key])) {
      $hash[$key] = $value;
    }
  }
  return $hash;
}