Search code examples
laravelphpunittdd

run phpunit's tests within a cron job scheduler in laravel


i've searched google for a solution to run my tests (unit and feature) in laravel kernel.php , using scheduler. but i got no chance , can anyone please make a suggestion on this situation ? scenario: run my tests in tests/ directory every day at 00:00 like:

 $schedule->call(function(){$this->runAllMyTests($please);})->dailyAt('00:00');


or (i know its like a joke but wishful to do like this ):

$schedule->call(function () {
   Artisan::call('./vendor/bin/phpunit --filter SubmitOrdetTest');
})->dailyAt('00:00');

the final purpose is to run tests every night and make a report of failed or successful tests so can send a report mail to someone , any suggestion would be pleasure .


Solution

  • PHPUnit is not an artisan command, but a php script and need to be executed from the command line or any other means.

    use Scheduling Shell Commands

    $schedule->exec('./vendor/bin/phpunit')->dailyAt('00:00');