Skip to content

Commit 7ee0b6b

Browse files
committed
Add tests for the output types and modified author to pass.
1 parent ee3da88 commit 7ee0b6b

File tree

3 files changed

+117
-2
lines changed

3 files changed

+117
-2
lines changed

src/Output/AuthorOutput.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,23 @@ protected function getStats($count, $total)
150150
*/
151151
protected function wrapLineWithRightAlign($subject, $word)
152152
{
153+
$lineOutput = '';
153154
$len = strlen($word);
154155

155156
if (strlen($subject) < self::CHARS_PER_LINE - $len + 1) {
156157
return $this->rightAlign($subject, $word);
157158
}
158159

159-
$newSubject = substr_replace($subject, "\n", self::CHARS_PER_LINE - $len, 0);
160-
return $this->wrapLine($newSubject);
160+
$lines = explode("\n", $this->wrapLine($subject));
161+
$firstLine = array_shift($lines);
162+
163+
// Add the stats to the first line.
164+
$lineOutput .= $this->rightAlign($firstLine, $word) . "\n ";
165+
166+
// And add the remaining lines to the resulting string.
167+
$lineOutput .= $this->wrapLine(implode(" ", array_map("trim", $lines)));
168+
169+
return $lineOutput;
161170
}
162171

163172
/**
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace ChrisHalbert\PhpBCC\Output;
4+
5+
class AuthorOutputTest extends \PHPUnit_Framework_TestCase
6+
{
7+
protected $output;
8+
9+
public function setUp()
10+
{
11+
$this->output = new AuthorOutput();
12+
}
13+
14+
public function testOutput()
15+
{
16+
$entries = [
17+
[
18+
'file' => 'FooFile',
19+
'line' => 321,
20+
'author' => 'Jordy',
21+
'date' => '2016-11-01'
22+
]
23+
];
24+
25+
$expected = <<<EOF
26+
PHP BLAME CODE COVERAGE UNCOVERED OBJECTS (#/total) %
27+
28+
Jordy (1/1) 100%
29+
FooFile:321 (1/1) 100%
30+
31+
EOF;
32+
$this->expectOutputString($expected);
33+
$this->output->output($entries);
34+
}
35+
36+
public function testOutputWithLongLine()
37+
{
38+
$entries = $this->getLongListOfEntries();
39+
$expected = <<<EOF
40+
PHP BLAME CODE COVERAGE UNCOVERED OBJECTS (#/total) %
41+
42+
Jordy (50/50) 100%
43+
FooFile:50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, (50/50) 100%
44+
69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
45+
90, 91, 92, 93, 94, 95, 96, 97, 98, 99
46+
47+
EOF;
48+
$this->expectOutputString($expected);
49+
$this->output->output($entries);
50+
}
51+
52+
public function getLongListOfEntries()
53+
{
54+
$entries = [];
55+
56+
for ($line = 50; $line < 100; $line++) {
57+
$entries[] = [
58+
'file' => 'FooFile',
59+
'line' => $line,
60+
'author' => 'Jordy',
61+
'date' => '2016-11-01'
62+
];
63+
}
64+
65+
return $entries;
66+
}
67+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace ChrisHalbert\PhpBCC\Output;
4+
5+
class TextOutputTest extends \PHPUnit_Framework_TestCase
6+
{
7+
protected $output;
8+
9+
public function setUp()
10+
{
11+
$this->output = new TextOutput();
12+
}
13+
14+
public function testOutput()
15+
{
16+
$this->expectOutputString(
17+
"FooFile:321 Jordy last touched 2016-11-01\nBarFile:123 Nat last touched 2016-11-02\n"
18+
);
19+
$this->output->output($this->getEntries());
20+
}
21+
22+
protected function getEntries()
23+
{
24+
return [
25+
[
26+
'file' => 'FooFile',
27+
'line' => 321,
28+
'author' => 'Jordy',
29+
'date' => '2016-11-01'
30+
],
31+
[
32+
'file' => 'BarFile',
33+
'line' => 123,
34+
'author' => 'Nat',
35+
'date' => '2016-11-02'
36+
]
37+
];
38+
}
39+
}

0 commit comments

Comments
 (0)