finshed result printer and fix posting bugs

This commit is contained in:
James 2019-09-22 16:26:25 +01:00
parent b9d8f04875
commit f05a4e8687
4 changed files with 44 additions and 112 deletions

View File

@ -1,19 +0,0 @@
<?php declare(strict_types=1);
namespace JHodges\GiteaBitPHPUnit;
use PHPUnit\Runner\BeforeFirstTestHook;
use PHPUnit\Runner\AfterLastTestHook;
final class Extension implements BeforeFirstTestHook, AfterLastTestHook{
public function executeBeforeFirstTest(): void
{
// called before the first test is being run
echo "AAAAAA";
}
public function executeAfterLastTest(): void
{
echo "ZZZZZZZ";
// called after the last test has been run
}
}

View File

@ -1,57 +0,0 @@
<?php
namespace JHodges\GiteaBotPHPUnit;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\Test as PHPUnit_Framework_Test;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\AssertionFailedError as PHPUnit_Framework_AssertionFailedError;
use PHPUnit\Framework\TestSuite as PHPUnit_Framework_TestSuite;
use PHPUnit\Framework\Warning;
use Exception;
class Listener implements TestListener{
private $stack=[];
public function addWarning(Test $test, Warning $e, $time){
die("wrank");
print_r($test->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";
}
}
}

View File

@ -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);
}
}
}
}
}

View File

@ -1,18 +1,23 @@
<?php
namespace JHodges\GiteaBitPHPUnit;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LogLevel;
namespace JHodges\GiteaBotPHPUnit;
class ResultPrinter extends \PHPUnit\TextUI\ResultPrinter
{
public function __construct($out = null, $verbose = false, $colors = self::COLOR_DEFAULT, $debug = false, $numberOfColumns = 80)
{
public function __construct($out = null, $verbose = false, $colors = self::COLOR_DEFAULT, $debug = false, $numberOfColumns = 80){
parent::__construct($out, $verbose, $colors , $debug , $numberOfColumns);
}
public function printResult(\PHPUnit\Framework\TestResult $result)
{
$poster=new \JHodges\GiteaBotPHPUnit\Poster('/tmp/testdox.txt','/tmp/logfile.xml');
$poster->post(
getenv('GiteaUrl'),
getenv('GiteaUser'),
getenv('GiteaPass'),
getenv('GiteaRepoUser'),
getenv('GiteaRepo')
);
}
protected function printHeader()