我想使用Grunt自动化CakePHP测试,并发现grunt.loadNpmTasks('grunt-phpunit');
可以自动化PHPUnit,但我确定它无法处理cake test
。
我也对cake test
从Grunt运行的解决方案感到满意,但是我对运行PHPUnit命令的方法非常感兴趣,该命令可以执行CakePHP测试。
编辑:我使用的是CakePHP的当前稳定版本,现在是2.5.4。
我找到了解决方案。
在一个日语站点上,我发现了一个有趣的主意:
首先,我必须将复制webroot/test.php
为webroot/phpunit.php
,然后替换最后一行:
--- a/webroot/test.php
+++ b/webroot/phpunit-bootstrap.php
@@ -86,4 +86,4 @@ if (Configure::read('debug') < 1) {
require_once CAKE . 'TestSuite' . DS . 'CakeTestSuiteDispatcher.php';
-CakeTestSuiteDispatcher::run();
+App::load('CakeTestSuiteCommand');
这样就可以将其用作PHPUnit的引导程序。
然后,您可以创建一个phpunit.xml
以简化测试过程。
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" stopOnFailure="false" bootstrap="webroot/phpunit-bootstrap.php">
<testsuites>
<testsuite name="AllTests">
<directory suffix=".php">Test/Case</directory>
</testsuite>
</testsuites>
</phpunit>
现在我只需要添加grunt-phpunit
配置到我的Gruntfile.js
:
phpunit: {
options: {
bin: 'phpunit',
configuration: 'phpunit.xml',
colors: true,
},
app: {
options: {
testsuite: 'AllTests',
},
},
}
现在,如果我运行grunt phpunit
,(或配置grunt watch
为phpunit
在更改后运行任务并更改文件),PHPUnit将运行测试。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句