Created
January 25, 2012 13:18
-
-
Save woledzki/1676214 to your computer and use it in GitHub Desktop.
hackish assertIsSubset
This file contains 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
<?php | |
class SimpleTest extends \PHPUnit_Framework_TestCase { | |
protected function assertIsSubset(array $expected, $actual, $selector = '') { | |
$this->assertInternalType('array', $actual); | |
foreach ($expected as $key => $value) { | |
if(is_numeric($key) && !is_array($value)) { | |
// basic mode - for when $expected is a list of elements we expect to find in $actual | |
$this->assertTrue(in_array($value, $actual), | |
"Expected element [$selector.$value] is missing"); | |
} else { | |
$this->assertTrue(array_key_exists($key, $actual), | |
"Expected key [$selector.$key] is missing"); | |
if (is_array($value)) { | |
$this->assertTrue(is_array($actual[$key]), | |
"Expecting array for key [$selector.$key]"); | |
$this->assertIsSubset($value, $actual[$key], $selector.'.'.$key); | |
} else { | |
$this->assertEquals($value, $actual[$key], | |
"Expected [$value] for key [$selector.$key] not equals to [{$actual[$key]}]"); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment