我找到了解决办法。
在Japanese site 上我发现了一个有趣的想法:
首先我必须将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 运行我的测试。