Skip to content

Commit 0b19bb8

Browse files
authored
[9.x] Include full stack trace in deprecation (#42191)
* Include full stack trace in deprecation * Fix HandleExceptionsTest Windows tests * Fix HandleExceptionsTest Windows tests * Revert the breaking change
1 parent 4d12bcf commit 0b19bb8

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

src/Illuminate/Foundation/Bootstrap/HandleExceptions.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ public function handleDeprecation($message, $file, $line)
102102
$this->ensureDeprecationLoggerIsConfigured();
103103

104104
with($logger->channel('deprecations'), function ($log) use ($message, $file, $line) {
105-
$log->warning(sprintf('%s in %s on line %s',
106-
$message, $file, $line
107-
));
105+
$log->warning((string) new ErrorException($message, 0, E_DEPRECATED, $file, $line));
108106
});
109107
}
110108

tests/Foundation/Bootstrap/HandleExceptionsTest.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Foundation\Application;
88
use Illuminate\Foundation\Bootstrap\HandleExceptions;
99
use Illuminate\Log\LogManager;
10+
use Illuminate\Support\Str;
1011
use Mockery as m;
1112
use Monolog\Handler\NullHandler;
1213
use PHPUnit\Framework\TestCase;
@@ -50,11 +51,20 @@ public function testPhpDeprecations()
5051
$this->app->instance(LogManager::class, $logger);
5152

5253
$logger->shouldReceive('channel')->with('deprecations')->andReturnSelf();
53-
$logger->shouldReceive('warning')->with(sprintf('%s in %s on line %s',
54-
'str_contains(): Passing null to parameter #2 ($needle) of type string is deprecated',
55-
'/home/user/laravel/routes/web.php',
56-
17
57-
));
54+
$logger->shouldReceive('warning')->with(
55+
m::on(fn(string $message) => (bool) preg_match(
56+
<<<REGEXP
57+
#ErrorException: str_contains\(\): Passing null to parameter \#2 \(\\\$needle\) of type string is deprecated in /home/user/laravel/routes/web\.php:17
58+
Stack trace:
59+
\#0 .*helpers.php\(.*\): Illuminate\\\\Foundation\\\\Bootstrap\\\\HandleExceptions.*
60+
\#1 .*HandleExceptions\.php\(.*\): with.*
61+
\#2 .*HandleExceptions\.php\(.*\): Illuminate\\\\Foundation\\\\Bootstrap\\\\HandleExceptions->handleDeprecation.*
62+
\#3 .*HandleExceptionsTest\.php\(.*\): Illuminate\\\\Foundation\\\\Bootstrap\\\\HandleExceptions->handleError.*
63+
[\s\S]*#i
64+
REGEXP,
65+
$message
66+
))
67+
);
5868

5969
$this->handleExceptions->handleError(
6070
E_DEPRECATED,
@@ -70,11 +80,20 @@ public function testUserDeprecations()
7080
$this->app->instance(LogManager::class, $logger);
7181

7282
$logger->shouldReceive('channel')->with('deprecations')->andReturnSelf();
73-
$logger->shouldReceive('warning')->with(sprintf('%s in %s on line %s',
74-
'str_contains(): Passing null to parameter #2 ($needle) of type string is deprecated',
75-
'/home/user/laravel/routes/web.php',
76-
17
77-
));
83+
$logger->shouldReceive('warning')->with(
84+
m::on(fn(string $message) => (bool) preg_match(
85+
<<<REGEXP
86+
#ErrorException: str_contains\(\): Passing null to parameter \#2 \(\\\$needle\) of type string is deprecated in /home/user/laravel/routes/web\.php:17
87+
Stack trace:
88+
\#0 .*helpers.php\(.*\): Illuminate\\\\Foundation\\\\Bootstrap\\\\HandleExceptions.*
89+
\#1 .*HandleExceptions\.php\(.*\): with.*
90+
\#2 .*HandleExceptions\.php\(.*\): Illuminate\\\\Foundation\\\\Bootstrap\\\\HandleExceptions->handleDeprecation.*
91+
\#3 .*HandleExceptionsTest\.php\(.*\): Illuminate\\\\Foundation\\\\Bootstrap\\\\HandleExceptions->handleError.*
92+
[\s\S]*#i
93+
REGEXP,
94+
$message
95+
))
96+
);
7897

7998
$this->handleExceptions->handleError(
8099
E_USER_DEPRECATED,

0 commit comments

Comments
 (0)