Skip to content

Commit 55e6295

Browse files
committed
Bump test coverage for markdown generator; fix bugs in process
1 parent 73fc247 commit 55e6295

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

src/Generator/MarkdownGenerator.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MarkdownGenerator implements Generator
1616
{
1717
public function createSniffDoc(Sniff $sniff): string
1818
{
19-
return <<<MD
19+
$sniffDoc = <<<MD
2020
# {$sniff->getCode()}
2121
2222
{$this->getDescription($sniff)}
@@ -26,26 +26,35 @@ public function createSniffDoc(Sniff $sniff): string
2626
{$this->getSeeAlso($sniff->getLinks())}
2727
{$this->getViolations($sniff->getViolations())}
2828
MD;
29+
30+
$sniffDoc = preg_replace('/\n{3,}/', "\n\n",$sniffDoc);
31+
return preg_replace('/\n{2,}$/', "\n",$sniffDoc);
2932
}
3033

3134
private function getDescription(Sniff $sniff): string
3235
{
36+
$description = $sniff->getDescription();
37+
if ($description === '') {
38+
return '';
39+
}
40+
3341
return <<<MD
34-
{$sniff->getDescription()}
42+
{$description}
3543
3644
MD;
3745
}
3846

3947
private function getDocblock(Sniff $sniff): string
4048
{
41-
if ($sniff->getDocblock() === '') {
49+
$docblock = $sniff->getDocblock();
50+
if ($docblock === '') {
4251
return '';
4352
}
4453

4554
return <<<MD
4655
## Docblock
4756
48-
{$sniff->getDocblock()}
57+
{$docblock}
4958
MD;
5059
}
5160

@@ -127,7 +136,7 @@ private function getPublicPropertyLines(array $properties): array
127136
*/
128137
private function getSeeAlso(Urls $links): string
129138
{
130-
if ($links === []) {
139+
if ($links->getUrls() === []) {
131140
return '';
132141
}
133142

tests/Generator/MarkdownGeneratorTest.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,32 @@ class MarkdownGeneratorTest extends TestCase
1818
private MarkdownGenerator $generator;
1919

2020
/** @test */
21-
public function fromSniff()
21+
public function fromSniff_WithMinimalData_WriteMinimalDetails()
2222
{
2323
$doc = new Sniff(
24-
'Generic.MySniff',
24+
'Standard.Category.My',
25+
'',
26+
[],
27+
new Urls([]),
28+
'',
29+
[],
30+
[]
31+
);
32+
33+
self::assertEquals(
34+
<<<MD
35+
# Standard.Category.My
36+
37+
MD,
38+
$this->generator->createSniffDoc($doc)
39+
);
40+
}
41+
42+
/** @test */
43+
public function fromSniff_WithCompleteData_WriteAllDetails()
44+
{
45+
$doc = new Sniff(
46+
'Standard.Category.My',
2547
'DocBlock',
2648
[
2749
new Property('a', 'string', 'DescriptionA'),
@@ -35,7 +57,7 @@ public function fromSniff()
3557
[],
3658
[
3759
new Violation(
38-
'Generic.MySniff.ErrorCode',
60+
'Standard.Category.My.ErrorCode',
3961
'Description',
4062
[
4163
new Diff('a();', 'b();'),
@@ -51,7 +73,7 @@ public function fromSniff()
5173

5274
self::assertEquals(
5375
<<<MD
54-
# Generic.MySniff
76+
# Standard.Category.My
5577
5678
Description
5779
@@ -73,7 +95,7 @@ public function fromSniff()
7395
7496
```
7597
<details>
76-
<summary>Generic.MySniff.ErrorCode</summary>
98+
<summary>Standard.Category.My.ErrorCode</summary>
7799
Description
78100
79101
## Comparisons

0 commit comments

Comments
 (0)