Deprecations Handling Improvements with v7.16.0 (for PHPUnit 9) #97
Replies: 1 comment 12 replies
-
Just today I was investigating this (whilst preparing my package for PHP 8.4) and I'm currently super confused how things are supposed to be handled. What I (think) I know:
So recommendations like using Using this I noticed such logging produces a stacktrace on every hit, which isn't really useful (the message contains the source of the PHP deprecation trigger) but I can't turn off Maybe I'm also mixing things up, but is there a way doing things "the phpunit way" or is "enabling sideband logging during tests" the way forward with Laravel here? thanks! |
Beta Was this translation helpful? Give feedback.
-
The upcoming release will introduce Deprecation Handling Improvements and may cause your packages CI to start failing especially if you have configured
phpunit.xml
configuration withconvertDeprecationsToExceptions="true"
.In the past,
Illuminate\Foundation\Bootstrap\HandleExceptions
handles all errors includingE_DEPRECATED
andE_USER_DEPRECATED
and convert it into logs. This works great to reduce deprecation warnings during development but isn't useful for Packages development where you want to actually see the deprecation warnings/exceptions.Coming with 7.16.0, you should be able to do the following:
convertDeprecationsToExceptions="false"
Output to Spatie Ray
In order to do this, you just need to add the following environment variables to
phpunit.xml
or CI pipeline:Output deprecations logs to
stderr
You can also setup Laravel's logger to output deprecation warnings to specific logger channel such as
stderr
:Throws using Laravel's exception.
This would throws
Orchestra\Testbench\Exceptions\DeprecatedException
when you add the following environment variable:TESTBENCH_CONVERT_DEPRECATIONS_TO_EXCEPTIONS=true
convertDeprecationsToExceptions="true"
By default, all deprecation exception will throws
Orchestra\Testbench\Exceptions\DeprecatedException
instead ofPHPUnit\Framework\Error\Deprecated
. SettingTESTBENCH_CONVERT_DEPRECATIONS_TO_EXCEPTIONS
environment variable totrue
has no additional affect.Completely exclude throwing exceptions
There might be CI build where you might want to exclude throwing deprecation exceptions such as
--prefer-lowest
builds. In this cause you may add the following environment variable to the build:TESTBENCH_CONVERT_DEPRECATIONS_TO_EXCEPTIONS=false
Beta Was this translation helpful? Give feedback.
All reactions