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

TestDox printer does not display details about exceptions raised in before-test methods #5760

Closed
BladeMF opened this issue Mar 20, 2024 · 5 comments
Assignees
Labels
feature/test-runner CLI test runner feature/testdox The TextDox printer/formatter type/bug Something is broken version/10 Something affects PHPUnit 10 version/11 Something affects PHPUnit 11

Comments

@BladeMF
Copy link

BladeMF commented Mar 20, 2024

Since PHPUnit 10, exceptions that are thrown in setUp (as opposed to the actual test body) are not displayed although the test is marked as "E", forcing you to write your own try/catch and see what they are. Since setting up is part of the test I don't think why it should be treated differently. Saying there was an error but not explaining what the error was is most unhelpful.

@BladeMF BladeMF added the type/enhancement A new idea that should be implemented label Mar 20, 2024
@sebastianbergmann sebastianbergmann added type/bug Something is broken feature/test-runner CLI test runner version/10 Something affects PHPUnit 10 version/11 Something affects PHPUnit 11 and removed type/enhancement A new idea that should be implemented labels Mar 20, 2024
@sebastianbergmann
Copy link
Owner

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

@sebastianbergmann sebastianbergmann added the status/waiting-for-feedback Waiting for feedback from original reporter label Mar 20, 2024
@BladeMF
Copy link
Author

BladeMF commented Mar 20, 2024

There - https://github.com/BladeMF/phpunit-setup-exception. The interesting bit - the --testdox needs to be on.

Case 1 - A throw in the test body

command

'/var/www/test-repo2/vendor/bin/phpunit' --colors=always --filter 'test_something_with_error' --testdox --display-deprecations --display-errors '/var/www/test-repo2/tests/MyTestWithNormalThrows.php'

output

PHPUnit 11.0.6 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.13

E                                                                   1 / 1 (100%)

Time: 00:00.009, Memory: 8.00 MB

My Test With Normal Throws (Tests\MyTestWithNormalThrows)
 ✘ Something with error
   ┐
   ├ Exception: An error in the test!
   │
   │ /var/www/test-repo2/tests/MyTestWithNormalThrows.php:11
   ┴

Case 2 - A throw in the setUp method

command

'/var/www/test-repo2/vendor/bin/phpunit' --colors=always --filter 'test_something' --testdox --display-deprecations --display-errors '/var/www/test-repo2/tests/MyTestWithSetupThrows.php'

output

PHPUnit 11.0.6 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.13

E                                                                   1 / 1 (100%)

Time: 00:00.011, Memory: 8.00 MB

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

@DanteB918
Copy link

@BladeMF thank you for the testing environment! after playing around with it, I have found the issue to be with the --testdox flag. As seen in my screenshots below, without this flag, the exception is being shown.

With testdox flag

image

Without testdox flag

image

@sebastianbergmann sebastianbergmann added the feature/testdox The TextDox printer/formatter label Mar 21, 2024
@sebastianbergmann sebastianbergmann changed the title Show exceptions that occur in setUp TestDox printer does not display details about exceptions raised in before-test methods Mar 21, 2024
@sebastianbergmann sebastianbergmann self-assigned this Mar 21, 2024
@sebastianbergmann sebastianbergmann removed the status/waiting-for-feedback Waiting for feedback from original reporter label Mar 21, 2024
@sebastianbergmann
Copy link
Owner

@DanteB918 Thank you for investigating.

@sebastianbergmann sebastianbergmann changed the title TestDox printer does not display details about exceptions raised in before-test methods TestDox printer does not display details about exceptions raised in before-test methods Mar 21, 2024
sebastianbergmann added a commit that referenced this issue Mar 21, 2024
@BladeMF
Copy link
Author

BladeMF commented Mar 21, 2024

@sebastianbergmann , thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-runner CLI test runner feature/testdox The TextDox printer/formatter type/bug Something is broken version/10 Something affects PHPUnit 10 version/11 Something affects PHPUnit 11
Projects
None yet
Development

No branches or pull requests

3 participants