From ae532837f1ef1b629b2e996c569207e422549c4f Mon Sep 17 00:00:00 2001 From: Vincent Wong Date: Tue, 31 Dec 2024 01:17:27 +0800 Subject: [PATCH] Handle missing LARAVEL_START during test cases --- src/AsyncTask.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/AsyncTask.php b/src/AsyncTask.php index c3e130c..f7b0963 100644 --- a/src/AsyncTask.php +++ b/src/AsyncTask.php @@ -83,7 +83,7 @@ public function run(): void { // todo startup configs // write down the LARAVEL_START constant value for future usage - $this->laravelStartVal = constant("LARAVEL_START"); + $this->laravelStartVal = constant("LARAVEL_START") ?? null; // install a timeout detector // this single function checks all kinds of timeouts @@ -257,10 +257,13 @@ protected function checkTaskTimeout(): void // external killing; could be normal Unix timeout SIG_TERM or manual Windows taskkill // Laravel Artisan very conveniently has a LARAVEL_START = microtime(true) to let us check time elapsed - $timeElapsed = microtime(true) - $this->laravelStartVal; - if ($timeElapsed > $this->timeLimit) { - // timeout! - $hasTimedOut = true; + if ($this->laravelStartVal !== null) { + // we know when we have started; this can be null when running some test cases + $timeElapsed = microtime(true) - $this->laravelStartVal; + if ($timeElapsed > $this->timeLimit) { + // timeout! + $hasTimedOut = true; + } } // runtime timeout triggers a PHP fatal error