Skip to content

Commit 2aae51c

Browse files
authored
[10.x] Ensure duration is present (#47596)
* Ensure duration is present * add test
1 parent fff5b0b commit 2aae51c

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

src/Illuminate/Foundation/Console/Kernel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ public function terminate($input, $status)
218218
{
219219
$this->app->terminate();
220220

221+
if ($this->commandStartedAt === null) {
222+
return;
223+
}
224+
221225
$this->commandStartedAt->setTimezone($this->app['config']->get('app.timezone') ?? 'UTC');
222226

223227
foreach ($this->commandLifecycleDurationHandlers as ['threshold' => $threshold, 'handler' => $handler]) {

src/Illuminate/Foundation/Http/Kernel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ public function terminate($request, $response)
214214

215215
$this->app->terminate();
216216

217+
if ($this->requestStartedAt === null) {
218+
return;
219+
}
220+
217221
$this->requestStartedAt->setTimezone($this->app['config']->get('app.timezone') ?? 'UTC');
218222

219223
foreach ($this->requestLifecycleDurationHandlers as ['threshold' => $threshold, 'handler' => $handler]) {

tests/Integration/Console/CommandDurationThresholdTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,12 @@ public function testUsesTheConfiguredDateTimezone()
198198

199199
$this->assertSame('Australia/Melbourne', $startedAt->timezone->getName());
200200
}
201+
202+
public function testItHandlesCallingTerminateWithoutHandle()
203+
{
204+
$this->app[Kernel::class]->terminate(new StringInput('foo'), 21);
205+
206+
// this is a placeholder just to show that the above did not throw an exception.
207+
$this->assertTrue(true);
208+
}
201209
}

tests/Integration/Http/RequestDurationThresholdTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,12 @@ public function testItClearsStartTimeAfterHandlingRequest()
186186
$kernel->terminate($request, $response);
187187
$this->assertNull($kernel->requestStartedAt());
188188
}
189+
190+
public function testItHandlesCallingTerminateWithoutHandle()
191+
{
192+
$this->app[Kernel::class]->terminate(Request::create('http://localhost/test-route'), new Response);
193+
194+
// this is a placeholder just to show that the above did not throw an exception.
195+
$this->assertTrue(true);
196+
}
189197
}

0 commit comments

Comments
 (0)