- Member | 28
I tried to write some tests using Nette Tester, but when using the
Tester\DomQuery::fromHtml($html) method, weird errors appears
(something like Attribute class redefined in Entity). I tried to debug
the code and I realized that when I change the line
33 in Tester\DomQuery from
<?php $dom->loadHTML($html); ?>
<?php @$dom->loadHTML($html); ?>
errors caused by DOMDocument dissappears and my tests are able to pass. So I just wanted to ask whether there is some specific reason why not to use the @ sign in the method to suppress these errors.
Last edited by xlilien (2013-06-20 19:24)
- Nette Core | 1153
@xlilien: I guess, you have an invalid HTML code. DOMDocument method loadHTML() can deal with it, it is written for this purpose and expects an errors in HTML code. Using the @ operator is legitimate in this case, but it isn't in Tester libs. It would cover more serious problem.
If you can, fix the HTML code. Use W3C Validator to found what is wrong.
The other way is to catch errors by LibXML internal error handling:
libxml_use_internal_errors(TRUE); Tester\DomQuery::fromHtml($html); $errors = libxml_get_errors(); // or just ignore it libxml_use_internal_errors(FALSE);
but as Honza Marek wrote, it is potentional weakness.