'.implode('', $lines).'
'.PHP_EOL; + return ''.implode('', $lines).'
'.PHP_EOL; - }//end printTextBlock() + }//end getFormattedTextBlock() /** @@ -275,9 +359,29 @@ protected function printTextBlock(DOMNode $node) * * @param \DOMNode $node The DOMNode object for the code comparison block. * + * @deprecated 3.12.0 Use HTML::getFormattedCodeComparisonBlock() instead. + * + * @codeCoverageIgnore + * * @return void */ protected function printCodeComparisonBlock(DOMNode $node) + { + echo $this->getFormattedCodeComparisonBlock($node); + + }//end printCodeComparisonBlock() + + + /** + * Format a code comparison block found in a standard. + * + * @param \DOMNode $node The DOMNode object for the code comparison block. + * + * @since 3.12.0 Replaces the deprecated HTML::printCodeComparisonBlock() method. + * + * @return string + */ + protected function getFormattedCodeComparisonBlock(DOMNode $node) { $codeBlocks = $node->getElementsByTagName('code'); @@ -299,18 +403,20 @@ protected function printCodeComparisonBlock(DOMNode $node) $second = str_replace('', '', $second); $second = str_replace('', '', $second); - echo ' '.PHP_EOL; - echo ' '.PHP_EOL; - echo " ".PHP_EOL; - echo " ".PHP_EOL; - echo ' '.PHP_EOL; - echo ' '.PHP_EOL; - echo " ".PHP_EOL; - echo " ".PHP_EOL; - echo ' '.PHP_EOL; - echo '$firstTitle | $secondTitle |
$first | $second |
$firstTitle | $secondTitle |
$first | $second |
$firstTitle | $secondTitle |
---|---|
'.PHP_EOL.PHP_EOL; - echo " $first".PHP_EOL.PHP_EOL; - echo ' | '.PHP_EOL.PHP_EOL; - echo " $second".PHP_EOL.PHP_EOL; - echo ' |
$firstTitle | $secondTitle |
---|---|
'.PHP_EOL.PHP_EOL; + $output .= " $first".PHP_EOL.PHP_EOL; + $output .= ' | '.PHP_EOL.PHP_EOL; + $output .= " $second".PHP_EOL.PHP_EOL; + $output .= ' |
element at the wrong level' => [
'sniffs' => 'StandardWithDocs.Unsupported.ElementAtWrongLevel',
- 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.html',
+ 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputEmpty.txt',
],
'Unsupported: one correct elm, one at wrong level' => [
'sniffs' => 'StandardWithDocs.Unsupported.OneElmAtWrongLevel',
@@ -187,7 +187,7 @@ public static function dataDocSpecifics()
],
'Unsupported: unknown element' => [
'sniffs' => 'StandardWithDocs.Unsupported.UnknownElement',
- 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedUnknownElement.html',
+ 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputEmpty.txt',
],
];
@@ -210,10 +210,16 @@ public function testFooter()
$regex .= 'Documentation generated on [A-Z][a-z]{2}, [0-9]{2} [A-Z][a-z]{2} 20[0-9]{2} [0-2][0-9](?::[0-5][0-9]){2} [+-][0-9]{4}';
$regex .= ' by PHP_CodeSniffer [3-9]\.[0-9]+.[0-9]+';
$regex .= '\R \R\R$`';
- $this->expectOutputRegex($regex);
$generator = new HTMLDouble($ruleset);
- $generator->printRealFooter();
+ $footer = $generator->getRealFooter();
+
+ if (method_exists($this, 'assertMatchesRegularExpression') === true) {
+ $this->assertMatchesRegularExpression($regex, $footer);
+ } else {
+ // PHPUnit < 9.1.0.
+ $this->assertRegExp($regex, $footer);
+ }
}//end testFooter()
@@ -235,11 +241,8 @@ public function testFooterResetsErrorReportingToOriginalSetting()
$config = new ConfigDouble(["--standard=$standard"]);
$ruleset = new Ruleset($config);
- // We know there will be output, but we're not interested in the output for this test.
- ob_start();
$generator = new HTMLDouble($ruleset);
- $generator->printRealFooter();
- ob_end_clean();
+ $generator->getRealFooter();
$this->assertSame($expected, error_reporting());
@@ -277,11 +280,8 @@ public function testFooterDoesntThrowWarningOnMissingTimezone()
$config = new ConfigDouble(["--standard=$standard"]);
$ruleset = new Ruleset($config);
- // We know there will be output, but we're not interested in the output for this test.
- ob_start();
$generator = new HTMLDouble($ruleset);
- $generator->printRealFooter();
- ob_end_clean();
+ $generator->getRealFooter();
// Reset the timezone to its original state.
ini_set('date.timezone', $originalIni);
diff --git a/tests/Core/Generators/MarkdownTest.php b/tests/Core/Generators/MarkdownTest.php
index 54f60d075e..edc9db8c31 100644
--- a/tests/Core/Generators/MarkdownTest.php
+++ b/tests/Core/Generators/MarkdownTest.php
@@ -175,7 +175,7 @@ public static function dataDocSpecifics()
],
'Unsupported: element at the wrong level' => [
'sniffs' => 'StandardWithDocs.Unsupported.ElementAtWrongLevel',
- 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.md',
+ 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputEmpty.txt',
],
'Unsupported: one correct elm, one at wrong level' => [
'sniffs' => 'StandardWithDocs.Unsupported.OneElmAtWrongLevel',
@@ -187,7 +187,7 @@ public static function dataDocSpecifics()
],
'Unsupported: unknown element' => [
'sniffs' => 'StandardWithDocs.Unsupported.UnknownElement',
- 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedUnknownElement.md',
+ 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputEmpty.txt',
],
];
@@ -208,10 +208,16 @@ public function testFooter()
$regex = '`^\RDocumentation generated on [A-Z][a-z]{2}, [0-9]{2} [A-Z][a-z]{2} 20[0-9]{2} [0-2][0-9](?::[0-5][0-9]){2} [+-][0-9]{4}';
$regex .= ' by \[PHP_CodeSniffer [3-9]\.[0-9]+.[0-9]+\]\(https://github\.com/PHPCSStandards/PHP_CodeSniffer\)\R$`';
- $this->expectOutputRegex($regex);
$generator = new MarkdownDouble($ruleset);
- $generator->printRealFooter();
+ $footer = $generator->getRealFooter();
+
+ if (method_exists($this, 'assertMatchesRegularExpression') === true) {
+ $this->assertMatchesRegularExpression($regex, $footer);
+ } else {
+ // PHPUnit < 9.1.0.
+ $this->assertRegExp($regex, $footer);
+ }
}//end testFooter()
@@ -233,11 +239,8 @@ public function testFooterResetsErrorReportingToOriginalSetting()
$config = new ConfigDouble(["--standard=$standard"]);
$ruleset = new Ruleset($config);
- // We know there will be output, but we're not interested in the output for this test.
- ob_start();
$generator = new MarkdownDouble($ruleset);
- $generator->printRealFooter();
- ob_end_clean();
+ $generator->getRealFooter();
$this->assertSame($expected, error_reporting());
@@ -275,11 +278,8 @@ public function testFooterDoesntThrowWarningOnMissingTimezone()
$config = new ConfigDouble(["--standard=$standard"]);
$ruleset = new Ruleset($config);
- // We know there will be output, but we're not interested in the output for this test.
- ob_start();
$generator = new MarkdownDouble($ruleset);
- $generator->printRealFooter();
- ob_end_clean();
+ $generator->getRealFooter();
// Reset the timezone to its original state.
ini_set('date.timezone', $originalIni);
diff --git a/tests/Core/Generators/TextTest.php b/tests/Core/Generators/TextTest.php
index b0c5f2807f..5b157bd774 100644
--- a/tests/Core/Generators/TextTest.php
+++ b/tests/Core/Generators/TextTest.php
@@ -175,7 +175,7 @@ public static function dataDocSpecifics()
],
'Unsupported: element at the wrong level' => [
'sniffs' => 'StandardWithDocs.Unsupported.ElementAtWrongLevel',
- 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedElementAtWrongLevel.txt',
+ 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputEmpty.txt',
],
'Unsupported: one correct elm, one at wrong level' => [
'sniffs' => 'StandardWithDocs.Unsupported.OneElmAtWrongLevel',
@@ -187,7 +187,7 @@ public static function dataDocSpecifics()
],
'Unsupported: unknown element' => [
'sniffs' => 'StandardWithDocs.Unsupported.UnknownElement',
- 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputUnsupportedUnknownElement.txt',
+ 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputEmpty.txt',
],
];