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

feat: Clean-up listener/subscriber after the test #78

Merged
merged 3 commits into from
Mar 12, 2025

Conversation

michalbundyra
Copy link
Member

@michalbundyra michalbundyra commented Mar 10, 2025

Fixes #74

Now MockDisabler constructor has optional 2nd parameter callback which will be executed once the test ends.
We remove the listener (for old PHPUnit versions) and for newer - remove the subscriber. It stills heavily relies on the internals of PHPUnit and it might break at any point, but as so the whole package.

Tests are a bit tricky, basically we chain of three tests, so I do not need to register a mock function in set up.
First just register a mock and it should be clearer in tearDown;
so then, the second should have the counter === 1, as the mock has been disabled, and it should be removed at this point, so the 3rd test should remain with the same counter (=== 1) - and actually it was failing before before the 'callback' solution.

@michalbundyra
Copy link
Member Author

@mvorisek, I was able to replicate the issue, and I believe it should be resolved here.
It was a bit tricky to test it. Any feedback will be very appreciated! Thanks

@michalbundyra michalbundyra added this to the 2.12.0 milestone Mar 10, 2025
@michalbundyra michalbundyra marked this pull request as ready for review March 10, 2025 19:33
@michalbundyra michalbundyra merged commit 17f68c1 into master Mar 12, 2025
128 checks passed
@michalbundyra michalbundyra deleted the feat/clean-up-on-tear-down branch March 12, 2025 15:12
@michalbundyra
Copy link
Member Author

@mvorisek - thanks, 2.12.0 is now released.

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.

registerForTearDown must remove PHPUnit listener once disable is called
1 participant