将Laravel的phpunit测试绑定到路由



我正在使用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.");
    }
}));

取自类似的问题:你能从脚本中运行PHPUnit测试吗?

最新更新