GiteaBot-PHPUnit/src/Poster.php
2019-09-19 16:55:24 +01:00

40 lines
1.2 KiB
PHP

<?php
namespace JHodges\GiteaBotPHPUnit;
use \JHodges\GiteaBot\Client;
final class Poster{
function __construct($testdox,$xml){
$report=file_get_contents($testdox);
$report=preg_replace('# \[#',' * [',$report);
$xml = simplexml_load_file($xml);
$project = $xml->testsuite;
//echo sprintf("total: %s msec", ($project['time'])) . PHP_EOL;
foreach ($project->testsuite as $testsuite) {
//echo sprintf(" suite: %s msec : %s", ($testsuite['time']), $testsuite['name']) . PHP_EOL;
foreach ($testsuite->testcase as $testcase) {
//echo sprintf(" case: %s msec : %s", ($testcase['time']), $testcase['name']) . PHP_EOL;
foreach($testcase as $k=>$v){
$report.="\n```plain\n".print_r($testcase,true)."\n```";
}
}
}
$this->report=$report;
}
function post($url, $user, $pass, $repoUser, $repo){
// open connection and repo
$client=new Client($url, $user, $pass, $repoUser, $repo);
$repo=$client->getRepo($repoUser, $repo);
// create the issue
$issue=$repo->createIssue([
'title'=>'Test Results',
'body'=>$this->report
]);
}
}