9 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
4 changed files with 63 additions and 34 deletions

View File

@@ -1 +1,20 @@
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": {
"jhodges/giteabot": "~1.2.0"
"jhodges/giteabot": "~1.2.2"
},
"autoload": {
"psr-4": {

View File

@@ -13,18 +13,19 @@ final class Poster{
$this->report.=$testdox;
$xml = simplexml_load_file($xml_path);
$this->process($xml);
$this->xml = simplexml_load_file($xml_path);
}
public function post($url, $user, $pass, $repoUser, $repo){
public function post($url, $user, $pass, $repoUser, $repo, $title='Test Results'){
// open connection and repo
$client=new Client($url, $user, $pass);
$repo=$client->getRepo($repoUser, $repo);
$this->client=new Client($url, $user, $pass);
$this->repo=$this->client->getRepo($repoUser, $repo);
$this->process($this->xml); //process xml and upload screenshots
// create the issue
$issue=$repo->createIssue([
'title'=>'Test Results',
$issue=$this->repo->createIssue([
'title'=>$title,
'body'=>$this->report
]);
@@ -34,7 +35,15 @@ final class Poster{
if(isset($item->testcase)){
foreach($item->testcase as $testcase) {
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
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){
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(
public function printResult(\PHPUnit\Framework\TestResult $result){
parent::printResult($result);
$poster=new \JHodges\GiteaBotPHPUnit\Poster('/tmp/testdox.txt','/tmp/logfile.xml');
$poster->post(
getenv('GiteaUrl'),
getenv('GiteaUser'),
getenv('GiteaPass'),
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);
}
}