PHPUnit で作成したテスト項目をHTMLで出力する

PHPUnit--log-junit オプションでxmlを出力する

# ./vendor/bin/phpunit tests/Feature/SampleControllerTest.php --log-junit output.xml
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.

.                                                                   1 / 1 (100%)

Time: 00:00.901, Memory: 24.00 MB

OK (1 test, 1 assertion)

xsltproc を使用して html に変換する

# xsltproc phpunit.xslt output.xml > output.html 

(※ xsltproc コマンドがない場合は別途インストールする。Macにはデフォルトで入ってるはず。。)
出力用のテンプレ(phpunit.xslt)は以下よりDL

PHPUnit xslt · GitHub

htmlが出力されていることを確認
テンプレを変えたい場合は phpunit.xslt を任意で修正すればOK

参考

https://phpunit.readthedocs.io/ja/latest/textui.htmlphpunit.readthedocs.io

inokara.hateblo.jp

qiita.com


株式会社エイルシステムではWebエンジニア・モバイルアプリエンジニアを募集しています。
実務経験がなくてもOKです。ご興味のある方は弊社HPよりご連絡ください。