Skip to content

Commit 33cd903

Browse files
authored
Merge pull request #1077 from PHPCSStandards/feature/config-bug-report-file-vs-phpcbf
Config: bug fix - "reports" could get set incorrectly when in CBF mode
2 parents 726bbc1 + 46c1d3e commit 33cd903

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

src/Config.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,8 @@ public function processLongArgument($arg, $pos)
10101010
}
10111011

10121012
self::$overriddenDefaults['stdinPath'] = true;
1013-
} else if (PHP_CODESNIFFER_CBF === false && substr($arg, 0, 12) === 'report-file=') {
1014-
if (isset(self::$overriddenDefaults['reportFile']) === true) {
1013+
} else if (substr($arg, 0, 12) === 'report-file=') {
1014+
if (PHP_CODESNIFFER_CBF === true || isset(self::$overriddenDefaults['reportFile']) === true) {
10151015
break;
10161016
}
10171017

tests/Core/Config/ReportArgsTest.php

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Tests for the \PHP_CodeSniffer\Config --report, --report-file and --report-* arguments.
4+
*
5+
* @copyright 2025 PHPCSStandards and contributors
6+
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
7+
*/
8+
9+
namespace PHP_CodeSniffer\Tests\Core\Config;
10+
11+
use PHP_CodeSniffer\Tests\ConfigDouble;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Tests for the \PHP_CodeSniffer\Config --report, --report-file and --report-* arguments.
16+
*
17+
* @covers \PHP_CodeSniffer\Config::processLongArgument
18+
*/
19+
final class ReportArgsTest extends TestCase
20+
{
21+
22+
23+
/**
24+
* [CS mode] Verify that passing `--report-file` does not influence *which* reports get activated.
25+
*
26+
* @return void
27+
*/
28+
public function testReportFileDoesNotSetReportsCs()
29+
{
30+
if (PHP_CODESNIFFER_CBF === true) {
31+
$this->markTestSkipped('This test needs CS mode to run');
32+
}
33+
34+
$config = new ConfigDouble(['--report-file='.__DIR__.'/report.txt']);
35+
36+
$this->assertTrue(is_string($config->reportFile));
37+
$this->assertStringEndsWith('/report.txt', $config->reportFile);
38+
$this->assertSame(['full' => null], $config->reports);
39+
40+
}//end testReportFileDoesNotSetReportsCs()
41+
42+
43+
/**
44+
* [CBF mode] Verify that passing `--report-file` does not influence *which* reports get activated.
45+
*
46+
* @group CBF
47+
*
48+
* @return void
49+
*/
50+
public function testReportFileDoesNotSetReportsCbf()
51+
{
52+
if (PHP_CODESNIFFER_CBF === false) {
53+
$this->markTestSkipped('This test needs CBF mode to run');
54+
}
55+
56+
$config = new ConfigDouble(['--report-file='.__DIR__.'/report.txt']);
57+
58+
$this->assertNull($config->reportFile);
59+
$this->assertSame(['full' => null], $config->reports);
60+
61+
}//end testReportFileDoesNotSetReportsCbf()
62+
63+
64+
}//end class

0 commit comments

Comments
 (0)