Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Util/HelpTest: test CBF-only code #725

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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