1111 */
1212namespace HyperfTest \Command ;
1313
14+ use Hyperf \Utils \Reflection \ClassInvoker ;
1415use HyperfTest \Command \Command \DefaultSwooleFlagsCommand ;
16+ use HyperfTest \Command \Command \FooCommand ;
17+ use HyperfTest \Command \Command \FooExceptionCommand ;
18+ use HyperfTest \Command \Command \FooExitCommand ;
1519use HyperfTest \Command \Command \SwooleFlagsCommand ;
20+ use Mockery ;
1621use PHPUnit \Framework \TestCase ;
22+ use Symfony \Component \Console \Input \InputInterface ;
23+ use Symfony \Component \Console \Output \OutputInterface ;
1724
1825/**
1926 * @internal
2027 * @coversNothing
2128 */
2229class CommandTest extends TestCase
2330{
31+ protected function tearDown (): void
32+ {
33+ Mockery::close ();
34+ }
35+
2436 public function testHookFlags ()
2537 {
2638 $ command = new DefaultSwooleFlagsCommand ('test:demo ' );
@@ -29,4 +41,32 @@ public function testHookFlags()
2941 $ command = new SwooleFlagsCommand ('test:demo2 ' );
3042 $ this ->assertSame (SWOOLE_HOOK_ALL | SWOOLE_HOOK_CURL , $ command ->getHookFlags ());
3143 }
44+
45+ /**
46+ * @group NonCoroutine
47+ */
48+ public function testExitCodeWhenThrowException ()
49+ {
50+ /** @var FooExceptionCommand $command */
51+ $ command = new ClassInvoker (new FooExceptionCommand ());
52+ $ input = Mockery::mock (InputInterface::class);
53+ $ input ->shouldReceive ('getOption ' )->andReturnFalse ();
54+ $ exitCode = $ command ->execute ($ input , Mockery::mock (OutputInterface::class));
55+ $ this ->assertSame (99 , $ exitCode );
56+
57+ /** @var FooExitCommand $command */
58+ $ command = new ClassInvoker (new FooExitCommand ());
59+ $ exitCode = $ command ->execute ($ input , Mockery::mock (OutputInterface::class));
60+ $ this ->assertSame (11 , $ exitCode );
61+
62+ /** @var FooCommand $command */
63+ $ command = new ClassInvoker (new FooCommand ());
64+ $ exitCode = $ command ->execute ($ input , Mockery::mock (OutputInterface::class));
65+ $ this ->assertSame (0 , $ exitCode );
66+ }
67+
68+ public function testExitCodeWhenThrowExceptionInCoroutine ()
69+ {
70+ $ this ->testExitCodeWhenThrowException ();
71+ }
3272}
0 commit comments