-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
98 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Churn\Result\Render; | ||
|
||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class MarkdownResultsRenderer implements ResultsRendererInterface | ||
{ | ||
/** | ||
* Renders the results. | ||
* | ||
* @param OutputInterface $output Output Interface. | ||
* @param array<array<float|integer|string>> $results The results. | ||
*/ | ||
public function render(OutputInterface $output, array $results): void | ||
{ | ||
$output->writeln('| File | Times Changed | Complexity | Score |'); | ||
$output->writeln('|------|---------------|------------|-------|'); | ||
|
||
foreach ($results as $result) { | ||
$output->writeln($this->inline($result)); | ||
} | ||
} | ||
|
||
/** | ||
* @param array<float|integer|string> $data The data to inline. | ||
*/ | ||
private function inline(array $data): string | ||
{ | ||
$escapedData = \array_map(static function ($item) { | ||
return \is_string($item) | ||
? \str_replace('|', '\\|', $item) | ||
: $item; | ||
}, $data); | ||
|
||
return '| ' . \implode(' | ', $escapedData) . ' |'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Churn\Tests\Unit\Result\Render; | ||
|
||
use Churn\Result\Render\MarkdownResultsRenderer; | ||
use Churn\Tests\BaseTestCase; | ||
use Mockery as m; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class MarkdownResultsRendererTest extends BaseTestCase | ||
{ | ||
/** @test */ | ||
public function it_can_be_instantiated() | ||
{ | ||
$this->assertInstanceOf(MarkdownResultsRenderer::class, new MarkdownResultsRenderer()); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_render_the_results_as_markdown() | ||
{ | ||
$results = [ | ||
['filename1.php', 5, 7, 0.625], | ||
['path/filename2.php', 3, 4, 0.242], | ||
['pa|th/filename3.php', 1, 5, 0.08], | ||
]; | ||
|
||
$output = m::mock(OutputInterface::class); | ||
$output->shouldReceive('writeln')->once()->with('| File | Times Changed | Complexity | Score |'); | ||
$output->shouldReceive('writeln')->once()->with('|------|---------------|------------|-------|'); | ||
$output->shouldReceive('writeln')->once()->with('| filename1.php | 5 | 7 | 0.625 |'); | ||
$output->shouldReceive('writeln')->once()->with('| path/filename2.php | 3 | 4 | 0.242 |'); | ||
$output->shouldReceive('writeln')->once()->with('| pa\\|th/filename3.php | 1 | 5 | 0.08 |'); | ||
|
||
(new MarkdownResultsRenderer())->render($output, $results); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters