From 1935601cc7fadbd22b092db5a07f7eef0a6103d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Dufraisse?= Date: Mon, 20 Mar 2023 09:29:13 +0100 Subject: [PATCH] fix(test/comand): try to display error message from phpunit --- src/commands/Command.php | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/commands/Command.php b/src/commands/Command.php index 5b0fd9f..94a3d66 100644 --- a/src/commands/Command.php +++ b/src/commands/Command.php @@ -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("Commands {$def['command']} return code $code"); + return Command::FAILURE; + } + } catch (Throwable $th){ + $output->writeln("Something went wrong ({$th->getMessage()} - code :{$th->getCode()} )"); + $output->writeln("In file {$th->getFile()}(line {$th->getLine()})"); + 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('phpunit not installed !'); }