diff --git a/src/Console/Commander.php b/src/Console/Commander.php index f35b72d1..a5360712 100644 --- a/src/Console/Commander.php +++ b/src/Console/Commander.php @@ -4,7 +4,6 @@ use Illuminate\Console\Command; use Illuminate\Console\Concerns\InteractsWithSignals; -use Illuminate\Console\Signals; use Illuminate\Contracts\Console\Kernel as ConsoleKernel; use Illuminate\Contracts\Debug\ExceptionHandler; use Illuminate\Filesystem\Filesystem; @@ -15,6 +14,7 @@ use Orchestra\Testbench\Foundation\Bootstrap\LoadMigrationsFromArray; use Orchestra\Testbench\Foundation\Config; use Orchestra\Testbench\Foundation\Console\Concerns\CopyTestbenchFiles; +use Orchestra\Testbench\Foundation\Console\Signals; use Orchestra\Testbench\Foundation\TestbenchServiceProvider; use Orchestra\Testbench\Workbench\Workbench; use Symfony\Component\Console\Application as ConsoleApplication; @@ -253,6 +253,25 @@ protected function prepareCommandSignals(): void exit($status); }) ); + }, function () { + if (windows_os() && PHP_SAPI === 'cli' && \function_exists('sapi_windows_set_ctrl_handler')) { + sapi_windows_set_ctrl_handler(function ($event) { + $this->handleTerminatingConsole(); + Workbench::flush(); + + $status = match ($event) { + PHP_WINDOWS_EVENT_CTRL_C => 572, + PHP_WINDOWS_EVENT_CTRL_BREAK => 572, + default => 0, + }; + + if (\in_array($status, [0])) { + exit; + } + + exit($status); + }); + } }); } } diff --git a/src/Foundation/Console/Concerns/HandleTerminatingConsole.php b/src/Foundation/Console/Concerns/HandleTerminatingConsole.php index 300e02ff..7282c788 100644 --- a/src/Foundation/Console/Concerns/HandleTerminatingConsole.php +++ b/src/Foundation/Console/Concerns/HandleTerminatingConsole.php @@ -35,5 +35,7 @@ protected function handleTerminatingConsole(): void ->each(static function ($callback) { \call_user_func($callback); }); + + $this->beforeTerminatingCallbacks = []; } } diff --git a/src/Foundation/Console/ServeCommand.php b/src/Foundation/Console/ServeCommand.php index fc956b5e..f5b49b71 100644 --- a/src/Foundation/Console/ServeCommand.php +++ b/src/Foundation/Console/ServeCommand.php @@ -3,7 +3,6 @@ namespace Orchestra\Testbench\Foundation\Console; use Composer\Config as ComposerConfig; -use Illuminate\Console\Signals; use Illuminate\Foundation\Console\ServeCommand as Command; use Orchestra\Testbench\Foundation\Events\ServeCommandEnded; use Orchestra\Testbench\Foundation\Events\ServeCommandStarted; diff --git a/src/Foundation/Console/Signals.php b/src/Foundation/Console/Signals.php new file mode 100644 index 00000000..edd755eb --- /dev/null +++ b/src/Foundation/Console/Signals.php @@ -0,0 +1,27 @@ + package_path()], ))->mustRun(); $this->assertSame(json_decode($artisan->getOutput(), true), json_decode($remote->getOutput(), true)); diff --git a/tests/TestCaseTest.php b/tests/TestCaseTest.php index c704392b..410f3d56 100644 --- a/tests/TestCaseTest.php +++ b/tests/TestCaseTest.php @@ -46,6 +46,8 @@ public function it_can_create_the_testcase() $this->assertInstanceOf(TestCaseContract::class, $testbench); $this->assertTrue($testbench->isRunningTestCase()); $this->assertFalse($testbench->isRunningTestCaseUsingPest()); + + $app->terminate(); } /** @test */ @@ -65,5 +67,8 @@ public function it_can_create_a_container() $this->assertInstanceOf(ConfigRepository::class, $app['config']); $this->assertFalse($container->isRunningTestCase()); + $this->assertFalse($container->isRunningTestCaseUsingPest()); + + $app->terminate(); } }