3

I have a situation where i have some unit tests with PHPUnit, and i want to trigger them from the artisan console utility of laravel. I have googled and i have not found any reference, Is it possible? I am not asking how to test artisan commands. or how to dynamically call another artisan command, but to trigger unit tests from artisan

I can call certain commands using Artisan facade like

Artisan::call('migrate'); //which calls migration

like this is there a way i can call unit tests? I am using PHPUnit

Shobi
  • 10,374
  • 6
  • 46
  • 82

2 Answers2

2

You can use symfony's process command, which drives Laravel's artisan command under the hood anyway:

use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;

$process = new Process('phpunit');
$process->run();

// executes after the command finishes
if (!$process->isSuccessful()) {
    throw new ProcessFailedException($process);
}

echo $process->getOutput();
Ohgodwhy
  • 49,779
  • 11
  • 80
  • 110
1

You can just use shell_exec() or exec():

shell_exec('/path/to/phpunit/ /path/to/tests')
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279