Skip to content
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

Open
jrushlow opened this issue Mar 29, 2024 · 3 comments
Open

[2.x] Deprecations / Upgrading w/o Symfony's Deprecation Helper #579

jrushlow opened this issue Mar 29, 2024 · 3 comments

Comments

@jrushlow
Copy link
Contributor

I was just skimming through the UPGRADE docs to start testing the 2.x branch in an internal app I'm working on and noticed:

SYMFONY_DEPRECATIONS_HELPER="max[self]=0&max[direct]=0&quiet[]=indirect&quiet[]=other"

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?

@nikophil
Copy link
Member

nikophil commented Mar 30, 2024

Hi @jrushlow

I spent a large part of the day yesterday figuring out why the deprecations were not bubbling in PHPUnit >= 10.
There are two main problems: as you've noticed in #577, there is a whole subject around the error handler, which I kinda mitigated with this PR.

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 trigger_deprecation() when PHPUnit >= 10 is used?

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.

@nikophil
Copy link
Member

nikophil commented Mar 30, 2024

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 testRunnerTriggeredDeprecation():

    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:

.                                                                   1 / 1 (100%)

Time: 00:00.033, Memory: 10.00 MB

There was 1 PHPUnit test runner deprecation:

1) deprecation message

Notice that there is no D displayed.
I don't know if it is a valid usage of the so called "runner deprecation". All these deprecations are always displayed, disregarding the option --display-deprecations nor --filter, etc... because all data providers are always executed.

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.

@nikophil
Copy link
Member

It seems that PHPUnit will emit deprecations from dataproviders. But this will land in 11.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants