Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
eb81b0e965 |
19
README.md
19
README.md
@@ -1,20 +1 @@
|
||||
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.2"
|
||||
"jhodges/giteabot": "~1.2.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
19
src/Extention.php
Normal file
19
src/Extention.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?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
|
||||
}
|
||||
}
|
57
src/Listener.php
Normal file
57
src/Listener.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -13,18 +13,17 @@ final class Poster{
|
||||
|
||||
$this->report.=$testdox;
|
||||
|
||||
$this->xml = simplexml_load_file($xml_path);
|
||||
$xml = simplexml_load_file($xml_path);
|
||||
$this->process($xml);
|
||||
}
|
||||
|
||||
public function post($url, $user, $pass, $repoUser, $repo){
|
||||
// open connection and repo
|
||||
$this->client=new Client($url, $user, $pass, true);
|
||||
$this->repo=$this->client->getRepo($repoUser, $repo);
|
||||
|
||||
$this->process($this->xml); //process xml and upload screenshots
|
||||
$client=new Client($url, $user, $pass, $repoUser, $repo);
|
||||
$repo=$client->getRepo($repoUser, $repo);
|
||||
|
||||
// create the issue
|
||||
$issue=$this->repo->createIssue([
|
||||
$issue=$repo->createIssue([
|
||||
'title'=>'Test Results',
|
||||
'body'=>$this->report
|
||||
]);
|
||||
@@ -35,14 +34,7 @@ final class Poster{
|
||||
if(isset($item->testcase)){
|
||||
foreach($item->testcase as $testcase) {
|
||||
foreach($testcase as $k=>$v){
|
||||
$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";
|
||||
}
|
||||
$this->report.="\n------\n# $name\n$img\n```plain\n".print_r($testcase,true)."\n```";
|
||||
$this->report.="\n```plain\n".print_r($testcase,true)."\n```";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user