Permalink
Browse files

OutputHandler: result() renamed to finish() and receives whole Test i…

…nstance (BC break)
  • Loading branch information...
milo committed Jul 31, 2017
1 parent 900febd commit 64ef6427028461320461066420535188402f6797
@@ -51,20 +51,20 @@ public function begin()
}
public function result($testName, $result, $message)
public function finish(Test $test)
{
$outputs = [
Test::PASSED => '.',
Test::SKIPPED => 's',
Test::FAILED => Dumper::color('white/red', 'F'),
];
fwrite($this->file, $outputs[$result]);
fwrite($this->file, $outputs[$test->getResult()]);
$message = ' ' . str_replace("\n", "\n ", trim($message)) . "\n\n";
if ($result === Test::FAILED) {
$this->buffer .= Dumper::color('red', "-- FAILED: $testName") . "\n$message";
} elseif ($result === Test::SKIPPED && $this->displaySkipped) {
$this->buffer .= "-- Skipped: $testName\n$message";
$message = ' ' . str_replace("\n", "\n ", trim($test->message)) . "\n\n";
if ($test->getResult() === Test::FAILED) {
$this->buffer .= Dumper::color('red', "-- FAILED: {$test->getSignature()}") . "\n$message";
} elseif ($test->getResult() === Test::SKIPPED && $this->displaySkipped) {
$this->buffer .= "-- Skipped: {$test->getSignature()}\n$message";
}
}
@@ -44,13 +44,13 @@ public function begin()
}
public function result($testName, $result, $message)
public function finish(Test $test)
{
$this->buffer .= "\t\t<testcase classname=\"" . htmlspecialchars($testName) . '" name="' . htmlspecialchars($testName) . '"';
$this->buffer .= "\t\t<testcase classname=\"" . htmlspecialchars($test->getSignature()) . '" name="' . htmlspecialchars($test->getSignature()) . '"';
switch ($result) {
switch ($test->getResult()) {
case Test::FAILED:
$this->buffer .= ">\n\t\t\t<failure message=\"" . htmlspecialchars($message) . "\"/>\n\t\t</testcase>\n";
$this->buffer .= ">\n\t\t\t<failure message=\"" . htmlspecialchars($test->message) . "\"/>\n\t\t</testcase>\n";
break;
case Test::SKIPPED:
$this->buffer .= ">\n\t\t\t<skipped/>\n\t\t</testcase>\n";
@@ -39,15 +39,15 @@ public function begin()
}
public function result($testName, $result, $message)
public function finish(Test $test)
{
$message = ' ' . str_replace("\n", "\n ", Tester\Dumper::removeColors(trim($message)));
$message = ' ' . str_replace("\n", "\n ", Tester\Dumper::removeColors(trim($test->message)));
$outputs = [
Test::PASSED => "-- OK: $testName",
Test::SKIPPED => "-- Skipped: $testName\n$message",
Test::FAILED => "-- FAILED: $testName\n$message",
Test::PASSED => "-- OK: {$test->getSignature()}",
Test::SKIPPED => "-- Skipped: {$test->getSignature()}\n$message",
Test::FAILED => "-- FAILED: {$test->getSignature()}\n$message",
];
fwrite($this->file, $outputs[$result] . "\n\n");
fwrite($this->file, $outputs[$test->getResult()] . "\n\n");
}
@@ -37,15 +37,15 @@ public function begin()
}
public function result($testName, $result, $message)
public function finish(Test $test)
{
$message = str_replace("\n", "\n# ", trim($message));
$message = str_replace("\n", "\n# ", trim($test->message));
$outputs = [
Test::PASSED => "ok $testName",
Test::SKIPPED => "ok $testName #skip $message",
Test::FAILED => "not ok $testName\n# $message",
Test::PASSED => "ok {$test->getSignature()}",
Test::SKIPPED => "ok {$test->getSignature()} #skip $message",
Test::FAILED => "not ok {$test->getSignature()}\n# $message",
];
fwrite($this->file, $outputs[$result] . "\n");
fwrite($this->file, $outputs[$test->getResult()] . "\n");
}
@@ -17,7 +17,7 @@ interface OutputHandler
{
function begin();
function result($testName, $result, $message);
function finish(Test $test);
function end();
}
@@ -212,11 +212,11 @@ public function getJobCount()
* Writes to output handlers.
* @return void
*/
public function writeResult(Test $test)
public function finishTest(Test $test)
{
$this->results[$test->getResult()]++;
foreach ($this->outputHandlers as $handler) {
$handler->result($test->getSignature(), $test->getResult(), $test->message);
$handler->finish(clone $test);
}
if ($this->tempDir) {
@@ -56,7 +56,7 @@ public function initiate($file)
foreach (is_array($res) ? $res : [$res] as $testVariety) {
/** @var Test $testVariety */
if ($testVariety->hasResult()) {
$this->runner->writeResult($testVariety);
$this->runner->finishTest($testVariety);
} else {
$prepared[] = $testVariety;
}
@@ -92,12 +92,12 @@ public function assess(Job $job)
foreach ((array) $annotations[$m[1]] as $arg) {
/** @var Test|null $res */
if ($res = $this->$method($job, $arg)) {
$this->runner->writeResult($res);
$this->runner->finishTest($res);
return;
}
}
}
$this->runner->writeResult($test->withResult(Test::PASSED, $test->message));
$this->runner->finishTest($test->withResult(Test::PASSED, $test->message));
}
@@ -15,9 +15,9 @@ class Logger implements Tester\Runner\OutputHandler
public $results = [];
public function result($testName, $result, $message)
public function finish(Test $test)
{
$this->results[] = [basename($testName), $result, $message];
$this->results[] = [basename($test->getFile()), $test->getResult(), $test->message];
}
@@ -15,9 +15,9 @@ class Logger implements Tester\Runner\OutputHandler
public $results = [];
public function result($testName, $result, $message)
public function finish(Test $test)
{
$this->results[basename($testName)] = [$result, $message];
$this->results[basename($test->getFile())] = [$test->getResult(), $test->message];
}
@@ -15,9 +15,9 @@ class Logger implements Tester\Runner\OutputHandler
public $results = [];
public function result($testName, $result, $message)
public function finish(Test $test)
{
$this->results[basename($testName)] = $result;
$this->results[basename($test->getFile())] = $test->getResult();
}
@@ -17,9 +17,9 @@ class Logger implements Tester\Runner\OutputHandler
public $results = [];
public function result($testName, $result, $message)
public function finish(Test $test)
{
$this->results[basename($testName)] = [$result, $message];
$this->results[basename($test->getFile())] = [$test->getResult(), $test->message];
}
@@ -16,9 +16,9 @@ class Logger implements Tester\Runner\OutputHandler
public $results = [];
public function result($testName, $result, $message)
public function finish(Test $test)
{
$this->results[] = [$result, basename($testName)];
$this->results[] = [$test->getResult(), basename($test->getFile())];
}

0 comments on commit 64ef642

Please sign in to comment.