From eedd9b93f195040601054ec6345377105708ac13 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 4 Nov 2024 13:19:18 +0100 Subject: [PATCH] Generators: add tests covering handling of unsupported doc structures This adds a 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. --- ...dOutputUnsupportedElementAtWrongLevel.html | 77 ++++++++++++++++ ...tedOutputUnsupportedElementAtWrongLevel.md | 5 ++ ...edOutputUnsupportedElementAtWrongLevel.txt | 5 ++ ...edOutputUnsupportedOneElmAtWrongLevel.html | 78 ++++++++++++++++ ...ctedOutputUnsupportedOneElmAtWrongLevel.md | 6 ++ ...tedOutputUnsupportedOneElmAtWrongLevel.txt | 7 ++ ...tputUnsupportedSuperfluousCodeElement.html | 88 +++++++++++++++++++ ...OutputUnsupportedSuperfluousCodeElement.md | 24 +++++ ...utputUnsupportedSuperfluousCodeElement.txt | 13 +++ ...pectedOutputUnsupportedUnknownElement.html | 77 ++++++++++++++++ ...ExpectedOutputUnsupportedUnknownElement.md | 5 ++ ...xpectedOutputUnsupportedUnknownElement.txt | 5 ++ .../ElementAtWrongLevelStandard.xml | 8 ++ .../OneElmAtWrongLevelStandard.xml | 13 +++ .../SuperfluousCodeElementStandard.xml | 24 +++++ .../Unsupported/UnknownElementStandard.xml | 7 ++ .../Unsupported/ElementAtWrongLevelSniff.php | 12 +++ .../Unsupported/OneElmAtWrongLevelSniff.php | 12 +++ .../SuperfluousCodeElementSniff.php | 12 +++ .../Unsupported/UnknownElementSniff.php | 12 +++ tests/Core/Generators/HTMLTest.php | 16 ++++ tests/Core/Generators/MarkdownTest.php | 16 ++++ tests/Core/Generators/TextTest.php | 16 ++++ 23 files changed, 538 insertions(+) create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.html create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.md create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.txt create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.html create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.md create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.txt create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.html create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.md create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.txt create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputUnsupportedUnknownElement.html create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputUnsupportedUnknownElement.md create mode 100644 tests/Core/Generators/Expectations/ExpectedOutputUnsupportedUnknownElement.txt create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/ElementAtWrongLevelStandard.xml create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/OneElmAtWrongLevelStandard.xml create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/SuperfluousCodeElementStandard.xml create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/UnknownElementStandard.xml create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Unsupported/ElementAtWrongLevelSniff.php create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Unsupported/OneElmAtWrongLevelSniff.php create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Unsupported/SuperfluousCodeElementSniff.php create mode 100644 tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Unsupported/UnknownElementSniff.php diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.html b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.html new file mode 100644 index 0000000000..dfa5670f0e --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.html @@ -0,0 +1,77 @@ + + + GeneratorTest Coding Standards + + + +

GeneratorTest Coding Standards

+ +

Code element at wrong level

+
Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
+ + diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.md b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.md new file mode 100644 index 0000000000..669ea0f4c6 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.md @@ -0,0 +1,5 @@ +# GeneratorTest Coding Standard + +## Code element at wrong level + +Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer) diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.txt b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.txt new file mode 100644 index 0000000000..940832ced1 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.txt @@ -0,0 +1,5 @@ + +-------------------------------------------------------------- +| GENERATORTEST CODING STANDARD: CODE ELEMENT AT WRONG LEVEL | +-------------------------------------------------------------- + diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.html b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.html new file mode 100644 index 0000000000..dc86a6c42f --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.html @@ -0,0 +1,78 @@ + + + GeneratorTest Coding Standards + + + +

GeneratorTest Coding Standards

+ +

One element correct, one element wrong level

+

This is a standard block at the correct level.

+
Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
+ + diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.md b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.md new file mode 100644 index 0000000000..f6eda21036 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.md @@ -0,0 +1,6 @@ +# GeneratorTest Coding Standard + +## One element correct, one element wrong level +This is a standard block at the correct level. + +Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer) diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.txt b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.txt new file mode 100644 index 0000000000..4d1aaeaa12 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.txt @@ -0,0 +1,7 @@ + +------------------------------------------------------------------------------- +| GENERATORTEST CODING STANDARD: ONE ELEMENT CORRECT, ONE ELEMENT WRONG LEVEL | +------------------------------------------------------------------------------- + +This is a standard block at the correct level. + diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.html b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.html new file mode 100644 index 0000000000..967381e3a9 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.html @@ -0,0 +1,88 @@ + + + GeneratorTest Coding Standards + + + +

GeneratorTest Coding Standards

+ +

Superfluous code element

+

This is a standard block.

+ + + + + + + + + +
Valid: Checking handling of blank lines.Invalid: Checking handling of blank lines.
$valid = true;$invalid = true;
+
Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
+ + diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.md b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.md new file mode 100644 index 0000000000..131c6cc45a --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.md @@ -0,0 +1,24 @@ +# GeneratorTest Coding Standard + +## Superfluous code element +This is a standard block. + + + + + + + + + +
Valid: Checking handling of blank lines.Invalid: Checking handling of blank lines.
+ + $valid = true; + + + + $invalid = true; + +
+ +Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer) diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.txt b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.txt new file mode 100644 index 0000000000..1307eebfd1 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.txt @@ -0,0 +1,13 @@ + +----------------------------------------------------------- +| GENERATORTEST CODING STANDARD: SUPERFLUOUS CODE ELEMENT | +----------------------------------------------------------- + +This is a standard block. + +----------------------------------------- CODE COMPARISON ------------------------------------------ +| Valid: Checking handling of blank lines. | Invalid: Checking handling of blank lines. | +---------------------------------------------------------------------------------------------------- +| $valid = true; | $invalid = true; | +---------------------------------------------------------------------------------------------------- + diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedUnknownElement.html b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedUnknownElement.html new file mode 100644 index 0000000000..770d08bbc7 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedUnknownElement.html @@ -0,0 +1,77 @@ + + + GeneratorTest Coding Standards + + + +

GeneratorTest Coding Standards

+ +

Unknown element

+
Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
+ + diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedUnknownElement.md b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedUnknownElement.md new file mode 100644 index 0000000000..a8be8f9928 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedUnknownElement.md @@ -0,0 +1,5 @@ +# GeneratorTest Coding Standard + +## Unknown element + +Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer) diff --git a/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedUnknownElement.txt b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedUnknownElement.txt new file mode 100644 index 0000000000..3e2f564720 --- /dev/null +++ b/tests/Core/Generators/Expectations/ExpectedOutputUnsupportedUnknownElement.txt @@ -0,0 +1,5 @@ + +-------------------------------------------------- +| GENERATORTEST CODING STANDARD: UNKNOWN ELEMENT | +-------------------------------------------------- + diff --git a/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/ElementAtWrongLevelStandard.xml b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/ElementAtWrongLevelStandard.xml new file mode 100644 index 0000000000..68519dd2be --- /dev/null +++ b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/ElementAtWrongLevelStandard.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/OneElmAtWrongLevelStandard.xml b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/OneElmAtWrongLevelStandard.xml new file mode 100644 index 0000000000..6c1dd164aa --- /dev/null +++ b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/OneElmAtWrongLevelStandard.xml @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/SuperfluousCodeElementStandard.xml b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/SuperfluousCodeElementStandard.xml new file mode 100644 index 0000000000..333786a337 --- /dev/null +++ b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/SuperfluousCodeElementStandard.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + diff --git a/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/UnknownElementStandard.xml b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/UnknownElementStandard.xml new file mode 100644 index 0000000000..c9ec3227fa --- /dev/null +++ b/tests/Core/Generators/Fixtures/StandardWithDocs/Docs/Unsupported/UnknownElementStandard.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Unsupported/ElementAtWrongLevelSniff.php b/tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Unsupported/ElementAtWrongLevelSniff.php new file mode 100644 index 0000000000..6ed5c2be69 --- /dev/null +++ b/tests/Core/Generators/Fixtures/StandardWithDocs/Sniffs/Unsupported/ElementAtWrongLevelSniff.php @@ -0,0 +1,12 @@ + 'StandardWithDocs.Content.CodeComparisonLineLength', 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputCodeComparisonLineLength.html', ], + 'Unsupported: element at the wrong level' => [ + 'sniffs' => 'StandardWithDocs.Unsupported.ElementAtWrongLevel', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.html', + ], + 'Unsupported: one correct elm, one at wrong level' => [ + 'sniffs' => 'StandardWithDocs.Unsupported.OneElmAtWrongLevel', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.html', + ], + 'Unsupported: superfluous code element' => [ + 'sniffs' => 'StandardWithDocs.Unsupported.SuperfluousCodeElement', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.html', + ], + 'Unsupported: unknown element' => [ + 'sniffs' => 'StandardWithDocs.Unsupported.UnknownElement', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedUnknownElement.html', + ], ]; }//end dataDocSpecifics() diff --git a/tests/Core/Generators/MarkdownTest.php b/tests/Core/Generators/MarkdownTest.php index 515b832c59..54f60d075e 100644 --- a/tests/Core/Generators/MarkdownTest.php +++ b/tests/Core/Generators/MarkdownTest.php @@ -173,6 +173,22 @@ public static function dataDocSpecifics() 'sniffs' => 'StandardWithDocs.Content.CodeComparisonLineLength', 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputCodeComparisonLineLength.md', ], + 'Unsupported: element at the wrong level' => [ + 'sniffs' => 'StandardWithDocs.Unsupported.ElementAtWrongLevel', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.md', + ], + 'Unsupported: one correct elm, one at wrong level' => [ + 'sniffs' => 'StandardWithDocs.Unsupported.OneElmAtWrongLevel', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.md', + ], + 'Unsupported: superfluous code element' => [ + 'sniffs' => 'StandardWithDocs.Unsupported.SuperfluousCodeElement', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.md', + ], + 'Unsupported: unknown element' => [ + 'sniffs' => 'StandardWithDocs.Unsupported.UnknownElement', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedUnknownElement.md', + ], ]; }//end dataDocSpecifics() diff --git a/tests/Core/Generators/TextTest.php b/tests/Core/Generators/TextTest.php index fd7388d256..b0c5f2807f 100644 --- a/tests/Core/Generators/TextTest.php +++ b/tests/Core/Generators/TextTest.php @@ -173,6 +173,22 @@ public static function dataDocSpecifics() 'sniffs' => 'StandardWithDocs.Content.CodeComparisonLineLength', 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputCodeComparisonLineLength.txt', ], + 'Unsupported: element at the wrong level' => [ + 'sniffs' => 'StandardWithDocs.Unsupported.ElementAtWrongLevel', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.txt', + ], + 'Unsupported: one correct elm, one at wrong level' => [ + 'sniffs' => 'StandardWithDocs.Unsupported.OneElmAtWrongLevel', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedOneElmAtWrongLevel.txt', + ], + 'Unsupported: superfluous code element' => [ + 'sniffs' => 'StandardWithDocs.Unsupported.SuperfluousCodeElement', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedSuperfluousCodeElement.txt', + ], + 'Unsupported: unknown element' => [ + 'sniffs' => 'StandardWithDocs.Unsupported.UnknownElement', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedUnknownElement.txt', + ], ]; }//end dataDocSpecifics()