Skip to content

Commit bb560d1

Browse files
committed
ConsolePrinter: print test's title and common path instead of signature
1 parent fa6c196 commit bb560d1

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

src/Runner/Output/ConsolePrinter.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class ConsolePrinter implements Tester\Runner\OutputHandler
3939
/** @var array */
4040
private $results;
4141

42+
/** @var string */
43+
private $baseDir;
44+
4245

4346
public function __construct(Runner $runner, $displaySkipped = false, $file = 'php://output')
4447
{
@@ -51,6 +54,7 @@ public function __construct(Runner $runner, $displaySkipped = false, $file = 'ph
5154
public function begin()
5255
{
5356
$this->count = 0;
57+
$this->baseDir = null;
5458
$this->results = [
5559
Test::PASSED => 0,
5660
Test::SKIPPED => 0,
@@ -65,6 +69,23 @@ public function begin()
6569

6670
public function prepare(Test $test)
6771
{
72+
if ($this->baseDir === null) {
73+
$this->baseDir = dirname($test->getFile()) . DIRECTORY_SEPARATOR;
74+
} elseif (strpos($test->getFile(), $this->baseDir) !== 0) {
75+
$common = array_intersect_assoc(
76+
explode(DIRECTORY_SEPARATOR, $this->baseDir),
77+
explode(DIRECTORY_SEPARATOR, $test->getFile())
78+
);
79+
$this->baseDir = '';
80+
$prev = 0;
81+
foreach ($common as $i => $part) {
82+
if ($i !== $prev++) {
83+
break;
84+
}
85+
$this->baseDir .= $part . DIRECTORY_SEPARATOR;
86+
}
87+
}
88+
6889
$this->count++;
6990
}
7091

@@ -79,11 +100,12 @@ public function finish(Test $test)
79100
];
80101
fwrite($this->file, $outputs[$test->getResult()]);
81102

103+
$title = ($test->title ? "$test->title | " : '') . substr($test->getSignature(), strlen($this->baseDir));
82104
$message = ' ' . str_replace("\n", "\n ", trim($test->message)) . "\n\n";
83105
if ($test->getResult() === Test::FAILED) {
84-
$this->buffer .= Dumper::color('red', "-- FAILED: {$test->getSignature()}") . "\n$message";
106+
$this->buffer .= Dumper::color('red', "-- FAILED: $title") . "\n$message";
85107
} elseif ($test->getResult() === Test::SKIPPED && $this->displaySkipped) {
86-
$this->buffer .= "-- Skipped: {$test->getSignature()}\n$message";
108+
$this->buffer .= "-- Skipped: $title\n$message";
87109
}
88110
}
89111

tests/RunnerOutput/OutputHandlers.expect.console.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
F.sF.sFsF.s
44

5-
-- FAILED: %a%01-basic.fail.phptx
5+
-- FAILED: 01-basic.fail.phptx
66
Multi
77
line
88
stdout.Failed:
99

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

12-
-- FAILED: %a%02-title.fail.phptx
12+
-- FAILED: Title for output handlers | 02-title.fail.phptx
1313
Multi
1414
line
1515
stdout.Failed:
1616

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

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

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

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

tests/RunnerOutput/OutputHandlers.expect.consoleWithSkip.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
F.sF.sFsF.s
44

5-
-- FAILED: %a%01-basic.fail.phptx
5+
-- FAILED: %a?%01-basic.fail.phptx
66
Multi
77
line
88
stdout.Failed:
99

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

12-
-- Skipped: %a%01-basic.skip.phptx
12+
-- Skipped: %a?%01-basic.skip.phptx
1313

1414

15-
-- FAILED: %a%02-title.fail.phptx
15+
-- FAILED: Title for output handlers | 02-title.fail.phptx
1616
Multi
1717
line
1818
stdout.Failed:
1919

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

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

2424

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

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

34-
-- Skipped: %a%03-message.skip.phptx
34+
-- Skipped: 03-message.skip.phptx
3535
Multi
3636
line
3737
message.
3838

39-
-- FAILED: %a%04-args.fail.phptx dataprovider=thisIsAVeryVeryVeryLongArgumentNameToTestHowOutputHandlersDealWithItsLengthInTheirOutputFormatting|%a%provider.ini
39+
-- FAILED: 04-args.fail.phptx dataprovider=thisIsAVeryVeryVeryLongArgumentNameToTestHowOutputHandlersDealWithItsLengthInTheirOutputFormatting|%a%provider.ini
4040
Multi
4141
line
4242
stdout.Failed:
4343

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

46-
-- Skipped: %a%04-args.skip.phptx dataprovider=thisIsAVeryVeryVeryLongArgumentNameToTestHowOutputHandlersDealWithItsLengthInTheirOutputFormatting|%a%provider.ini
46+
-- Skipped: 04-args.skip.phptx dataprovider=thisIsAVeryVeryVeryLongArgumentNameToTestHowOutputHandlersDealWithItsLengthInTheirOutputFormatting|%a%provider.ini
4747
Multi
4848
line
4949
message.

0 commit comments

Comments
 (0)