Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 单元测试Smarty模板_Php_Unit Testing_Testing_Smarty - Fatal编程技术网

Php 单元测试Smarty模板

Php 单元测试Smarty模板,php,unit-testing,testing,smarty,Php,Unit Testing,Testing,Smarty,我使用Smarty模板,我只是想知道它是否有任何类型的测试机制。不同模板文件的数量在增加,复杂性也在增加。理想情况下,我希望测试最终的输出HTML,以确保Smarty中使用的模板/条件/变量按预期工作。有办法吗?您可以使用Smarty的功能。下面是一个松散的示例/伪代码 要测试的模板 {* foo.tpl *} <html> <head></head> <body>{$hi}</body> </html>

我使用Smarty模板,我只是想知道它是否有任何类型的测试机制。不同模板文件的数量在增加,复杂性也在增加。理想情况下,我希望测试最终的输出HTML,以确保Smarty中使用的模板/条件/变量按预期工作。有办法吗?

您可以使用Smarty的功能。下面是一个松散的示例/伪代码

要测试的模板

{* foo.tpl *}
<html>
    <head></head>
    <body>{$hi}</body>
</html>

这个问题并不是关于smarty的,而是关于程序输出测试的。如果输出符合要求,则执行控制器操作和测试(使用您喜欢的任何工具)。
<!-- foo.html -->
<html>
    <head></head>
    <body>Hello World!</body>
</html>
class FooTemplateTestCase extends TestCase {

    protected $_view;

    public function setup(){
        $this->_view = new Smarty();
        // setup smarty options, caching, etc
    }

    public function test(){
        $this->_view->assign('hi', 'Hello World!');

        $output = $this->_view->fetch('foo.tpl');
        $expected_output = file_get_contents('foo.html');

        $this->assertEquals($expected_output, $output);
    }

}