简体   繁体   中英

Binding Laravel phpunit tests to routes

I'm building a RESTful API using Laravel 5.1. I wrote functional tests using the default phpunit came with the package. I'm able to run the tests from command line with phpunit command.

I want to create a route called /tests , and bind it to the phpunit tests. So after I deploy the api to the server, I should get the test results when I make a GET request to http://api.mysite.com/test .

Is that possible ?

Thanks in advance.

You can create a route like this:

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

Taken from similar question: Can you run PHPUnit tests from a script?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM