Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
994768ca9d | ||
|
1cbcac0361 | ||
|
bcea50c5dd | ||
|
0c98200fc2 | ||
|
e4c9d97697 | ||
|
495d4e0d26 | ||
6c0873fc6f | |||
cc0eec3b4a | |||
|
676c2215c7 | ||
|
4ecd985aba |
19
README.md
19
README.md
@@ -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>
|
||||
```
|
||||
|
@@ -8,7 +8,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"jhodges/giteabot": "~1.2.0"
|
||||
"jhodges/giteabot": "~1.2.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@@ -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, $repoUser, $repo);
|
||||
$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\n";
|
||||
unlink("/tmp/$name.png");
|
||||
}
|
||||
$this->report.="\n------\n# $name\n$img\n```plain\n".print_r($testcase,true)."\n```";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user