Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Illuminate/Foundation/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ public function terminate($input, $status)
{
$this->app->terminate();

$this->commandStartedAt->setTimezone($this->app['config']->get('app.timezone') ?? 'UTC');

foreach ($this->commandLifecycleDurationHandlers as ['threshold' => $threshold, 'handler' => $handler]) {
$end ??= Carbon::now();

Expand Down
2 changes: 2 additions & 0 deletions src/Illuminate/Foundation/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ public function terminate($request, $response)

$this->app->terminate();

$this->requestStartedAt->setTimezone($this->app['config']->get('app.timezone') ?? 'UTC');

foreach ($this->requestLifecycleDurationHandlers as ['threshold' => $threshold, 'handler' => $handler]) {
$end ??= Carbon::now();

Expand Down
21 changes: 21 additions & 0 deletions tests/Integration/Console/CommandDurationThresholdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Carbon\CarbonInterval;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Config;
use Orchestra\Testbench\TestCase;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\ConsoleOutput;
Expand Down Expand Up @@ -177,4 +178,24 @@ public function testItClearsStartTimeAfterHandlingCommand()
$kernel->terminate($input, 21);
$this->assertNull($kernel->commandStartedAt());
}

public function testUsesTheConfiguredDateTimezone()
{
Config::set('app.timezone', 'UTC');
$startedAt = null;
$kernel = $this->app[Kernel::class];
$kernel->command('foo', fn () => null);
$kernel->whenCommandLifecycleIsLongerThan(0, function ($started) use (&$startedAt) {
$startedAt = $started;
});

Config::set('app.timezone', 'Australia/Melbourne');
Carbon::setTestNow(Carbon::now());
$kernel->handle($input = new StringInput('foo'), new ConsoleOutput);

Carbon::setTestNow(now()->addMinute());
$kernel->terminate($input, 21);

$this->assertSame('Australia/Melbourne', $startedAt->timezone->getName());
}
}
20 changes: 20 additions & 0 deletions tests/Integration/Http/RequestDurationThresholdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Route;
use Orchestra\Testbench\TestCase;

Expand Down Expand Up @@ -72,6 +73,25 @@ public function testItProvidesRequestToHandler()
$this->assertSame('http://localhost/test-route', $url);
}

public function testUsesTheConfiguredDateTimezone()
{
Config::set('app.timezone', 'UTC');
Route::get('test-route', fn () => 'ok');
$kernel = $this->app[Kernel::class];
$startedAt = null;
$kernel->whenRequestLifecycleIsLongerThan(CarbonInterval::seconds(1), function ($started) use (&$startedAt) {
$startedAt = $started;
});

Config::set('app.timezone', 'Australia/Melbourne');
Carbon::setTestNow(now()->startOfDay());
$kernel->handle($request = Request::create('http://localhost/test-route'));
Carbon::setTestNow(now()->addMinute());
$kernel->terminate($request, new Response);

$this->assertSame('Australia/Melbourne', $startedAt->timezone->getName());
}

public function testItCanExceedThresholdWhenSpecifyingDurationAsMilliseconds()
{
Route::get('test-route', fn () => 'ok');
Expand Down