Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
eb81b0e965 |
19
README.md
19
README.md
@@ -1,20 +1 @@
|
|||||||
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>
|
|
||||||
```
|
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"jhodges/giteabot": "~1.2.2"
|
"jhodges/giteabot": "~1.2.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"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,19 +13,18 @@ final class Poster{
|
|||||||
|
|
||||||
$this->report.=$testdox;
|
$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, $title='Test Results'){
|
public function post($url, $user, $pass, $repoUser, $repo){
|
||||||
// open connection and repo
|
// open connection and repo
|
||||||
$this->client=new Client($url, $user, $pass);
|
$client=new Client($url, $user, $pass, $repoUser, $repo);
|
||||||
$this->repo=$this->client->getRepo($repoUser, $repo);
|
$repo=$client->getRepo($repoUser, $repo);
|
||||||
|
|
||||||
$this->process($this->xml); //process xml and upload screenshots
|
|
||||||
|
|
||||||
// create the issue
|
// create the issue
|
||||||
$issue=$this->repo->createIssue([
|
$issue=$repo->createIssue([
|
||||||
'title'=>$title,
|
'title'=>'Test Results',
|
||||||
'body'=>$this->report
|
'body'=>$this->report
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -35,15 +34,7 @@ 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){
|
||||||
$img='';
|
$this->report.="\n```plain\n".print_r($testcase,true)."\n```";
|
||||||
$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,35 +1,34 @@
|
|||||||
<?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);
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user