5

I want to format PHPUnit output like this:

1/15. ATestCaseTest ... passed (3/3), time: 0ms
  1/59. DISABLED_test1 ... skipped , time: 0ms
  2/59. test2 ... passed , time: 1497ms
  3/59. test3 ... passed , time: 593ms

2/15. AnotherTestCaseTest ... passed (2/2), time: 0ms
  4/59. Test4 ... passed , time: 49ms
  5/59. Test5 ... passed , time: 0ms
.....


  Test cases run: 15/15, tests passed: 58/59, Asserts: 100/100, Failures: 0, Exceptions: 0

"passed" will be green, skipped - orange, failed - red

the summary line will also have color coding - green if everything passed (or skipped), red if something failed

I don't find any documentation of phpunit classes. Only a quick-guide-type documentation with just few examples: https://phpunit.de/manual/4.8/en/extending-phpunit.html

I tried looking at code/comments, but it seems too much work for the simple task I need to do.

Update:

What I couldn't find is:

  1. How do I run my code after all test cases finish and how do I pass the information from the TestListener.
  2. How do I replace phpunit's out (the dots .......) with the one above. Currently my stats are output together with the dots and it looks a bit messy.
NickSoft
  • 3,215
  • 5
  • 27
  • 48
  • Does this answer your question? [PHPunit result output on the CLI not showing test names](https://stackoverflow.com/questions/25180148/phpunit-result-output-on-the-cli-not-showing-test-names) – A.L Aug 13 '20 at 14:23

1 Answers1

5

This packages is what you need.

https://github.com/sempro/phpunit-pretty-print

phpunit-pretty-print

Prettify PHPUnit output

phpunit-pretty-print

Installation

composer require sempro/phpunit-pretty-print --dev

This package requires >=7.0.0 of phpunit. If you're running on version 6, please use version 1.0.3 of this package.

Usage

You can specify the printer to use on the phpunit command line:

php vendor/bin/phpunit --printer 'Sempro\PHPUnitPrettyPrinter\PrettyPrinter' tests/

Optionally, you can add it to your project's phpunit.xml file instead:

<phpunit
    bootstrap="bootstrap.php"
    colors="true"
    printerClass="Sempro\PHPUnitPrettyPrinter\PrettyPrinter">
Suhendra
  • 91
  • 1
  • 3