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
[2.x] Deprecations / Upgrading w/o Symfony's Deprecation Helper #579
Comments
Hi @jrushlow I spent a large part of the day yesterday figuring out why the deprecations were not bubbling in PHPUnit >= 10. Another annoyance is that PHPUnit does not handle deprecations when they occur in a data provider whereas Foundry is used a lot in data providers in userland. Maybe we can emit ourself the deprecation events instead of calling This will need to dig a little bit more, as I still have no experience in recent PHPUnit versions nor in its event system, but that would be a good start! Depending on how this is feasible, we'll change the upgrade guide, in order to explain how to trigger deprecations for both systems. |
Here is how you can trigger deprecation in a test: public function testSomething()
{
$emitter = Event\Facade::emitter();
$emitter->testTriggeredDeprecation(
$this->valueObjectForEvents(),
'message',
'file',
123,
suppressed: false,
ignoredByBaseline: false,
ignoredByTest: false
);
} But this solution is not satisfying for data providers, since it needs an occurrence of a test, and data providers are now static. A workaround would be to use public static function provide(): iterable
{
$emitter = Event\Facade::emitter();
$emitter->testRunnerTriggeredDeprecation('deprecatoin message');
yield [/* ... */];
}
#[DataProvider('provide')]
public function testSomething(Factory $factory): void
{
// ...
} Resulting in the following output:
Notice that there is no Another solution would be to collect all deprecations in data providers, and only trigger them when the test is actually ran. But that sounds like a much more complex solution. |
It seems that PHPUnit will emit deprecations from dataproviders. But this will land in 11.2 |
I was just skimming through the
UPGRADE
docs to start testing the2.x
branch in an internal app I'm working on and noticed:foundry/UPGRADE-2.0.md
Line 20 in bbcef6a
It would be nice if we did not have to rely on the deprecation helper from
phpunit-bridge
as part of the upgrade process. e.g. I'm using PHPUnit 11 and the bridge is not available to me yet.I haven't looked into too deeply yet (this may not even be needed / feasible), but I'm wondering if it is possible to leverage PHPUnit 10/11's event system to trigger deprecation notices in 1.x (for those of us that are not using PHPUnit 9.x).
Thoughts?
The text was updated successfully, but these errors were encountered: