10 Commits

Author SHA1 Message Date
James
994768ca9d fix indenting 2019-09-25 09:23:48 +01:00
James
1cbcac0361 call parent functions so default output not lost 2019-09-25 08:51:37 +01:00
James
bcea50c5dd delete screenshots after uploading 2019-09-25 08:51:21 +01:00
James
0c98200fc2 remove debug 2019-09-23 16:13:57 +01:00
James
e4c9d97697 add selenium url to test results 2019-09-23 16:13:11 +01:00
James
495d4e0d26 upload screenshots 2019-09-23 12:18:16 +01:00
6c0873fc6f Update 'README.md' 2019-09-22 20:09:53 +01:00
cc0eec3b4a Update 'README.md' 2019-09-22 20:03:33 +01:00
James
676c2215c7 update readme 2019-09-22 19:58:46 +01:00
James
4ecd985aba bug: displaying debug info on production 2019-09-22 18:00:37 +01:00
6 changed files with 63 additions and 110 deletions

View File

@@ -1 +1,20 @@
Post PHPUnit test results to Gitea Post PHPUnit test results to Gitea
Enable in phpunit.xml with
```plain
<phpunit ... printerClass="JHodges\GiteaBotPHPUnit\ResultPrinter">
<php>
<env name="GiteaUrl" value="https://try.gitea.io/api/v1/"/>
<env name="GiteaUser" value="bot"/>
<!--env name="GiteaPass" value="xxx"/--> <!--probably set this on the machine env-->
<env name="GiteaRepoUser" value="bobemoe"/>
<env name="GiteaRepo" value="test"/>
</php>
<logging>
<log type="junit" target="/tmp/logfile.xml"/>
<log type="testdox-text" target="/tmp/testdox.txt"/>
</logging>
```

View File

@@ -8,7 +8,7 @@
} }
], ],
"require": { "require": {
"jhodges/giteabot": "~1.2.0" "jhodges/giteabot": "~1.2.2"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

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

@@ -13,18 +13,19 @@ final class Poster{
$this->report.=$testdox; $this->report.=$testdox;
$xml = simplexml_load_file($xml_path); $this->xml = simplexml_load_file($xml_path);
$this->process($xml);
} }
public function post($url, $user, $pass, $repoUser, $repo){ public function post($url, $user, $pass, $repoUser, $repo, $title='Test Results'){
// open connection and repo // open connection and repo
$client=new Client($url, $user, $pass, $repoUser, $repo); $this->client=new Client($url, $user, $pass);
$repo=$client->getRepo($repoUser, $repo); $this->repo=$this->client->getRepo($repoUser, $repo);
$this->process($this->xml); //process xml and upload screenshots
// create the issue // create the issue
$issue=$repo->createIssue([ $issue=$this->repo->createIssue([
'title'=>'Test Results', 'title'=>$title,
'body'=>$this->report 'body'=>$this->report
]); ]);
@@ -34,7 +35,15 @@ final class Poster{
if(isset($item->testcase)){ if(isset($item->testcase)){
foreach($item->testcase as $testcase) { foreach($item->testcase as $testcase) {
foreach($testcase as $k=>$v){ foreach($testcase as $k=>$v){
$this->report.="\n```plain\n".print_r($testcase,true)."\n```"; $img='';
$name=$testcase->attributes()->class[0]."::".$testcase->attributes()->name[0];
if(file_exists("/tmp/$name.png")){
$data=$this->repo->addAttachment("/tmp/$name.png");
$url=$data->browser_download_url;
$img="\n![]($url)\n";
unlink("/tmp/$name.png");
}
$this->report.="\n------\n# $name\n$img\n```plain\n".print_r($testcase,true)."\n```";
} }
} }
} }

View File

@@ -1,34 +1,35 @@
<?php <?php
namespace JHodges\GiteaBotPHPUnit; namespace JHodges\GiteaBotPHPUnit;
class ResultPrinter extends \PHPUnit\TextUI\ResultPrinter 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); parent::__construct($out, $verbose, $colors , $debug , $numberOfColumns);
} }
public function printResult(\PHPUnit\Framework\TestResult $result) public function printResult(\PHPUnit\Framework\TestResult $result){
{ parent::printResult($result);
$poster=new \JHodges\GiteaBotPHPUnit\Poster('/tmp/testdox.txt','/tmp/logfile.xml'); $poster=new \JHodges\GiteaBotPHPUnit\Poster('/tmp/testdox.txt','/tmp/logfile.xml');
$poster->post( $poster->post(
getenv('GiteaUrl'), getenv('GiteaUrl'),
getenv('GiteaUser'), getenv('GiteaUser'),
getenv('GiteaPass'), getenv('GiteaPass'),
getenv('GiteaRepoUser'), getenv('GiteaRepoUser'),
getenv('GiteaRepo') getenv('GiteaRepo'),
'Test Results '.getenv('SeleniumBrowserUrl')
); );
} }
protected function printHeader() protected function printHeader(){
{ parent::printHeader();
} }
public function messageProcessor(array $record) public function messageProcessor(array $record){
{ parent::messageProcessor($record);
} }
public function suiteNameProcessor(array $record) public function suiteNameProcessor(array $record){
{ parent::suiteNameProcessor($record);
} }
} }