phpunit - 如何格式化输出

Nic*_*oft 5 formatting phpunit output

我想像这样格式化 PHPUnit 输出:

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
Run Code Online (Sandbox Code Playgroud)

“通过”将为绿色,跳过 - 橙色,失败 - 红色

摘要行还将有颜色编码 - 如果一切都通过(或跳过)则为绿色,如果失败则为红色

我没有找到 phpunit 类的任何文档。只有快速指南类型的文档,只有几个示例: https: //phpunit.de/manual/4.8/en/extending-phpunit.html

我尝试查看代码/注释,但对于我需要完成的简单任务来说,这似乎太多了。

更新:

我找不到的是:

  1. 所有测试用例完成后如何运行我的代码以及如何传递来自 TestListener 的信息。
  2. 如何用上面的替换 phpunit 的输出(点.......)。目前我的统计数据与点一起输出,看起来有点混乱。

小智 5

这个包正是您所需要的。

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

phpunit 漂亮打印

美化 PHPUnit 输出

phpunit 漂亮打印

安装

composer require sempro/phpunit-pretty-print --dev
Run Code Online (Sandbox Code Playgroud)

该软件包需要 >=7.0.0 的 phpunit。如果您运行的是版本 6,请使用此软件包的版本 1.0.3。

用法

您可以在 phpunit 命令行上指定要使用的打印机:

php vendor/bin/phpunit --printer 'Sempro\PHPUnitPrettyPrinter\PrettyPrinter' tests/
Run Code Online (Sandbox Code Playgroud)

或者,您可以将其添加到项目的phpunit.xml文件中:

<phpunit
    bootstrap="bootstrap.php"
    colors="true"
    printerClass="Sempro\PHPUnitPrettyPrinter\PrettyPrinter">
Run Code Online (Sandbox Code Playgroud)