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(
'',
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.
Look at Zend_Test_PHPUnit. Here you may query the DOM using:
看看Zend_Test_PHPUnit。在这里您可以使用以下方式查询DOM:
assertQuery() or assertXpath();
assertQuery()或assertXpath();
#2
0
I'm dealing with the same issues. LOL! What I think I'm going to do is use the DOMDocument at some point. But for now all I'm doing is writing coverage tests, which is what your doing. Here is one of my tests. The same as yours: