Make earl report a test result printer.

This commit is contained in:
Dave Longley 2013-09-14 22:19:07 -04:00
parent 86908c8e4f
commit 0e37dd4388

View file

@ -9,18 +9,6 @@
require_once('jsonld.php');
class JsonLdTestCase extends PHPUnit_Framework_TestCase {
/**
* Called after all tests; optionally outputs an earl report.
*/
public static function tearDownAfterClass() {
global $EARL, $OPTIONS;
if(isset($OPTIONS['-e'])) {
$filename = $OPTIONS['-e'];
printf("\nWriting EARL report to: %s\n", $filename);
$EARL->write($filename);
}
}
/**
* Runs this test case. Overridden to attach to EARL report w/o need for
* an external XML configuration file.
@ -444,8 +432,10 @@ class JsonLdTestIterator implements Iterator {
}
}
class EarlReport implements PHPUnit_Framework_TestListener {
class EarlReport extends PHPUnit_Util_Printer
implements PHPUnit_Framework_TestListener {
public function __construct() {
$this->filename = null;
$this->result = null;
$this->report = (object)array(
'@context' => (object)array(
@ -523,14 +513,15 @@ class EarlReport implements PHPUnit_Framework_TestListener {
/**
* Writes this EARL report to a file.
*
* @param string $filename the name of the file to write to.
*/
public function write($filename) {
$fd = fopen($filename, 'w');
public function flush() {
if($this->filename) {
printf("\nWriting EARL report to: %s\n", $this->filename);
$fd = fopen($this->filename, 'w');
fwrite($fd, Util::jsonldEncode($this->report));
fclose($fd);
}
}
public function endTest(PHPUnit_Framework_Test $test, $time) {
$this->addAssertion($test->test, true);
@ -617,9 +608,6 @@ $TESTS = array();
// parsed command line options
$OPTIONS = array();
// EARL Report
$EARL = new EarlReport();
// parse command line options
global $argv;
$args = $argv;
@ -647,6 +635,12 @@ if(!isset($OPTIONS['-d'])) {
exit(0);
}
// EARL Report
$EARL = new EarlReport();
if(isset($OPTIONS['-e'])) {
$EARL->filename = $OPTIONS['-e'];
}
// load root manifest
$ROOT_MANIFEST_DIR = realpath($OPTIONS['-d']);
$filename = join(