Skip to content

Commit f264a3e

Browse files
committed
Merge branch '9.x' into 10.x
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
2 parents 6c8071d + 36ac821 commit f264a3e

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

CHANGELOG-9.x.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
This changelog references the relevant changes (bug and security fixes) done to `orchestra/testbench-core`.
44

5+
## 9.21.0
6+
7+
Released: 2026-03-24
8+
9+
### Changes
10+
11+
* Add `TESTBENCH_USER_MODEL` environment variable when running `serve` command.
12+
* Utilise `Orchestra\Testbench\Foundation\Console\TerminatingConsole` when running `serve`.
13+
514
## 9.20.0
615

716
Released: 2026-03-18

src/Console/Commander.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ protected function prepareCommandSignals(): void
262262
(new Collection(Arr::wrap([SIGTERM, SIGINT, SIGHUP, SIGUSR1, SIGUSR2, SIGQUIT])))
263263
->each(
264264
fn ($signal) => $this->signals->register($signal, function () use ($signal) {
265-
TerminatingConsole::handle();
265+
TerminatingConsole::handle($signal);
266266
Workbench::flush();
267267

268268
$status = match ($signal) {

src/Foundation/Console/ServeCommand.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
namespace Orchestra\Testbench\Foundation\Console;
44

55
use Composer\Config as ComposerConfig;
6+
use Illuminate\Foundation\Auth\User;
67
use Illuminate\Foundation\Console\ServeCommand as Command;
78
use Orchestra\Testbench\Foundation\Events\ServeCommandEnded;
89
use Orchestra\Testbench\Foundation\Events\ServeCommandStarted;
10+
use Orchestra\Testbench\Workbench\Workbench;
911
use Symfony\Component\Console\Input\InputInterface;
1012
use Symfony\Component\Console\Output\OutputInterface;
1113
use Symfony\Component\Process\Process;
@@ -40,9 +42,8 @@ class_exists(ComposerConfig::class, false)
4042
$this->phpServerWorkers = $workers;
4143
}
4244

43-
$_ENV['TESTBENCH_WORKING_PATH'] = package_path();
44-
45-
static::$passthroughVariables[] = 'TESTBENCH_WORKING_PATH';
45+
$this->addPassThroughEnvironmentVariable('TESTBENCH_WORKING_PATH', package_path());
46+
$this->addPassThroughEnvironmentVariable('TESTBENCH_USER_MODEL', Workbench::applicationUserModel() ?? User::class);
4647

4748
event(new ServeCommandStarted($input, $output, $this->components));
4849

@@ -51,14 +52,26 @@ class_exists(ComposerConfig::class, false)
5152
});
5253
}
5354

55+
/**
56+
* Add an environment variable that should be passed through to the server process.
57+
*
58+
* @param string $name
59+
* @param mixed $value
60+
* @return void
61+
*/
62+
protected function addPassThroughEnvironmentVariable(string $name, mixed $value): void
63+
{
64+
$_ENV[$name] = $value;
65+
66+
static::$passthroughVariables[] = $name;
67+
}
68+
5469
/** {@inheritDoc} */
5570
#[\Override]
5671
protected function startProcess($hasEnvironment)
5772
{
5873
return tap(parent::startProcess($hasEnvironment), function (Process $process) {
59-
$this->untrap();
60-
61-
$this->trap(fn () => [SIGTERM, SIGINT, SIGHUP, SIGUSR1, SIGUSR2, SIGQUIT], function ($signal) use ($process) {
74+
TerminatingConsole::before(static function ($signal) use ($process) {
6275
if ($process->isRunning()) {
6376
$process->stop(10, $signal);
6477
}

src/Foundation/Console/TerminatingConsole.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ final class TerminatingConsole
1212
/**
1313
* The terminating callbacks.
1414
*
15-
* @var array<int, (callable():void)>
15+
* @var array<int, (callable(?int):void)>
1616
*/
1717
protected static array $beforeTerminatingCallbacks = [];
1818

1919
/**
2020
* Register a callback to be run before terminating the command.
2121
*
22-
* @param callable():void $callback
22+
* @param callable(?int):void $callback
2323
* @return void
2424
*/
2525
public static function before(callable $callback): void
@@ -31,7 +31,7 @@ public static function before(callable $callback): void
3131
* Register a callback to be run before terminating the command.
3232
*
3333
* @param bool $condition
34-
* @param callable():void $callback
34+
* @param callable(?int):void $callback
3535
* @return void
3636
*/
3737
public static function beforeWhen(bool $condition, callable $callback): void
@@ -44,13 +44,14 @@ public static function beforeWhen(bool $condition, callable $callback): void
4444
/**
4545
* Handle terminating console.
4646
*
47+
* @param ?int $signal
4748
* @return void
4849
*/
49-
public static function handle(): void
50+
public static function handle(?int $signal = null): void
5051
{
5152
(new Collection(self::$beforeTerminatingCallbacks))
52-
->each(static function ($callback) {
53-
\call_user_func($callback);
53+
->each(static function ($callback) use ($signal) {
54+
\call_user_func($callback, $signal);
5455
});
5556

5657
self::flush();

0 commit comments

Comments
 (0)