Using PHPUnit to run tests, I'd love to have code coverage metrics for my Smarty templates.
Unfortunately this doesn't work out of the box, because Smarty compiles the templates into .php
files, so that the templates itself do not have coverage information. Looking at the compiled .php
file coverage is not nice since the compiled files are near to unreadable.
What can I do to get the original template code annotated with coverage information?
I'd like to have a tool 开发者_JS百科that integrates with PHPUnit's PHP_CodeCoverage, since I could see the coverage in its generated HTML files then. But any other solution will also suffice :)
In essence, you are using a "new" programming language (templates) for which you don't have a coverage tool. You've observed that you want coverage data on the templates, and yes, that has to get through to the compiled PHP files so you can run/test and get coverage data.
I don't know about ad hoc solutions, but a general solution for any language is outlined here:
Branch Coverage for Arbitrary Languages Made Easy.
My company builds a family of test coverage tools based on this idea. These tools interoperate; if you collect test coverage data from a mixed system of Java with (JNI-enabled calls on ) C code, using the Java and C test coverage tools, they can display the coverage of both the Java and C code together, sensibly, as well as provide coverage data statistics.
There's already a PHP test coverage tool in this family. If there were a Smarty-coverage tool, its output could be combined directly with that of the PHP coverage to get coverage on both PHP and Smarty templates together.
精彩评论