2
votes

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.

1
Why would you want to run the tests on your production server?Bogdan
Its for this API only, I need to show the functional tests that are running to the people I'll demonstrate.OguzGelal

1 Answers

3
votes

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?