Permalink
Browse files

ConsolePrinter: print test's title and common path instead of signature

  • Loading branch information...
milo committed Aug 3, 2017
1 parent fa6c196 commit bb560d1e4ae91d9a2b066a0fdfea52a5510dcd61
@@ -39,6 +39,9 @@ class ConsolePrinter implements Tester\Runner\OutputHandler
/** @var array */
private $results;
/** @var string */
private $baseDir;
public function __construct(Runner $runner, $displaySkipped = false, $file = 'php://output')
{
@@ -51,6 +54,7 @@ public function __construct(Runner $runner, $displaySkipped = false, $file = 'ph
public function begin()
{
$this->count = 0;
$this->baseDir = null;
$this->results = [
Test::PASSED => 0,
Test::SKIPPED => 0,
@@ -65,6 +69,23 @@ public function begin()
public function prepare(Test $test)
{
if ($this->baseDir === null) {
$this->baseDir = dirname($test->getFile()) . DIRECTORY_SEPARATOR;
} elseif (strpos($test->getFile(), $this->baseDir) !== 0) {
$common = array_intersect_assoc(
explode(DIRECTORY_SEPARATOR, $this->baseDir),
explode(DIRECTORY_SEPARATOR, $test->getFile())
);
$this->baseDir = '';
$prev = 0;
foreach ($common as $i => $part) {
if ($i !== $prev++) {
break;
}
$this->baseDir .= $part . DIRECTORY_SEPARATOR;
}
}
$this->count++;
}
@@ -79,11 +100,12 @@ public function finish(Test $test)
];
fwrite($this->file, $outputs[$test->getResult()]);
$title = ($test->title ? "$test->title | " : '') . substr($test->getSignature(), strlen($this->baseDir));
$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";
$this->buffer .= Dumper::color('red', "-- FAILED: $title") . "\n$message";
} elseif ($test->getResult() === Test::SKIPPED && $this->displaySkipped) {
$this->buffer .= "-- Skipped: {$test->getSignature()}\n$message";
$this->buffer .= "-- Skipped: $title\n$message";
}
}
@@ -2,21 +2,21 @@

F.sF.sFsF.s

-- FAILED: %a%01-basic.fail.phptx
-- FAILED: 01-basic.fail.phptx
Multi
line
stdout.Failed:

in %a%01-basic.fail.phptx(7) Tester\Assert::fail('');

-- FAILED: %a%02-title.fail.phptx
-- FAILED: Title for output handlers | 02-title.fail.phptx
Multi
line
stdout.Failed:

in %a%02-title.fail.phptx(11) Tester\Assert::fail('');

-- FAILED: %a%03-message.fail.phptx
-- FAILED: 03-message.fail.phptx
Multi
line
stdout.Failed: Multi
@@ -25,7 +25,7 @@ F.sF.sFsF.s

in %a%03-message.fail.phptx(7) Tester\Assert::fail("Multi\nline\nmessage.");

-- FAILED: %a%04-args.fail.phptx dataprovider=thisIsAVeryVeryVeryLongArgumentNameToTestHowOutputHandlersDealWithItsLengthInTheirOutputFormatting|%a%provider.ini
-- FAILED: 04-args.fail.phptx dataprovider=thisIsAVeryVeryVeryLongArgumentNameToTestHowOutputHandlersDealWithItsLengthInTheirOutputFormatting|%a%provider.ini
Multi
line
stdout.Failed:
@@ -2,27 +2,27 @@

F.sF.sFsF.s

-- FAILED: %a%01-basic.fail.phptx
-- FAILED: %a?%01-basic.fail.phptx
Multi
line
stdout.Failed:

in %a%01-basic.fail.phptx(7) Tester\Assert::fail('');

-- Skipped: %a%01-basic.skip.phptx
-- Skipped: %a?%01-basic.skip.phptx


-- FAILED: %a%02-title.fail.phptx
-- FAILED: Title for output handlers | 02-title.fail.phptx
Multi
line
stdout.Failed:

in %a%02-title.fail.phptx(11) Tester\Assert::fail('');

-- Skipped: %a%02-title.skip.phptx
-- Skipped: Title for output handlers | 02-title.skip.phptx


-- FAILED: %a%03-message.fail.phptx
-- FAILED: 03-message.fail.phptx
Multi
line
stdout.Failed: Multi
@@ -31,19 +31,19 @@ F.sF.sFsF.s

in %a%03-message.fail.phptx(7) Tester\Assert::fail("Multi\nline\nmessage.");

-- Skipped: %a%03-message.skip.phptx
-- Skipped: 03-message.skip.phptx
Multi
line
message.

-- FAILED: %a%04-args.fail.phptx dataprovider=thisIsAVeryVeryVeryLongArgumentNameToTestHowOutputHandlersDealWithItsLengthInTheirOutputFormatting|%a%provider.ini
-- FAILED: 04-args.fail.phptx dataprovider=thisIsAVeryVeryVeryLongArgumentNameToTestHowOutputHandlersDealWithItsLengthInTheirOutputFormatting|%a%provider.ini
Multi
line
stdout.Failed:

in %a%04-args.fail.phptx(11) Tester\Assert::fail('');

-- Skipped: %a%04-args.skip.phptx dataprovider=thisIsAVeryVeryVeryLongArgumentNameToTestHowOutputHandlersDealWithItsLengthInTheirOutputFormatting|%a%provider.ini
-- Skipped: 04-args.skip.phptx dataprovider=thisIsAVeryVeryVeryLongArgumentNameToTestHowOutputHandlersDealWithItsLengthInTheirOutputFormatting|%a%provider.ini
Multi
line
message.

0 comments on commit bb560d1

Please sign in to comment.