fix(test/comand): try to display error message from phpunit
This commit is contained in:
parent
f576ad2bcb
commit
1935601cc7
@ -14,6 +14,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Command to lauch tests from command line accross all seacms dependencies
|
||||
@ -96,15 +97,38 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
default:
|
||||
// default display help
|
||||
$inputInternal = new ArrayInput([
|
||||
return $this->runApplicationSafe([
|
||||
'command' => 'help',
|
||||
'command_name' => 'seacms-test'
|
||||
]);
|
||||
(new Application())->run($inputInternal,$output);
|
||||
return Command::SUCCESS;
|
||||
],$output);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* run safe new Application
|
||||
* @param array $def
|
||||
* @param OutputInterface $output
|
||||
* @return int errorCode
|
||||
*/
|
||||
protected function runApplicationSafe(array $def, OutputInterface $output): int
|
||||
{
|
||||
$app = new Application();
|
||||
$app->setCatchExceptions(false); // force not catching exceptions
|
||||
$app->setAutoExit(false); // force not exiting
|
||||
try {
|
||||
$code = $app->run(new ArrayInput($def),$output);
|
||||
if ($code != 0 && $code != 2){
|
||||
$output->writeln("<info>Commands {$def['command']} return code $code</info>");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
} catch (Throwable $th){
|
||||
$output->writeln("<info>Something went wrong ({$th->getMessage()} - code :{$th->getCode()} )</info>");
|
||||
$output->writeln("<info>In file {$th->getFile()}(line {$th->getLine()})</infos>");
|
||||
return Command::FAILURE;
|
||||
}
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* test if phpunit available
|
||||
* @return bool
|
||||
@ -132,7 +156,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
return ($v == '--pversion') ? '--version' : $v; // hack to prevent bad caught
|
||||
},$args);
|
||||
}
|
||||
(new Application())->run(new ArrayInput($def),$output);
|
||||
return $this->runApplicationSafe($def,$output);
|
||||
} else {
|
||||
$output->writeln('<info>phpunit not installed !</info>');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user