forked from squizlabs/PHP_CodeSniffer
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generators: add tests covering handling of invalid docs
This adds another set of dedicated tests to safeguard how XML docs which don't follow the specification are handled. This initial set of tests for this documents the current behaviour [*]. This behaviour may not always be the desired behaviour, in which case, this will be fixed in follow-up commits. To get these tests up and running, the following fatal errors needed to be fixed: * Fatal error when a code comparison only contains a single code element: ``` Fatal error: Uncaught Error: Call to a member function getAttribute() on null in path/to/PHP_CodeSniffer/src/Generators/Markdown.php:253 Stack trace: #0 path/to/PHP_CodeSniffer/src/Generators/Markdown.php(139): PHP_CodeSniffer\Generators\Markdown->getFormattedCodeComparisonBlock(Object(DOMElement)) #1 path/to/PHP_CodeSniffer/src/Generators/Markdown.php(39): PHP_CodeSniffer\Generators\Markdown->processSniff(Object(DOMElement)) squizlabs#2 path/to/PHP_CodeSniffer/src/Runner.php(99): PHP_CodeSniffer\Generators\Markdown->generate() squizlabs#3 path/to/PHP_CodeSniffer/bin/phpcs(14): PHP_CodeSniffer\Runner->runPHPCS() squizlabs#4 {main} thrown in path/to/PHP_CodeSniffer/src/Generators/Markdown.php on line 253 ``` * Fatal error when a code element contains no textual content: ``` Fatal error: Uncaught Error: Call to a member function getAttribute() on null in path/to/PHP_CodeSniffer/src/Generators/Markdown.php:246 Stack trace: #0 path/to/PHP_CodeSniffer/src/Generators/Markdown.php(139): PHP_CodeSniffer\Generators\Markdown->getFormattedCodeComparisonBlock(Object(DOMElement)) #1 path/to/PHP_CodeSniffer/src/Generators/Markdown.php(39): PHP_CodeSniffer\Generators\Markdown->processSniff(Object(DOMElement)) squizlabs#2 path/to/PHP_CodeSniffer/src/Runner.php(99): PHP_CodeSniffer\Generators\Markdown->generate() squizlabs#3 path/to/PHP_CodeSniffer/bin/phpcs(14): PHP_CodeSniffer\Runner->runPHPCS() squizlabs#4 {main} thrown in path/to/PHP_CodeSniffer/src/Generators/Markdown.php on line 246 ``` Both of these fatals are fixed by adding defensive coding validating that there are (at least) two code blocks to the `getFormattedCodeComparisonBlock()` methods for all three generator classes.
- Loading branch information
Showing
61 changed files
with
1,836 additions
and
63 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
88 changes: 88 additions & 0 deletions
88
...s/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMismatchedCodeElms.html
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,88 @@ | ||
<html> | ||
<head> | ||
<title>GeneratorTest Coding Standards</title> | ||
<style> | ||
body { | ||
background-color: #FFFFFF; | ||
font-size: 14px; | ||
font-family: Arial, Helvetica, sans-serif; | ||
color: #000000; | ||
} | ||
|
||
h1 { | ||
color: #666666; | ||
font-size: 20px; | ||
font-weight: bold; | ||
margin-top: 0px; | ||
background-color: #E6E7E8; | ||
padding: 20px; | ||
border: 1px solid #BBBBBB; | ||
} | ||
|
||
h2 { | ||
color: #00A5E3; | ||
font-size: 16px; | ||
font-weight: normal; | ||
margin-top: 50px; | ||
} | ||
|
||
.code-comparison { | ||
width: 100%; | ||
} | ||
|
||
.code-comparison td { | ||
border: 1px solid #CCCCCC; | ||
} | ||
|
||
.code-comparison-title, .code-comparison-code { | ||
font-family: Arial, Helvetica, sans-serif; | ||
font-size: 12px; | ||
color: #000000; | ||
vertical-align: top; | ||
padding: 4px; | ||
width: 50%; | ||
background-color: #F1F1F1; | ||
line-height: 15px; | ||
} | ||
|
||
.code-comparison-code { | ||
font-family: Courier; | ||
background-color: #F9F9F9; | ||
} | ||
|
||
.code-comparison-highlight { | ||
background-color: #DDF1F7; | ||
border: 1px solid #00A5E3; | ||
line-height: 15px; | ||
} | ||
|
||
.tag-line { | ||
text-align: center; | ||
width: 100%; | ||
margin-top: 30px; | ||
font-size: 12px; | ||
} | ||
|
||
.tag-line a { | ||
color: #000000; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>GeneratorTest Coding Standards</h1> | ||
<a name="Code-Comparison,-mismatched-code-blocks" /> | ||
<h2>Code Comparison, mismatched code blocks</h2> | ||
<p class="text">This doc has two code elements, one only has a title, one has actual code. Unbalanced</p> | ||
<table class="code-comparison"> | ||
<tr> | ||
<td class="code-comparison-title">Code title</td> | ||
<td class="code-comparison-title"></td> | ||
</tr> | ||
<tr> | ||
<td class="code-comparison-code"></td> | ||
<td class="code-comparison-code">$a = 'Example code';</td> | ||
</tr> | ||
</table> | ||
<div class="tag-line">Documentation generated on #REDACTED# by <a href="https://github.com/PHPCSStandards/PHP_CodeSniffer">PHP_CodeSniffer #VERSION#</a></div> | ||
</body> | ||
</html> |
25 changes: 25 additions & 0 deletions
25
...enerators/Expectations/ExpectedOutputInvalidCodeComparisonMismatchedCodeElms.md
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,25 @@ | ||
# GeneratorTest Coding Standard | ||
|
||
## Code Comparison, mismatched code blocks | ||
|
||
This doc has two code elements, one only has a title, one has actual code. Unbalanced | ||
<table> | ||
<tr> | ||
<th>Code title</th> | ||
<th></th> | ||
</tr> | ||
<tr> | ||
<td> | ||
|
||
|
||
|
||
</td> | ||
<td> | ||
|
||
$a = 'Example code'; | ||
|
||
</td> | ||
</tr> | ||
</table> | ||
|
||
Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer) |
13 changes: 13 additions & 0 deletions
13
tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMismatchedCodeElms.txt
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,13 @@ | ||
|
||
-------------------------------------------------------------------------- | ||
| GENERATORTEST CODING STANDARD: CODE COMPARISON, MISMATCHED CODE BLOCKS | | ||
-------------------------------------------------------------------------- | ||
|
||
This doc has two code elements, one only has a title, one has actual code. Unbalanced | ||
|
||
----------------------------------------- CODE COMPARISON ------------------------------------------ | ||
| Code title | | | ||
---------------------------------------------------------------------------------------------------- | ||
| | $a = 'Example code'; | | ||
---------------------------------------------------------------------------------------------------- | ||
|
78 changes: 78 additions & 0 deletions
78
tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMissingCodeElm.html
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,78 @@ | ||
<html> | ||
<head> | ||
<title>GeneratorTest Coding Standards</title> | ||
<style> | ||
body { | ||
background-color: #FFFFFF; | ||
font-size: 14px; | ||
font-family: Arial, Helvetica, sans-serif; | ||
color: #000000; | ||
} | ||
|
||
h1 { | ||
color: #666666; | ||
font-size: 20px; | ||
font-weight: bold; | ||
margin-top: 0px; | ||
background-color: #E6E7E8; | ||
padding: 20px; | ||
border: 1px solid #BBBBBB; | ||
} | ||
|
||
h2 { | ||
color: #00A5E3; | ||
font-size: 16px; | ||
font-weight: normal; | ||
margin-top: 50px; | ||
} | ||
|
||
.code-comparison { | ||
width: 100%; | ||
} | ||
|
||
.code-comparison td { | ||
border: 1px solid #CCCCCC; | ||
} | ||
|
||
.code-comparison-title, .code-comparison-code { | ||
font-family: Arial, Helvetica, sans-serif; | ||
font-size: 12px; | ||
color: #000000; | ||
vertical-align: top; | ||
padding: 4px; | ||
width: 50%; | ||
background-color: #F1F1F1; | ||
line-height: 15px; | ||
} | ||
|
||
.code-comparison-code { | ||
font-family: Courier; | ||
background-color: #F9F9F9; | ||
} | ||
|
||
.code-comparison-highlight { | ||
background-color: #DDF1F7; | ||
border: 1px solid #00A5E3; | ||
line-height: 15px; | ||
} | ||
|
||
.tag-line { | ||
text-align: center; | ||
width: 100%; | ||
margin-top: 30px; | ||
font-size: 12px; | ||
} | ||
|
||
.tag-line a { | ||
color: #000000; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>GeneratorTest Coding Standards</h1> | ||
<a name="Code-Comparison,-missing-code-element" /> | ||
<h2>Code Comparison, missing code element</h2> | ||
<p class="text">This is a standard block.</p> | ||
<div class="tag-line">Documentation generated on #REDACTED# by <a href="https://github.com/PHPCSStandards/PHP_CodeSniffer">PHP_CodeSniffer #VERSION#</a></div> | ||
</body> | ||
</html> |
7 changes: 7 additions & 0 deletions
7
...re/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMissingCodeElm.md
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,7 @@ | ||
# GeneratorTest Coding Standard | ||
|
||
## Code Comparison, missing code element | ||
|
||
This is a standard block. | ||
|
||
Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer) |
7 changes: 7 additions & 0 deletions
7
tests/Core/Generators/Expectations/ExpectedOutputInvalidCodeComparisonMissingCodeElm.txt
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,7 @@ | ||
|
||
------------------------------------------------------------------------ | ||
| GENERATORTEST CODING STANDARD: CODE COMPARISON, MISSING CODE ELEMENT | | ||
------------------------------------------------------------------------ | ||
|
||
This is a standard block. | ||
|
Oops, something went wrong.