簡體   English   中英

將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.");
    }
}));

來自類似的問題: 您可以從腳本運行PHPUnit測試嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM