From 9b63e033a284e56ec100f97e90d71ea15a5f6b5f Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 11 Oct 2024 20:17:37 +0800 Subject: [PATCH 1/3] wip Signed-off-by: Mior Muhammad Zaki --- src/Foundation/Console/Concerns/HandleTerminatingConsole.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Foundation/Console/Concerns/HandleTerminatingConsole.php b/src/Foundation/Console/Concerns/HandleTerminatingConsole.php index 300e02ff0..7282c7886 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 = []; } } From 2c5c6844ef08d6ac323f5aa59508da35261cadf6 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 11 Oct 2024 20:32:49 +0800 Subject: [PATCH 2/3] wip Signed-off-by: Mior Muhammad Zaki --- tests/Integrations/ArtisanTest.php | 1 + tests/TestCaseTest.php | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/tests/Integrations/ArtisanTest.php b/tests/Integrations/ArtisanTest.php index 265c6c275..5b0be9fb3 100644 --- a/tests/Integrations/ArtisanTest.php +++ b/tests/Integrations/ArtisanTest.php @@ -25,6 +25,7 @@ public function it_can_generate_the_same_output() $artisan = (new Process( command: [$phpBinary, 'artisan', '--version', '--no-ansi'], cwd: package_path('laravel'), + env: ['TESTBENCH_WORKING_PATH' => 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 d7f548ba8..ac3d12c56 100644 --- a/tests/TestCaseTest.php +++ b/tests/TestCaseTest.php @@ -31,6 +31,8 @@ public function it_can_create_the_testcase() $this->assertInstanceOf(TestCaseContract::class, $testbench); $this->assertTrue($testbench->isRunningTestCase()); + + $app->terminate(); } /** @test */ @@ -50,5 +52,7 @@ public function it_can_create_a_container() $this->assertInstanceOf(ConfigRepository::class, $app['config']); $this->assertFalse($container->isRunningTestCase()); + + $app->terminate(); } } From ce3cd266111c0811b9d0d08ce8bcd25a18187849 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Wed, 16 Oct 2024 10:13:53 +0800 Subject: [PATCH 3/3] [7.x] Improves `CTRL+C` and `CTRL+BREAK` supports on Windows without `pcntl` extensions (#245) * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki --------- Signed-off-by: Mior Muhammad Zaki --- src/Console/Commander.php | 21 ++++++++++++++++++- src/Foundation/Console/ServeCommand.php | 1 - src/Foundation/Console/Signals.php | 27 +++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/Foundation/Console/Signals.php diff --git a/src/Console/Commander.php b/src/Console/Commander.php index e0451b4b4..bfbcaea82 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; @@ -252,6 +252,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/ServeCommand.php b/src/Foundation/Console/ServeCommand.php index 6f20f09ba..428c4be22 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 000000000..edd755eb5 --- /dev/null +++ b/src/Foundation/Console/Signals.php @@ -0,0 +1,27 @@ +