diff --git a/action.yml b/action.yml index b8c4ad1..e2f0dd9 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,7 @@ branding: color: "green" inputs: type: - description: "lcov | simplecov" + description: "lcov | simplecov | phpunit" required: true default: "lcov" token: diff --git a/lib/coverage_report.rb b/lib/coverage_report.rb index 8752daa..73ceae4 100644 --- a/lib/coverage_report.rb +++ b/lib/coverage_report.rb @@ -7,6 +7,8 @@ class CoverageReport simplecov(report_path, data) elsif type == 'lcov' lcov(report_path, data) + elsif type == 'phpunit' + phpunit(report_path, data) else raise 'InvalidCoverageReportType' end @@ -25,6 +27,12 @@ class CoverageReport { 'lines' => { 'covered_percent' => lcov_covered_percent(lcov_result), 'minumum_percent' => minumum_percent } } end + def phpunit(report_path, data) + phpunit_result = execute_phpunit_parse(report_path) + minumum_percent = data[:min] + { 'lines' => { 'covered_percent' => phpunit_covered_percent(phpunit_result), 'minumum_percent' => minumum_percent} } + end + private def lcov_covered_percent(lcov_result) @@ -39,6 +47,22 @@ class CoverageReport JSON.parse(`node #{bin_path}/lcov-parse.js #{report_path}`) end + + def phpunit_covered_percent(phpunit_result) + # example for + # phpunit --coverage-text + # Summary: + # Classes: 10.14% (14/138) + # Methods: 16.67% (107/642) + # Lines: 13.95% (1059/7591) + + /Lines: * ([0-9\.]*)%/.match(phpunit_result)[1].to_f + end + + def execute_phpunit_parse(report_path) + File.read(report_path) + end + def read_json(path) JSON.parse(File.read(path)) end