From cf7fc454ec1789603b360d69db83faf49b1e3ef1 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Fri, 22 Jul 2016 14:31:11 +0200 Subject: Add code coverage output Signed-off-by: Florian Pritz --- application/controllers/tools.php | 17 +++++++++++++++++ application/test/Test.php | 7 +++++++ 2 files changed, 24 insertions(+) (limited to 'application') diff --git a/application/controllers/tools.php b/application/controllers/tools.php index 845597b08..e90ed6d5f 100644 --- a/application/controllers/tools.php +++ b/application/controllers/tools.php @@ -88,6 +88,7 @@ class Tools extends MY_Controller { try { $test->setTestNamePrefix($method->name." - "); $test->init(); + $test->setTestID("{$testcase}->{$method->name}"); $test->{$method->name}(); $test->cleanup(); } catch (\Exception $e) { @@ -97,10 +98,26 @@ class Tools extends MY_Controller { } } } + if ($exitcode == 0) { $test->done_testing(); } else { exit($exitcode); } } + + function generate_coverage_report() + { + include APPPATH."../vendor/autoload.php"; + $coverage = new \SebastianBergmann\CodeCoverage\CodeCoverage(); + foreach (glob(FCPATH."/test-coverage-data/*") as $file) { + $coverage->merge(unserialize(file_get_contents($file))); + } + + //$writer = new \SebastianBergmann\CodeCoverage\Report\Text(); + //print $writer->process($coverage, 'code-coverage-report'); + $writer = new \SebastianBergmann\CodeCoverage\Report\Html\Facade(); + print $writer->process($coverage, 'code-coverage-report'); + print "Report saved to ./code-coverage-report/index.html\n"; + } } diff --git a/application/test/Test.php b/application/test/Test.php index 925fe131e..a0ebf880e 100644 --- a/application/test/Test.php +++ b/application/test/Test.php @@ -26,6 +26,7 @@ class TestMore extends \TestMore { abstract class Test { protected $t; protected $server = ""; + private $testid = ""; public function __construct() { @@ -38,6 +39,11 @@ abstract class Test { $this->server = $server; } + public function setTestID($testid) + { + $this->testid = $testid; + } + // Method: POST, PUT, GET etc // Data: array("param" => "value") ==> index.php?param=value // Source: http://stackoverflow.com/a/9802854/953022 @@ -77,6 +83,7 @@ abstract class Test { curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "Accept: application/json", + "X-Testsuite-Testname: API request from ".$this->testid, "Expect: ", )); -- cgit v1.2.3-24-g4f1b