Created
August 19, 2012 21:12
-
-
Save ringmaster/3397748 to your computer and use it in GitHub Desktop.
Assert Associative Equality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function assert_associative_equal($value1, $value2, $message = 'Assertion failed', $output = null) | |
{ | |
$fn = function($value1, $value2) use (&$fn) { | |
foreach($value1 as $k => $v) { | |
if(is_scalar($v)) { | |
if(!is_scalar($value2[$k]) || $value2[$k] != $v) { | |
return false; | |
} | |
} | |
elseif(is_object($v)) { | |
if(!is_object($value2[$k])) { | |
return false; | |
} | |
if(!$f = $fn(get_object_vars($v), get_object_vars($value2[$k]))) { | |
return $f; | |
} | |
} | |
elseif(is_array($v)) { | |
if(!is_object($value2[$k])) { | |
return false; | |
} | |
if(!$f = $fn($v, $value2[$k])) { | |
return $f; | |
} | |
} | |
} | |
return true; | |
}; | |
$this->assert_something($fn($value1, $value2), $message, null, null, null, $output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment