Skip to content

Commit 4920a3d

Browse files
committed
Always output version header when running the script
1 parent 865d7ce commit 4920a3d

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed

Scripts/DocCodeExamples/Check.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public function __construct(
131131
*/
132132
public function run(): int
133133
{
134+
$this->writer->toStderr($this->config->getVersion());
135+
134136
$exitCode = 0;
135137

136138
if (empty($this->xmlFiles)) {

Tests/DocCodeExamples/ConfigTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,10 @@ public function testHelpOutput()
402402
*/
403403
public function testVersionOutput($command)
404404
{
405-
$regex = '`^PHPCSDevTools: XML documentation code examples checker version'
406-
. ' [0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}(?:-(?:alpha|beta|RC)\S+)?'
407-
. '[\r\n]+by PHPCSDevTools Contributors[\r\n]*$`';
408-
409405
$_SERVER['argv'] = \explode(' ', $command);
410406
new Config($this->writer);
411407

412-
$this->assertMatchesRegularExpression($regex, $this->writer->getStdout());
408+
$this->assertMatchesRegularExpression(VersionTestUtils::VERSION_HEADER_REGEX, $this->writer->getStdout());
413409
}
414410

415411
/**

Tests/DocCodeExamples/EndToEndTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,24 @@ public function testScriptBasicExecution(string $cliArgs, int $expectedExitCode,
109109
$this->assertEmpty($result['stdout']);
110110

111111
if (empty($expectedStderr)) {
112-
$this->assertEmpty($result['stderr']);
112+
$this->assertStderrContainsOnlyScriptHeader($result['stderr']);
113113
} else {
114114
$this->assertMatchesRegularExpression($expectedStderr, $result['stderr']);
115115
}
116116
}
117117

118+
/**
119+
* Assert that stderr contains only the script header and nothing else.
120+
*
121+
* @param string $stderr The stderr output to check.
122+
*
123+
* @return void
124+
*/
125+
protected function assertStderrContainsOnlyScriptHeader(string $stderr)
126+
{
127+
$this->assertMatchesRegularExpression(VersionTestUtils::VERSION_HEADER_REGEX, $stderr);
128+
}
129+
118130
/**
119131
* Data provider for testScriptBasicExecution.
120132
*
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* PHPCSDevTools, tools for PHP_CodeSniffer sniff developers.
4+
*
5+
* @package PHPCSDevTools
6+
* @copyright 2019 PHPCSDevTools Contributors
7+
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
8+
* @link https://github.com/PHPCSStandards/PHPCSDevTools
9+
*/
10+
11+
namespace PHPCSDevTools\Tests\DocCodeExamples;
12+
13+
/**
14+
* Utility class for version headeroutput testing.
15+
*/
16+
class VersionTestUtils
17+
{
18+
const VERSION_HEADER_REGEX = '`^PHPCSDevTools: XML documentation code examples checker version'
19+
. ' [0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}(?:-(?:alpha|beta|RC)\S+)?'
20+
. '[\r\n]+by PHPCSDevTools Contributors[\r\n]*$`';
21+
}

phpcs.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,9 @@
143143
<exclude-pattern>/Tests/DocCodeExamples/*\.php$</exclude-pattern>
144144
</rule>
145145

146+
<rule ref="PHPCompatibility.InitialValue.NewConstantScalarExpressions.constFound">
147+
<exclude-pattern>/Scripts/DocCodeExamples/*\.php$</exclude-pattern>
148+
<exclude-pattern>/Tests/DocCodeExamples/*\.php$</exclude-pattern>
149+
</rule>
150+
146151
</ruleset>

0 commit comments

Comments
 (0)