Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Ensure duration is present #47596

Merged
merged 2 commits into from
Jun 28, 2023
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
4 changes: 4 additions & 0 deletions src/Illuminate/Foundation/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ public function terminate($input, $status)
{
$this->app->terminate();

if ($this->commandStartedAt === null) {
return;
}

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

foreach ($this->commandLifecycleDurationHandlers as ['threshold' => $threshold, 'handler' => $handler]) {
Expand Down
4 changes: 4 additions & 0 deletions src/Illuminate/Foundation/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ public function terminate($request, $response)

$this->app->terminate();

if ($this->requestStartedAt === null) {
return;
}

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

foreach ($this->requestLifecycleDurationHandlers as ['threshold' => $threshold, 'handler' => $handler]) {
Expand Down
8 changes: 8 additions & 0 deletions tests/Integration/Console/CommandDurationThresholdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,12 @@ public function testUsesTheConfiguredDateTimezone()

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

public function testItHandlesCallingTerminateWithoutHandle()
{
$this->app[Kernel::class]->terminate(new StringInput('foo'), 21);

// this is a placeholder just to show that the above did not throw an exception.
$this->assertTrue(true);
}
}
8 changes: 8 additions & 0 deletions tests/Integration/Http/RequestDurationThresholdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,12 @@ public function testItClearsStartTimeAfterHandlingRequest()
$kernel->terminate($request, $response);
$this->assertNull($kernel->requestStartedAt());
}

public function testItHandlesCallingTerminateWithoutHandle()
{
$this->app[Kernel::class]->terminate(Request::create('http://localhost/test-route'), new Response);

// this is a placeholder just to show that the above did not throw an exception.
$this->assertTrue(true);
}
}