将 Laravel phpunit 测试绑定到路由
Binding Laravel phpunit tests to routes
我正在使用 Laravel 5.1 构建 RESTful API。我使用软件包附带的默认 phpunit 编写了功能测试。我可以使用 phpunit
命令从命令行 运行 进行测试。
我想创建一个名为 /tests
的路由,并将其绑定到 phpunit 测试。因此,在我将 api 部署到服务器后,当我向 http://api.mysite.com/test
发出 GET
请求时,我应该会得到测试结果。
这可能吗?
提前致谢。
您可以这样创建路线:
Route::get('tests', array(function () {
$phpunit = new PHPUnit_TextUI_TestRunner;
try {
$test_results = $phpunit->dorun($phpunit->getTest(__DIR__, '', 'Test.php'));
} catch (PHPUnit_Framework_Exception $e) {
print $e->getMessage() . "\n";
die ("Unit tests failed.");
}
}));
摘自类似问题:Can you run PHPUnit tests from a script?
我正在使用 Laravel 5.1 构建 RESTful API。我使用软件包附带的默认 phpunit 编写了功能测试。我可以使用 phpunit
命令从命令行 运行 进行测试。
我想创建一个名为 /tests
的路由,并将其绑定到 phpunit 测试。因此,在我将 api 部署到服务器后,当我向 http://api.mysite.com/test
发出 GET
请求时,我应该会得到测试结果。
这可能吗?
提前致谢。
您可以这样创建路线:
Route::get('tests', array(function () {
$phpunit = new PHPUnit_TextUI_TestRunner;
try {
$test_results = $phpunit->dorun($phpunit->getTest(__DIR__, '', 'Test.php'));
} catch (PHPUnit_Framework_Exception $e) {
print $e->getMessage() . "\n";
die ("Unit tests failed.");
}
}));
摘自类似问题:Can you run PHPUnit tests from a script?