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 show previous exception #5863

Open
donquixote opened this issue Jun 12, 2024 · 0 comments
Open

TestDox printer does not show previous exception #5863

donquixote opened this issue Jun 12, 2024 · 0 comments
Labels
feature/testdox The TextDox printer/formatter type/bug Something is broken

Comments

@donquixote
Copy link

Q A
PHPUnit version 11.2.1
PHP version 8.2.15
Installation Method Composer

Summary

phpunit --testdox does not show previous exception.

Current behavior

(good) Output for phpunit ExampleTest.php without --testdox shows outer and inner exception.
(bad) Output for phpunit --testdox ExampleTest.php shows outer exception, but not the inner (previous) exception.

~/projects/phplib/phpunit-test $ ./vendor/bin/phpunit --testdox ExampleTest.php 
PHPUnit 11.2.1 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.15

E                                                                   1 / 1 (100%)

Time: 00:00.008, Memory: 4.00 MB

Example
 ✘ Foo
   │
   │ Exception: Outer
   │
   │ /home/lemonhead/projects/phplib/phpunit-test/ExampleTest.php:10
   │

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

How to reproduce

mkdir testdir
cd testdir
composer require phpunit/phpunit
nano ExampleTest.php

Put the following php code:

<?php

declare(strict_types=1);

use PHPUnit\Framework\TestCase;

class ExampleTest extends TestCase {

  public function testFoo() {
    throw new \Exception('Outer', previous: new \Exception('Inner'));
  }

}

Run these commands:

./vendor/bin/phpunit ExampleTest.php
./vendor/bin/phpunit --testdox ExampleTest.php

Expected behavior

Output for both commands contains "Exception: Outer" and "Exception: Inner".

Related issues

There are other issues and PRs that deal with showing previous exception in different use cases.
But it seems this was not done yet for testdox.

About my use case

I personally would not mind to run the test without --testdox.
But I am currently using a tool that adds --testdox parameter by default. See https://github.com/ddev/ddev-drupal-contrib/blob/903026a2fef564b1b7b1fb54213ebb669267995b/commands/web/phpunit#L21
For the steps above I isolated the problem to a minimal project with the latest phpunit I get with composer.

@donquixote donquixote added the type/bug Something is broken label Jun 12, 2024
donquixote added a commit to donquixote/ddev-drupal-contrib that referenced this issue Jun 12, 2024
The `--testdox` parameter replaces the printer we previously set with `--printer`.

This causes the following problems:
- The previous exception is not shown, see sebastianbergmann/phpunit#5863
- The "HTML output was generated" message from Drupal is not shown.

By removing the argument we fall back to the Drupal output printer. A developer can still manually append --testdox when running `ddev phpunit`.
@sebastianbergmann sebastianbergmann added the feature/testdox The TextDox printer/formatter label Jun 13, 2024
weitzman pushed a commit to ddev/ddev-drupal-contrib that referenced this issue Jun 13, 2024
The `--testdox` parameter replaces the printer we previously set with `--printer`.

This causes the following problems:
- The previous exception is not shown, see sebastianbergmann/phpunit#5863
- The "HTML output was generated" message from Drupal is not shown.

By removing the argument we fall back to the Drupal output printer. A developer can still manually append --testdox when running `ddev phpunit`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/testdox The TextDox printer/formatter type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants