28 Sep 2011 20:16
assertIsSubset
Wojtek Oledzki <wojtek.oledzki <at> hoborglabs.com>
2011-09-28 18:16:10 GMT
2011-09-28 18:16:10 GMT
Hi chaps,
I've just forked phpunit and added new assert for checking if a
$expected value is a subset of $actual.
Works with objects and arrays.
Make sense if you want to test you code but don't want to write 10
lines of assertEquals for individual fields.
example usage
{{{
$expected = array(
'id' => 7,
'nodes' => array(
array('id' => 3),
array('id' => 12),
)
);
$actual = $myAPI->myCall();
$this->assertIsSubset($expected, $actual);
}}}
Whole idea is that your API might change over time (new fields in
response, ...) but this particular test doesn't care about whole
response. It's just checking if $actual variable meets the minimum
requirements.
What do you think? Can you see it useful?
I would love to hear some feedback.
Cheers,
W
--
Wojtek Oledzki
hoborglabs.com
RSS Feed