Skip to content
This repository
Browse code

- Merge [4643].

  • Loading branch information...
commit 8d52382e98a76771b86a252d3cc68ee5441df8a2 1 parent 58a934e
Sebastian Bergmann authored

Showing 2 changed files with 11 additions and 26 deletions. Show diff stats Hide diff stats

  1. +0 14 PHPUnit/Tests/Util/XMLTest.php
  2. +11 12 PHPUnit/Util/XML.php
14 PHPUnit/Tests/Util/XMLTest.php
@@ -136,20 +136,6 @@ public function testAssertValidKeysInvalidKeys()
136 136 }
137 137 }
138 138
139   - public function testAssertValidKeysThrowsExceptionWhenTypeIsNotArray()
140   - {
141   - foreach (array(NULL, 'foo', 42) as $bad) {
142   - try {
143   - PHPUnit_Util_XML::assertValidKeys($bad, array());
144   - $this->fail();
145   - }
146   -
147   - catch (InvalidArgumentException $e) {
148   - $this->assertRegExp('/expected array/i', $e->getMessage());
149   - }
150   - }
151   - }
152   -
153 139 public function testConvertAssertSelect()
154 140 {
155 141 $selector = 'div#folder.open a[href="http://www.xerox.com"][title="xerox"].selected.big > span';
23 PHPUnit/Util/XML.php
@@ -287,38 +287,37 @@ public static function xmlToVariable(DOMElement $element)
287 287 * @param array $hash
288 288 * @param array $validKeys
289 289 * @return array
  290 + * @throws InvalidArgumentException
290 291 * @since Method available since Release 3.3.0
291 292 * @author Mike Naberezny <mike@maintainable.com>
292 293 * @author Derek DeVries <derek@maintainable.com>
293 294 */
294   - public static function assertValidKeys($hash, $validKeys)
  295 + public static function assertValidKeys(array $hash, array $validKeys)
295 296 {
296   - // $hash must be an array
297   - if ( !is_array($hash)) {
298   - throw new InvalidArgumentException(
299   - 'Expected array, got ' . gettype($hash)
300   - );
301   - }
  297 + $valids = array();
302 298
303   - // normalize validation keys so that we can use both key/associative arrays
  299 + // Normalize validation keys so that we can use both indexed and
  300 + // associative arrays.
304 301 foreach ($validKeys as $key => $val) {
305 302 is_int($key) ? $valids[$val] = NULL : $valids[$key] = $val;
306 303 }
307 304
308   - // check for invalid keys
  305 + $validKeys = array_keys($valids);
  306 +
  307 + // Check for invalid keys.
309 308 foreach ($hash as $key => $value) {
310   - if (!in_array($key, array_keys($valids))) {
  309 + if (!in_array($key, $validKeys)) {
311 310 $unknown[] = $key;
312 311 }
313 312 }
314 313
315 314 if (!empty($unknown)) {
316 315 throw new InvalidArgumentException(
317   - 'Unknown key(s): '.implode(', ', $unknown)
  316 + 'Unknown key(s): ' . implode(', ', $unknown)
318 317 );
319 318 }
320 319
321   - // add default values for any valid keys that are empty
  320 + // Add default values for any valid keys that are empty.
322 321 foreach ($valids as $key => $value) {
323 322 if (!isset($hash[$key])) {
324 323 $hash[$key] = $value;

0 comments on commit 8d52382

Please sign in to comment.
Something went wrong with that request. Please try again.