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

What has happened to method setOutputCallback? #5319

Closed
oleibman opened this issue Apr 12, 2023 · 4 comments
Closed

What has happened to method setOutputCallback? #5319

oleibman opened this issue Apr 12, 2023 · 4 comments
Labels
type/backward-compatibility Something will be/is intentionally broken

Comments

@oleibman
Copy link

Q A
PHPUnit version 9.6.6 (success) 10.* (failure)
PHP version 8.1.17
Installation Method Composer

Summary

Tests using setOutputCallback to suppress output succeed with PhpUnit 9.6.6 and below. The same test errors out with PhpUnit 10 (method does not exist). I do not see any mention of this in the change log, and have no idea how to get the equivalent functionality in the new version.

Current behavior

Error (method setOutputCallback does not exist) for PhpUnit10.

How to reproduce

Any test that uses setOutputCallback.

Expected behavior

Method setOutputCallback should exist. Failing that, if the functionality has migrated to some different method, what is that method? Failing that as well, is there some other way to get the same functionality?

@oleibman oleibman added type/bug Something is broken version/10 Something affects PHPUnit 10 labels Apr 12, 2023
@sebastianbergmann
Copy link
Owner

TestCase::setOutputCallback() is marked as @internal in both PHPUnit 8.5 and PHPUnit 9.6. This means that this method is not covered by the backward compatibility promise for PHPUnit and should not be used.

TestCase::setOutputCallback() has been removed in PHPUnit 10 and there is no replacement for it.

@sebastianbergmann sebastianbergmann added type/backward-compatibility Something will be/is intentionally broken and removed type/bug Something is broken version/10 Something affects PHPUnit 10 labels Apr 12, 2023
@kachaj7
Copy link

kachaj7 commented Apr 27, 2023

Missing answer for second question inside Exptected behavior.

I have came to same Problem.

My fix is to use method expectOutputRegex and write test with text from echo.

@oleibman
Copy link
Author

Thanks for the suggestion. I used ob_start and ob_end_clean as a replacement in my test.

@jrfnl
Copy link
Contributor

jrfnl commented Jun 11, 2023

Came here to ask the same.

TestCase::setOutputCallback() is marked as @internal in both PHPUnit 8.5 and PHPUnit 9.6. This means that this method is not covered by the backward compatibility promise for PHPUnit and should not be used.

If that was the case, then why was the method explicitly mentioned in the PHPUnit manual as a method in the public API ?
https://docs.phpunit.de/en/9.6/writing-tests-for-phpunit.html#testing-output

The fact that it was marked as @internal in the code seems to be an error if the method was also publicized as being in the public API in the manual.

This really feels like it should have gotten a deprecation notice and deprecation period, as well as a changelog entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/backward-compatibility Something will be/is intentionally broken
Projects
None yet
Development

No branches or pull requests

4 participants