File: D:/HostingSpaces/farmfun/reserveren.farmfun.be/app/Komma/Kms/ArtisanCommands/RunTests.php
<?php
namespace App\Komma\Kms\ArtisanCommands;
use App\Komma\Kms\QualityAssurance\TestsController;
use Illuminate\Console\Command;
class RunTests extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'kms:test
{flavor? : phpunit, dusk. runs all if omitted} (PHP Bench is currently not supported anymore.)}
{--filter= : Filter which tests to run. (see phpunit manual)}
{--group= : Only runs tests from the specified group(s). (see phpunit manual)}
{--noprep : add when you don\'t want to prepare the environment}
';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Runs phpunit, dusk tests and phpbench. For kms, and the site.';
/**
* @var TestsController
*/
protected $testsController;
/**
* Create a new command instance.
*/
public function __construct()
{
$this->testsController = app(TestsController::class);
parent::__construct();
}
/**
* Execute the console command.
*
* @return int The exit code
*/
public function handle()
{
$flavor = $this->argument('flavor');
$noprep = $this->option('noprep');
if (\App::environment() !== 'testing') {
$this->output->error('Testing cannot be started for dusk tests. Make sure you run the tests using the test environment. E.g. suffix this command with --env=testing');
return 1;
}
echo 'flavor: '.$flavor.PHP_EOL;
echo 'environment: '.\App::environment().PHP_EOL;
echo 'using database: '.config('database.connections.mysql.database').PHP_EOL;
echo PHP_EOL;
if (! $noprep) {
$this->testsController->prepareEnvironment();
}
return $this->runTests($flavor);
}
/**
* @param string $type
* @param null $flavor
* @return int|string The exit code of the commands that where run.
*/
protected function runTests($flavor = null, $type = 'kms')
{
$exitCode = 0;
switch ($flavor) {
case 'unit':
case 'phpunit':
$exitCode = $this->testsController->phpunit($type);
break;
case 'browser':
case 'dusk':
$exitCode = $this->testsController->dusk($type);
break;
case 'benchmark':
case 'bench':
case 'phpbench':
echo 'PHPBench currently isn\'t supported since it is dependant on an old version of phpunit'.PHP_EOL;
// $exitCode = $this->testsController->phpbench($type);
break;
default:
$exitCodeUnit = $this->testsController->phpunit($type);
$exitCodeDusk = $this->testsController->dusk($type);
$exitCode = ($exitCodeUnit == 0 && $exitCodeDusk == 0) ? 0 : 1;
// $this->testsController->phpbench($type);
}
return $exitCode;
}
}