Permalink
Browse files

- Merge [4643].

  • Loading branch information...
1 parent 58a934e commit 8d52382e98a76771b86a252d3cc68ee5441df8a2 @sebastianbergmann committed Feb 17, 2009
Showing with 11 additions and 26 deletions.
  1. +0 −14 PHPUnit/Tests/Util/XMLTest.php
  2. +11 −12 PHPUnit/Util/XML.php
View
14 PHPUnit/Tests/Util/XMLTest.php
@@ -136,20 +136,6 @@ public function testAssertValidKeysInvalidKeys()
}
}
- public function testAssertValidKeysThrowsExceptionWhenTypeIsNotArray()
- {
- foreach (array(NULL, 'foo', 42) as $bad) {
- try {
- PHPUnit_Util_XML::assertValidKeys($bad, array());
- $this->fail();
- }
-
- catch (InvalidArgumentException $e) {
- $this->assertRegExp('/expected array/i', $e->getMessage());
- }
- }
- }
-
public function testConvertAssertSelect()
{
$selector = 'div#folder.open a[href="http://www.xerox.com"][title="xerox"].selected.big > span';
View
23 PHPUnit/Util/XML.php
@@ -287,38 +287,37 @@ public static function xmlToVariable(DOMElement $element)
* @param array $hash
* @param array $validKeys
* @return array
+ * @throws InvalidArgumentException
* @since Method available since Release 3.3.0
* @author Mike Naberezny <mike@maintainable.com>
* @author Derek DeVries <derek@maintainable.com>
*/
- public static function assertValidKeys($hash, $validKeys)
+ public static function assertValidKeys(array $hash, array $validKeys)
{
- // $hash must be an array
- if ( !is_array($hash)) {
- throw new InvalidArgumentException(
- 'Expected array, got ' . gettype($hash)
- );
- }
+ $valids = array();
- // normalize validation keys so that we can use both key/associative arrays
+ // 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;
}
- // check for invalid keys
+ $validKeys = array_keys($valids);
+
+ // Check for invalid keys.
foreach ($hash as $key => $value) {
- if (!in_array($key, array_keys($valids))) {
+ if (!in_array($key, $validKeys)) {
$unknown[] = $key;
}
}
if (!empty($unknown)) {
throw new InvalidArgumentException(
- 'Unknown key(s): '.implode(', ', $unknown)
+ 'Unknown key(s): ' . implode(', ', $unknown)
);
}
- // add default values for any valid keys that are empty
+ // Add default values for any valid keys that are empty.
foreach ($valids as $key => $value) {
if (!isset($hash[$key])) {
$hash[$key] = $value;

0 comments on commit 8d52382

Please sign in to comment.