Skip to content

Commit d95f2ad

Browse files
committed
Util/HelpTest: test CBF-only code
Now PR 703 has unblocked testing of PHPCBF-only code, the `// @codeCoverageIgnore` annotation for this CBF-only code in the `Util\Help` class can be removed and this code can now be tested. This commit adjusts the relevant test method to ensure that the CBF-only code is also tested.
1 parent eedd9b9 commit d95f2ad

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

src/Util/Help.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ private function printUsage()
270270
{
271271
$command = 'phpcs';
272272
if (defined('PHP_CODESNIFFER_CBF') === true && PHP_CODESNIFFER_CBF === true) {
273-
$command = 'phpcbf'; // @codeCoverageIgnore
273+
$command = 'phpcbf';
274274
}
275275

276276
$this->printCategoryHeader('Usage');

tests/Core/Util/Help/HelpTest.php

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Tests to verify that the "help" command functions as expected.
44
*
55
* @author Juliette Reinders Folmer <[email protected]>
6-
* @copyright 2024 Juliette Reinders Folmer. All rights reserved.
6+
* @copyright 2024 PHPCSStandards and contributors
77
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
88
*/
99

@@ -378,7 +378,7 @@ public static function dataOptionFilteringSpacerHandling()
378378

379379

380380
/**
381-
* Test that if no short/long options are passed, only usage information is displayed (and displayed correctly).
381+
* Test that if no short/long options are passed, only usage information is displayed (CS mode).
382382
*
383383
* @param array<string> $cliArgs Command line arguments.
384384
* @param string $expectedRegex Regex to validate expected output.
@@ -387,15 +387,59 @@ public static function dataOptionFilteringSpacerHandling()
387387
*
388388
* @return void
389389
*/
390-
public function testDisplayUsage($cliArgs, $expectedRegex)
390+
public function testDisplayUsageCS($cliArgs, $expectedRegex)
391+
{
392+
if (PHP_CODESNIFFER_CBF === true) {
393+
$this->markTestSkipped('This test needs CS mode to run');
394+
}
395+
396+
$expectedRegex = str_replace('phpc(bf|s)', 'phpcs', $expectedRegex);
397+
$this->verifyDisplayUsage($cliArgs, $expectedRegex);
398+
399+
}//end testDisplayUsageCS()
400+
401+
402+
/**
403+
* Test that if no short/long options are passed, only usage information is displayed (CBF mode).
404+
*
405+
* @param array<string> $cliArgs Command line arguments.
406+
* @param string $expectedRegex Regex to validate expected output.
407+
*
408+
* @dataProvider dataDisplayUsage
409+
* @group CBF
410+
*
411+
* @return void
412+
*/
413+
public function testDisplayUsageCBF($cliArgs, $expectedRegex)
414+
{
415+
if (PHP_CODESNIFFER_CBF === false) {
416+
$this->markTestSkipped('This test needs CBF mode to run');
417+
}
418+
419+
$expectedRegex = str_replace('phpc(bf|s)', 'phpcbf', $expectedRegex);
420+
$this->verifyDisplayUsage($cliArgs, $expectedRegex);
421+
422+
}//end testDisplayUsageCBF()
423+
424+
425+
/**
426+
* Helper method to test that if no short/long options are passed, only usage information is displayed
427+
* (and displayed correctly).
428+
*
429+
* @param array<string> $cliArgs Command line arguments.
430+
* @param string $expectedRegex Regex to validate expected output.
431+
*
432+
* @return void
433+
*/
434+
private function verifyDisplayUsage($cliArgs, $expectedRegex)
391435
{
392436
$help = new Help(new ConfigDouble($cliArgs), []);
393437

394438
$this->expectOutputRegex($expectedRegex);
395439

396440
$help->display();
397441

398-
}//end testDisplayUsage()
442+
}//end verifyDisplayUsage()
399443

400444

401445
/**

0 commit comments

Comments
 (0)