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

PHPUnit warning: Test code or tested code did not remove its own exception handlers #49502

Closed
nunomaduro opened this issue Dec 27, 2023 · 14 comments

Comments

@nunomaduro
Copy link
Member

Laravel Version

Any that uses PHPUnit ^10

PHP Version

Any

Database Driver & Version

No response

Description

Seems that, since PHPUnit 10.5.4, running any kind of test suite that boots the Laravel Framework displays the following warning multiple times: Test code or tested code did not remove its own exception handlers.

Steps To Reproduce

laravel new laravel
cd laravel
./vendor/bin/phpunit
@nunomaduro nunomaduro changed the title [10.x] PHPUnit warning: Test code or tested code did not remove its own exception handlers PHPUnit warning: Test code or tested code did not remove its own exception handlers Dec 27, 2023
@nunomaduro
Copy link
Member Author

PHPUnit change that introduced this BC issue: sebastianbergmann/phpunit#5619.

@rikvdh
Copy link
Contributor

rikvdh commented Dec 27, 2023

@nunomaduro Shouldnt this be reported upstream as a regression?

@nunomaduro
Copy link
Member Author

@rikvdh It's done. Sebastian is considering reverting it.

@nunomaduro
Copy link
Member Author

Reverted. Problem solved.

@arderyp
Copy link

arderyp commented Mar 3, 2024

I never had this issue in 10.x, but I just upgraded from latest 10.x to latest 11.x and 11.0.4 and I'm seeing this on every single test in my project

@TomBerkGH
Copy link

I never had this issue in 10.x, but I just upgraded from latest 10.x to latest 11.x and 11.0.4 and I'm seeing this on every single test in my project

i get the same error since laravel update. PHPUnit 11.0.9 and Laravel 11.2.0

@elb98rm
Copy link

elb98rm commented Apr 7, 2024

I can confirm this has reappeared:

  • L11 : 11.2.0
  • PHPUnit : 11.1.1

Looks like it's been re-introduced.

@oceanapplications
Copy link

I can confirm this has reappeared:

  • L11 : 11.2.0
  • PHPUnit : 11.1.1

Looks like it's been re-introduced.

Yup, Sebastian said it would be reintroduced in 11. What's the current work around other than using older phpunit?

@arderyp
Copy link

arderyp commented May 1, 2024

@oceanapplications various workarounds are presented in the Symfony thread: symfony/symfony#53812 (comment)

@phily245
Copy link

phily245 commented Jul 11, 2024

Putting the below in (what would be) my Tests/TestCase worked in the package I am working on and encountered this in:

public function tearDown(): void
{
    parent::tearDown();

    restore_error_handler();
    restore_exception_handler();
}

@zoispag
Copy link

zoispag commented Sep 2, 2024

We updated to L11 last week and today Dependabot bumped PHPUnit to v11 and these errors starting to appear for all tests:

  • Test code or tested code removed error handlers other than its own
  • Test code or tested code removed exception handlers other than its own

As of now, we can't find any working solution. This issue points to Symfony thread which is still open and redirects back to #49622. Does anyone have a working solution? @phily245 suggestion didn't do the trick :(

@JustChapman
Copy link

We have been digging into this issue at work with a new project. My boss found that removing newRelic in the docker container solved resolved the "Test code or tested code removed..." errors. He also mentioned there appears to be a memory leak in PHPUnit 11.3, though that has not yet been confirmed. I can confirm on my instance, removing newRelic from the docker container did resolve issues for me. Tests execute as expected now.

@lsfiege
Copy link

lsfiege commented Sep 11, 2024

We have been digging into this issue at work with a new project. My boss found that removing newRelic in the docker container solved resolved the "Test code or tested code removed..." errors. He also mentioned there appears to be a memory leak in PHPUnit 11.3, though that has not yet been confirmed. I can confirm on my instance, removing newRelic from the docker container did resolve issues for me. Tests execute as expected now.

I also confirm, removing new relic from my docker container fixed this. But I can't confirm the phpunit memory leak

@eddyger
Copy link

eddyger commented Sep 15, 2024

Reading the phpunit documentation, we can find the #[WithoutErrorHandler] attribute mention on your test method. Using this attribute fix the "risky" message.

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

No branches or pull requests