Skip to content

Tests should pass in CBF mode #1076

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

Merged
merged 4 commits into from
May 4, 2025
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
13 changes: 10 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,28 @@ jobs:
composer-options: ${{ matrix.php == '8.5' && '--ignore-platform-req=php+' || '' }}
custom-cache-suffix: $(date -u "+%Y-%m")

# Note: The code style check is run multiple times against every PHP version
# as it also acts as an integration test.
- name: 'PHPCS: set the path to PHP'
run: php "bin/phpcs" --config-set php_path php

- name: 'PHPUnit: run the full test suite without code coverage'
if: ${{ matrix.skip_tests != true }}
run: php "vendor/bin/phpunit" tests/AllTests.php --no-coverage

# Do one test run against the complete test suite in CBF mode to ensure all tests can run in CBF mode.
- name: 'PHPUnit: run the full test suite without code coverage in CBF mode (PHP 8.3 only)'
if: ${{ matrix.php == '8.3' }}
run: php "vendor/bin/phpunit" tests/AllTests.php --exclude-group nothing --no-coverage
env:
PHP_CODESNIFFER_CBF: '1'

- name: 'PHPUnit: run select tests in CBF mode'
if: ${{ matrix.skip_tests != true }}
if: ${{ matrix.skip_tests != true && matrix.php != '8.3' }}
run: php "vendor/bin/phpunit" tests/AllTests.php --group CBF --exclude-group nothing --no-coverage
env:
PHP_CODESNIFFER_CBF: '1'

# Note: The code style check is run multiple times against every PHP version
# as it also acts as an integration test.
- name: 'PHPCS: check code style without cache, no parallel'
if: ${{ matrix.custom_ini == false }}
run: php "bin/phpcs" --no-cache --parallel=1
Expand Down
16 changes: 16 additions & 0 deletions tests/Core/Config/GeneratorArgTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ final class GeneratorArgTest extends TestCase
{


/**
* Skip these tests when in CBF mode.
*
* @before
*
* @return void
*/
protected function maybeSkipTests()
{
if (PHP_CODESNIFFER_CBF === true) {
$this->markTestSkipped('The `--generator` CLI flag is only supported for the `phpcs` command');
}

}//end maybeSkipTests()


/**
* Ensure that the generator property is set when the parameter is passed a valid value.
*
Expand Down
7 changes: 6 additions & 1 deletion tests/Core/Config/SniffsExcludeArgsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ final class SniffsExcludeArgsTest extends TestCase
*/
public function testInvalid($argument, $value, $errors, $suggestion)
{
$cmd = 'phpcs';
if (PHP_CODESNIFFER_CBF === true) {
$cmd = 'phpcbf';
}

$exception = 'PHP_CodeSniffer\Exceptions\DeepExitException';
$message = 'ERROR: The --'.$argument.' option only supports sniff codes.'.PHP_EOL;
$message .= 'Sniff codes are in the form "Standard.Category.Sniff".'.PHP_EOL;
Expand All @@ -47,7 +52,7 @@ public function testInvalid($argument, $value, $errors, $suggestion)
}

$message .= PHP_EOL;
$message .= 'Run "phpcs --help" for usage information'.PHP_EOL;
$message .= "Run \"{$cmd} --help\" for usage information".PHP_EOL;
$message .= PHP_EOL;

if (method_exists($this, 'expectException') === true) {
Expand Down
18 changes: 12 additions & 6 deletions tests/Core/Ruleset/DisplayCachedMessagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,24 @@ public function testNonBlockingErrorsDoNotShowUnderSpecificCircumstances($config
*/
public static function dataSelectiveDisplayOfMessages()
{
return [
'Explain mode' => [
$data = [
'Explain mode' => [
'configArgs' => ['-e'],
],
'Quiet mode' => [
'Quiet mode' => [
'configArgs' => ['-q'],
],
'Documentation is requested' => [
'configArgs' => ['--generator=text'],
],
];

// Setting the `--generator` arg is only supported when running `phpcs`.
if (PHP_CODESNIFFER_CBF === false) {
$data['Documentation is requested'] = [
'configArgs' => ['--generator=text'],
];
}

return $data;

}//end dataSelectiveDisplayOfMessages()


Expand Down