assertValidKeys() public static method

Validate list of keys in the associative array.
Author: Mike Naberezny (mike@maintainable.com)
Author: Derek DeVries (derek@maintainable.com)
public static assertValidKeys ( array $hash, array $validKeys ) : array
$hash array
$validKeys array
return array
Exemplo n.º 1
0
 public function testAssertValidKeysInvalidKeys()
 {
     $options = array('testA' => 1, 'testD' => 2, 'testE' => 3);
     $valid = array('testA', 'testB', 'testC');
     try {
         $validated = PHPUnit_Util_XML::assertValidKeys($options, $valid);
         $this->fail();
     } catch (PHPUnit_Framework_Exception $e) {
         $this->assertEquals('Unknown key(s): testD, testE', $e->getMessage());
     }
 }
Exemplo n.º 2
0
 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());
         }
     }
 }