From f05a4e8687493aa8ade03e3a017f8bfc9724caf3 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 22 Sep 2019 16:26:25 +0100 Subject: [PATCH] finshed result printer and fix posting bugs --- src/Extention.php | 19 ------------- src/Listener.php | 57 --------------------------------------- src/Poster.php | 63 ++++++++++++++++++++++--------------------- src/ResultPrinter.php | 17 +++++++----- 4 files changed, 44 insertions(+), 112 deletions(-) delete mode 100644 src/Extention.php delete mode 100644 src/Listener.php diff --git a/src/Extention.php b/src/Extention.php deleted file mode 100644 index 6ef9ef7..0000000 --- a/src/Extention.php +++ /dev/null @@ -1,19 +0,0 @@ -getName()); -} - - public function addError(PHPUnit_Framework_Test $test, Exception $e, $time){ -die("err"); - print_r($test->getName()); - } - - public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time){ - $name=get_class($test).'::'.$test->getName(); - $message=$e->getMessage(); - echo("##### $name\n$message\n"); -} - - public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time){} - - public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time){} - - public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time){} - - public function startTest(PHPUnit_Framework_Test $test){} - - public function endTest(PHPUnit_Framework_Test $test, $time){ - print_r( $test->getActualOutput()); -} - - public function startTestSuite(PHPUnit_Framework_TestSuite $suite){ - $this->stack[$suite->getName()]='yes'; - } - - public function endTestSuite(PHPUnit_Framework_TestSuite $suite){ - unset($this->stack[$suite->getName()]); - if(count($this->stack)==0){ - echo "\n\nALLDONE\n\n"; - } - } - -} - diff --git a/src/Poster.php b/src/Poster.php index 2e0d5cf..b311b1e 100644 --- a/src/Poster.php +++ b/src/Poster.php @@ -5,41 +5,44 @@ use \JHodges\GiteaBot\Client; final class Poster{ - function __construct($testdox_path,$xml_path){ - $testdox=file_get_contents($testdox_path); - $testdox=preg_replace('# \[#',' * [',$testdox); + private $report; + function __construct($testdox_path,$xml_path){ + $testdox=file_get_contents($testdox_path); + $testdox=preg_replace('# \[#',' * [',$testdox); + + $this->report.=$testdox; $xml = simplexml_load_file($xml_path); - $project = $xml->testsuite; - $summary='';//sprintf("total: %s sec", ($project['time'])) . PHP_EOL; - $report=''; - foreach($project->attributes() as $k=>$v){ - //print_r($k);print_r($v);die(); - $summary.=" * $k : {$v[0]}\n"; - } - foreach ($project->testsuite as $testsuite) { - //$summary.=sprintf(" suite: %s sec : %s", ($testsuite['time']), $testsuite['name']) . PHP_EOL; - foreach ($testsuite->testcase as $testcase) { - //$summary.=sprintf(" case: %s sec : %s", ($testcase['time']), $testcase['name']) . PHP_EOL; - foreach($testcase as $k=>$v){ - $report.="\n```plain\n".print_r($testcase,true)."\n```"; - } - } - } - $this->report=$summary."\n".$testdox.$report; + $this->process($xml); } - function post($url, $user, $pass, $repoUser, $repo){ - // open connection and repo - $client=new Client($url, $user, $pass, $repoUser, $repo); - $repo=$client->getRepo($repoUser, $repo); + public function post($url, $user, $pass, $repoUser, $repo){ + // open connection and repo + $client=new Client($url, $user, $pass, $repoUser, $repo); + $repo=$client->getRepo($repoUser, $repo); - // create the issue - $issue=$repo->createIssue([ - 'title'=>'Test Results', - 'body'=>$this->report - ]); + // create the issue + $issue=$repo->createIssue([ + 'title'=>'Test Results', + 'body'=>$this->report + ]); + + } + + private function process($item){ + if(isset($item->testcase)){ + foreach($item->testcase as $testcase) { + foreach($testcase as $k=>$v){ + $this->report.="\n```plain\n".print_r($testcase,true)."\n```"; + } + } + } + if(isset($item->testsuite)){ + foreach($item->testsuite as $testsuite) { + $this->process($testsuite); + } + } + } - } } diff --git a/src/ResultPrinter.php b/src/ResultPrinter.php index 2527716..c06761b 100644 --- a/src/ResultPrinter.php +++ b/src/ResultPrinter.php @@ -1,18 +1,23 @@ post( + getenv('GiteaUrl'), + getenv('GiteaUser'), + getenv('GiteaPass'), + getenv('GiteaRepoUser'), + getenv('GiteaRepo') +); } protected function printHeader()