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