Skip to content

Commit 13f8646

Browse files
Allow Throwable to trigger the crash
1 parent c061076 commit 13f8646

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

src/Console/Command.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
namespace CaptainHook\App\Console;
1313

1414
use CaptainHook\App\Console\Runtime\Resolver;
15-
use Exception;
1615
use Symfony\Component\Console\Command\Command as SymfonyCommand;
1716
use Symfony\Component\Console\Input\InputInterface;
1817
use Symfony\Component\Console\Output\OutputInterface;
18+
use Throwable;
1919

2020
/**
2121
* Class Command
@@ -81,21 +81,21 @@ public function getIO(InputInterface $input, OutputInterface $output): IO
8181
* Write a final error message
8282
*
8383
* @param \Symfony\Component\Console\Output\OutputInterface $out
84-
* @param \Exception $e
84+
* @param \Throwable $t
8585
* @return int
86-
* @throws \Exception
86+
* @throws \Throwable
8787
*/
88-
public function crash(OutputInterface $out, Exception $e): int
88+
public function crash(OutputInterface $out, Throwable $t): int
8989
{
9090
if ($out->isDebug()) {
91-
throw $e;
91+
throw $t;
9292
}
9393

94-
$out->writeln('<fg=red>' . $e->getMessage() . '</>');
94+
$out->writeln('<fg=red>' . $t->getMessage() . '</>');
9595
if ($out->isVerbose()) {
9696
$out->writeln(
97-
'<comment>Error triggered in file:</comment> ' . $e->getFile() .
98-
' <comment>in line:</comment> ' . $e->getLine()
97+
'<comment>Error triggered in file:</comment> ' . $t->getFile() .
98+
' <comment>in line:</comment> ' . $t->getLine()
9999
);
100100
}
101101
return 1;

src/Console/Command/Hook.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace CaptainHook\App\Console\Command;
1313

1414
use CaptainHook\App\Config;
15-
use CaptainHook\App\Console\IOUtil;
1615
use CaptainHook\App\Hook\Util;
1716
use CaptainHook\App\Runner\Bootstrap\Util as BootstrapUtil;
1817
use RuntimeException;
@@ -98,8 +97,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9897
$hook->run();
9998

10099
return 0;
101-
} catch (Throwable $e) {
102-
return $this->crash($output, $e);
100+
} catch (Throwable $t) {
101+
return $this->crash($output, $t);
103102
}
104103
}
105104

tests/unit/Console/Command/ConfigurationTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\ArrayInput;
1717
use Symfony\Component\Console\Output\NullOutput;
1818
use PHPUnit\Framework\TestCase;
19+
use Symfony\Component\Console\Output\OutputInterface;
1920

2021
class ConfigurationTest extends TestCase
2122
{
@@ -39,4 +40,26 @@ public function testExecute(): void
3940

4041
unlink($config);
4142
}
43+
44+
/**
45+
* Tests Configure::run
46+
*
47+
* @throws \Exception
48+
*/
49+
public function testConfigFailure(): void
50+
{
51+
$resolver = new Resolver();
52+
$config = '/foo/bar/fiz/baz/config.json';
53+
$input = new ArrayInput(['--configuration' => $config]);
54+
$output = $this->getMockBuilder(OutputInterface::class)
55+
->disableOriginalConstructor()
56+
->getMock();
57+
$output->method('isVerbose')->willReturn(true);
58+
59+
$configure = new Configuration($resolver);
60+
$configure->setIO(new NullIO());
61+
$code = $configure->run($input, $output);
62+
63+
$this->assertEquals(1, $code);
64+
}
4265
}

0 commit comments

Comments
 (0)