Robust unit-testing of HTML in PHP
Posted
by asbja
on Stack Overflow
See other posts from Stack Overflow
or by asbja
Published on 2010-04-28T23:25:59Z
Indexed on
2010/04/29
2:47 UTC
Read the original article
Hit count: 357
I'm adding unit-tests to an older PHP codebase at work. I will be testing and then rewriting a lot of HTML generation code and currently I'm just testing if the generated strings are identical to the expected string, like so: (using PHPUnit)
public function testConntype_select() {
$this->assertEquals(
'<select><option value="blabla">Some text</option></select>',
conntype_select(1); // A value from the test dataset.
);
}
This way has the downside that attribute ordering, whitespace and a lot of other irrelevant details are tested as well. I'm wondering if there are any better ways to do this. For example if there are any good and easy ways to compare the generated DOM trees. I found very similar questions for ruby, but couldn't find anything for PHP.
© Stack Overflow or respective owner