Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions tests/EndToEnd/Fixtures/ClassWithTwoStyleErrors.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* Class containing a simple style error that phpcbf cannot fix, and another that it can fix.
*
* @copyright 2025 PHPCSStandards and contributors
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/

namespace PHP_CodeSniffer\Tests\EndToEnd\Fixtures;

# The brace on the following line should be on a line by itself. This can be fixed with phpcbf.
class ClassWithTwoStyleErrors {
} # This comment does not belong here, according to PSR12. This cannot be fixed with phpcbf.
14 changes: 14 additions & 0 deletions tests/EndToEnd/Fixtures/ClassWithUnfixableStyleError.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* Class containing a simple style error that phpcbf cannot fix.
*
* @copyright 2025 PHPCSStandards and contributors
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/

namespace PHP_CodeSniffer\Tests\EndToEnd\Fixtures;

class ClassWithUnfixableStyleError
{
} # This comment does not belong here, according to PSR12.
36 changes: 36 additions & 0 deletions tests/EndToEnd/phpcbf_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,39 @@ function test_phpcbf_bug_1112() {
assert_successful_code "$(bash -ic 'bash --init-file <(echo "echo \"Subprocess\"") -c "bin/phpcbf --no-cache --parallel=2 --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEnd/Fixtures/ClassTwoWithoutStyleError.inc"')"
fi
}

function test_phpcbf_exit_code_clean() {
bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc
assert_exit_code 0

# Same result via STDIN
bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc
assert_exit_code 0
}

function test_phpcbf_exit_code_fixable() {
bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithStyleError.inc
assert_exit_code 0

# Same result via STDIN
bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassWithStyleError.inc
assert_exit_code 0
}

function test_phpcbf_exit_code_non_fixable() {
bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithUnfixableStyleError.inc
assert_exit_code 2

# Same result via STDIN
bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassWithUnfixableStyleError.inc
assert_exit_code 2
}

function test_phpcbf_exit_code_fixable_and_non_fixable() {
bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithTwoStyleErrors.inc
assert_exit_code 2

# Same result via STDIN
bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassWithTwoStyleErrors.inc
assert_exit_code 2
}
36 changes: 36 additions & 0 deletions tests/EndToEnd/phpcs_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,39 @@ function test_phpcs_bug_1112() {
assert_successful_code "$(bash -ic 'bash --init-file <(echo "echo \"Subprocess\"") -c "bin/phpcs --no-cache --parallel=2 --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEnd/Fixtures/ClassTwoWithoutStyleError.inc"')"
fi
}

function test_phpcs_exit_code_clean() {
bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc
assert_exit_code 0

# Same result via STDIN
bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc
assert_exit_code 0
}

function test_phpcs_exit_code_fixable() {
bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithStyleError.inc
assert_exit_code 1

# Same result via STDIN
bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassWithStyleError.inc
assert_exit_code 1
}

function test_phpcs_exit_code_non_fixable() {
bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithUnfixableStyleError.inc
assert_exit_code 2

# Same result via STDIN
bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassWithUnfixableStyleError.inc
assert_exit_code 2
}

function test_phpcs_exit_code_fixable_and_non_fixable() {
bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithTwoStyleErrors.inc
assert_exit_code 3

# Same result via STDIN
bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassWithTwoStyleErrors.inc
assert_exit_code 3
}
Loading