我想用 Grunt 自动化 CakePHP 测试,发现grunt.loadNpmTasks('grunt-phpunit');
它可以自动化 PHPUnit,但我确定它不能处理cake test
。
我对cake test
从 Grunt 运行的解决方案也很满意,但我对运行 PHPUnit 命令的方法非常感兴趣,该命令可以执行 CakePHP 测试。
编辑:我正在使用 CakePHP 的当前稳定版本,现在是 2.5.4。
我想用 Grunt 自动化 CakePHP 测试,发现grunt.loadNpmTasks('grunt-phpunit');
它可以自动化 PHPUnit,但我确定它不能处理cake test
。
我对cake test
从 Grunt 运行的解决方案也很满意,但我对运行 PHPUnit 命令的方法非常感兴趣,该命令可以执行 CakePHP 测试。
编辑:我正在使用 CakePHP 的当前稳定版本,现在是 2.5.4。
我假设 grunt-phpunit 需要一个默认的标准 phpunit 执行,如果这是真的,你不能那样运行它,你必须熟练使用这个工具。我猜它正在解析测试输出。CakePHP2 不允许您像现在使用 CakePHP 和其他库那样简单地运行“phpunit”。CakePHP2 扩展了 phpunit 测试类,所以我怀疑你是否可以在不使用 cakephp 测试外壳的情况下运行它们。
我们使用 Jenkins 和我们自己定制的脚本来自动化测试。
我找到了解决方案。
在一个日本网站上,我发现了一个有趣的想法:
首先我必须复制webroot/test.php
as 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 运行我的测试。