Skip to content

Commit

Permalink
Merge branch '7.x' into 8.x
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Oct 16, 2024
2 parents 053c865 + ce3cd26 commit 7a7f1a0
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/Console/Commander.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
});
}
});
}
}
2 changes: 2 additions & 0 deletions src/Foundation/Console/Concerns/HandleTerminatingConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ protected function handleTerminatingConsole(): void
->each(static function ($callback) {
\call_user_func($callback);
});

$this->beforeTerminatingCallbacks = [];
}
}
1 change: 0 additions & 1 deletion src/Foundation/Console/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 27 additions & 0 deletions src/Foundation/Console/Signals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Orchestra\Testbench\Foundation\Console;

class Signals extends \Illuminate\Console\Signals
{
/**
* Execute the given callback if "signals" should be used and are available.
*
* @param callable $callback
* @param callable|null $default
* @return void
*/
#[\Override]
public static function whenAvailable($callback, $default = null)
{
if (\is_null($resolver = static::$availabilityResolver)) {
return;
}

if ($resolver()) {
$callback();
} elseif (\is_callable($default)) {
$default();
}
}
}
1 change: 1 addition & 0 deletions tests/Integrations/ArtisanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions tests/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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();
}
}

0 comments on commit 7a7f1a0

Please sign in to comment.