ユニファ開発者ブログ

ユニファ株式会社プロダクトデベロップメント本部メンバーによるブログです。

PHPUnit のカバレッジ結果を AWS CodeBuild で可視化する

こんにちは、rightgo09 です。

今回は、PHPUnit の実行とそのカバレッジの結果を AWS CodeBuild 上で行う方法をまとめます。

まとめ

結論としては PHPUnit のカバレッジ結果を Cobertura の XML として出力し、それを AWS CodeBuild の入力とすれば良いようです(現在 Clover 形式では AWS CodeBuild 内でエラーになってしまいました)。

AWS CodeBuild

buildspec.yml

カバレッジ付きの PHPUnit 実行部分

phases:
...
  build:
    commands:
...
      - ./vendor/bin/phpunit --coverage-cobertura coverage-report.xml

レポート出力部分

reports:
  coverage-report:
    files:
      - coverage-report.xml
    file-format: CoberturaXml

テストのコードカバレッジレポート


テスト結果のレポートも同時に出力する場合は、JUnit 形式の出力と入力をすれば可能です。

      - ./vendor/bin/phpunit --coverage-cobertura coverage-report.xml --log-junit unittest-report.xml
 reports:
   coverage-report:
     files:
       - coverage-report.xml
     file-format: CoberturaXml
+  unittest-report:
+    files:
+      - unittest-report.xml
+    file-format: JunitXml

テスト結果の可視化

以上です。

unifa-e.com