我正在使用 Laravel 5.1 构建 RESTful API。我使用包附带的默认 phpunit 编写了功能测试。我可以使用 phpunit
命令从命令行运行测试。
我想创建一个名为 /tests
的路由,并将其绑定(bind)到 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.");
}
}));
关于php - 将 Laravel phpunit 测试绑定(bind)到路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33063341/