29 Sep 2011 07:26
assertIsSubset
Wojtek O <wojtek.oledzki <at> gmail.com>
2011-09-29 05:26:11 GMT
2011-09-29 05:26:11 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.
(Continue reading)
RSS Feed