File tree Expand file tree Collapse file tree 4 files changed +100
-0
lines changed Expand file tree Collapse file tree 4 files changed +100
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Class containing a simple style error that phpcbf cannot fix, and another that it can fix.
5+ *
6+ * @copyright 2025 PHPCSStandards and contributors
7+ * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8+ */
9+
10+ namespace PHP_CodeSniffer \Tests \EndToEnd \Fixtures ;
11+
12+ # The brace on the following line should be on a line by itself. This can be fixed with phpcbf.
13+ class ClassWithUnfixableStyleError {
14+ } # This comment does not belong here, according to PSR12. This cannot be fixed with phpcbf.
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Class containing a simple style error that phpcbf cannot fix.
5+ *
6+ * @copyright 2025 PHPCSStandards and contributors
7+ * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8+ */
9+
10+ namespace PHP_CodeSniffer \Tests \EndToEnd \Fixtures ;
11+
12+ class ClassWithUnfixableStyleError
13+ {
14+ } # This comment does not belong here, according to PSR12.
Original file line number Diff line number Diff line change @@ -43,3 +43,39 @@ function test_phpcbf_bug_1112() {
4343 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"' ) "
4444 fi
4545}
46+
47+ function test_phpcbf_exit_code_clean() {
48+ bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc
49+ assert_exit_code 0
50+
51+ # Same result via STDIN
52+ bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc
53+ assert_exit_code 0
54+ }
55+
56+ function test_phpcbf_exit_code_fixable() {
57+ bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithStyleError.inc
58+ assert_exit_code 0
59+
60+ # Same result via STDIN
61+ bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassWithStyleError.inc
62+ assert_exit_code 0
63+ }
64+
65+ function test_phpcbf_exit_code_non_fixable() {
66+ bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithUnfixableStyleError.inc
67+ assert_exit_code 2
68+
69+ # Same result via STDIN
70+ bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassWithUnfixableStyleError.inc
71+ assert_exit_code 2
72+ }
73+
74+ function test_phpcbf_exit_code_fixable_and_non_fixable() {
75+ bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithTwoStyleErrors.inc
76+ assert_exit_code 2
77+
78+ # Same result via STDIN
79+ bin/phpcbf --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassWithTwoStyleErrors.inc
80+ assert_exit_code 2
81+ }
Original file line number Diff line number Diff line change @@ -26,3 +26,39 @@ function test_phpcs_bug_1112() {
2626 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"' ) "
2727 fi
2828}
29+
30+ function test_phpcs_exit_code_clean() {
31+ bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc
32+ assert_exit_code 0
33+
34+ # Same result via STDIN
35+ bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc
36+ assert_exit_code 0
37+ }
38+
39+ function test_phpcs_exit_code_fixable() {
40+ bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithStyleError.inc
41+ assert_exit_code 1
42+
43+ # Same result via STDIN
44+ bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassWithStyleError.inc
45+ assert_exit_code 1
46+ }
47+
48+ function test_phpcs_exit_code_non_fixable() {
49+ bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithUnfixableStyleError.inc
50+ assert_exit_code 2
51+
52+ # Same result via STDIN
53+ bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassWithUnfixableStyleError.inc
54+ assert_exit_code 2
55+ }
56+
57+ function test_phpcs_exit_code_fixable_and_non_fixable() {
58+ bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithTwoStyleErrors.inc
59+ assert_exit_code 3
60+
61+ # Same result via STDIN
62+ bin/phpcs --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist < tests/EndToEnd/Fixtures/ClassWithTwoStyleErrors.inc
63+ assert_exit_code 3
64+ }
You can’t perform that action at this time.
0 commit comments