Unit tests for HTML Output?

后端 未结 9 1622
无人共我
无人共我 2021-02-19 00:49

This may be a dumb question, but do you make unit tests for the HTML output of your PHP functions/scripts?

I try to keep my HTML and my PHP separate - i.e. HTML includes

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-19 01:22

    Running into this question myself. I think an approach might be to use something like phpQuery to make your tests less fragile. Instead of testing for exact output, test that there should be an h3 tag ~somewhere~ in the output. If it gets wrapped in a div later because a designer needed to tack on an extra background, or because of some ie6 float bug workaround, then your test still works.

    It's not very pure, but still potentially a very useful tool.

提交回复
热议问题