Skip to content

Commit

Permalink
Util/HelpTest: test CBF-only code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jrfnl committed Nov 24, 2024
1 parent ceebf9d commit 08f41df
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Util/Help.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private function printUsage()
{
$command = 'phpcs';
if (defined('PHP_CODESNIFFER_CBF') === true && PHP_CODESNIFFER_CBF === true) {
$command = 'phpcbf'; // @codeCoverageIgnore
$command = 'phpcbf';
}

$this->printCategoryHeader('Usage');
Expand Down
52 changes: 48 additions & 4 deletions tests/Core/Util/Help/HelpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Tests to verify that the "help" command functions as expected.
*
* @author Juliette Reinders Folmer <[email protected]>
* @copyright 2024 Juliette Reinders Folmer. All rights reserved.
* @copyright 2024 PHPCSStandards and contributors
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/

Expand Down Expand Up @@ -386,7 +386,7 @@ public static function dataOptionFilteringSpacerHandling()


/**
* Test that if no short/long options are passed, only usage information is displayed (and displayed correctly).
* Test that if no short/long options are passed, only usage information is displayed (CS mode).
*
* @param array<string> $cliArgs Command line arguments.
* @param string $expectedRegex Regex to validate expected output.
Expand All @@ -395,15 +395,59 @@ public static function dataOptionFilteringSpacerHandling()
*
* @return void
*/
public function testDisplayUsage($cliArgs, $expectedRegex)
public function testDisplayUsageCS($cliArgs, $expectedRegex)
{
if (PHP_CODESNIFFER_CBF === true) {
$this->markTestSkipped('This test needs CS mode to run');
}

$expectedRegex = str_replace('phpc(bf|s)', 'phpcs', $expectedRegex);
$this->verifyDisplayUsage($cliArgs, $expectedRegex);

}//end testDisplayUsageCS()


/**
* Test that if no short/long options are passed, only usage information is displayed (CBF mode).
*
* @param array<string> $cliArgs Command line arguments.
* @param string $expectedRegex Regex to validate expected output.
*
* @dataProvider dataDisplayUsage
* @group CBF
*
* @return void
*/
public function testDisplayUsageCBF($cliArgs, $expectedRegex)
{
if (PHP_CODESNIFFER_CBF === false) {
$this->markTestSkipped('This test needs CBF mode to run');
}

$expectedRegex = str_replace('phpc(bf|s)', 'phpcbf', $expectedRegex);
$this->verifyDisplayUsage($cliArgs, $expectedRegex);

}//end testDisplayUsageCBF()


/**
* Helper method to test that if no short/long options are passed, only usage information is displayed
* (and displayed correctly).
*
* @param array<string> $cliArgs Command line arguments.
* @param string $expectedRegex Regex to validate expected output.
*
* @return void
*/
private function verifyDisplayUsage($cliArgs, $expectedRegex)
{
$help = new Help(new ConfigDouble($cliArgs), []);

$this->expectOutputRegex($expectedRegex);

$help->display();

}//end testDisplayUsage()
}//end verifyDisplayUsage()


/**
Expand Down

0 comments on commit 08f41df

Please sign in to comment.