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

[8.x] Catch suppressed deprecation logs #40942

Merged
merged 2 commits into from Feb 10, 2022

Conversation

nunomaduro
Copy link
Member

This pull requests closes #40854 by making Laravel's deprecation handler catch suppressed deprecations.

The motivation behind this pull request is the way Symfony manages deprecations, as they use the @ operator like so:

@trigger_error('idn_to_utf8(): INTL_IDNA_VARIANT_2003 is deprecated', \E_USER_DEPRECATED);

@taylorotwell taylorotwell merged commit c48540d into 8.x Feb 10, 2022
@taylorotwell taylorotwell deleted the feat/catch-suppressed-deprecation-logs branch February 10, 2022 19:50
@madpilot78
Copy link

I'm seeing a problem with this approach. Since it uses the Log facade, now it makes mocking that much less useful, since I have to expect various calls to it due to the framework trying to use the Log APIs.

For example I get tests using Log::shouldReceive('warning')->times(2); with:

Mockery\Exception\BadMethodCallException: Received Mockery_2_Illuminate_Log_LogManager::error(), but no expectations were specified

Investigating this it has multiple calls failing and being catched. First one is actually this:

Received Mockery_2_Illuminate_Log_LogManager::channel(), but no expectations were specified

from

with($logger->channel('deprecations'), function ($log) use ($message, $file, $line) {

Not sure if I'm missing some basic way to fix the problem without having to rewrite a lot of tests.

Any suggestions?

@madpilot78
Copy link

madpilot78 commented Feb 16, 2022

For information, at present I found a workaround by overriding the symfony trigger_deprecation() function in the autoloader before everything else. Quite horrible, but makes things work since I don't have time right now to properly address this.

I'll try to file a but report or pull request for this as soon as I have a good idea on the best way to address it.
Right now my best idea is to wrap the handleDeprecation() call in a conditional checking a configuration variable or env variable, to allow opting out of it, restoring old behavior if wanted. Or maybe it should even be "opt-in".

@nunomaduro
Copy link
Member Author

@madpilot78 The #41057 pull request should address your issue.

@madpilot78
Copy link

@nunomaduro It looks to be exactly what I was looking for, thanks!

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

Successfully merging this pull request may close these issues.

None yet

3 participants