File tree Expand file tree Collapse file tree 9 files changed +153
-1
lines changed Expand file tree Collapse file tree 9 files changed +153
-1
lines changed Original file line number Diff line number Diff line change @@ -247,10 +247,21 @@ jobs:
247247 env :
248248 PHP_CODESNIFFER_CBF : ' 1'
249249
250+ - name : " Install bashunit"
251+ if : ${{ matrix.custom_ini == false && matrix.os == 'ubuntu-latest' }}
252+ run : |
253+ curl -s https://bashunit.typeddevs.com/install.sh > install.sh
254+ chmod +x install.sh
255+ ./install.sh
256+
257+ - name : " Run bashunit tests"
258+ if : ${{ matrix.custom_ini == false && matrix.os == 'ubuntu-latest' }}
259+ run : " ./lib/bashunit -p tests/EndToEnd"
260+
250261 # Note: The code style check is run multiple times against every PHP version
251262 # as it also acts as an integration test.
252263 - name : ' PHPCS: check code style without cache, no parallel'
253- if : ${{ matrix.custom_ini == false }}
264+ if : ${{ matrix.custom_ini == false && matrix.os == 'windows-latest' }}
254265 run : php "bin/phpcs" --no-cache --parallel=1
255266
256267 - name : Download the PHPCS phar
Original file line number Diff line number Diff line change 1111 <exclude-pattern >*/src/Standards/*/Tests/*\.(inc|css|js)$</exclude-pattern >
1212 <exclude-pattern >*/tests/Core/*/*\.(inc|css|js)$</exclude-pattern >
1313 <exclude-pattern >*/tests/Core/*/Fixtures/*\.php$</exclude-pattern >
14+ <exclude-pattern >*/tests/EndToEnd/Files/*\.inc$</exclude-pattern >
1415
1516 <arg name =" basepath" value =" ." />
1617 <arg name =" colors" />
Original file line number Diff line number Diff line change 1+ * .fixed
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Class containing no style errors according to the end-to-end tests phpcs.xml.dist.
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 \Files ;
11+
12+ class ClassOneWithoutStyleError
13+ {
14+ private function foo ()
15+ {
16+ return 'bar ' ;
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Class containing no style errors.
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 \Files ;
11+
12+ class ClassTwoWithoutStyleError
13+ {
14+ /**
15+ * A property.
16+ *
17+ * @var string
18+ */
19+ private $ bar = 'baz ' ;
20+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Class containing a simple style error that phpcbf 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 \Files ;
11+
12+ class ClassWithStyleError
13+ {
14+ /**
15+ * The bracket for this function is misaligned and this can be automatically fixed by phpcbf.
16+ *
17+ * @return string
18+ */
19+ private function foo () {
20+ return 'bar ' ;
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" ?>
2+ <ruleset xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" name =" PHP_CodeSniffer" xsi : noNamespaceSchemaLocation =" phpcs.xsd" >
3+ <description >The coding standard for end to end tests.</description >
4+
5+ <rule ref =" PSR12" />
6+
7+ <file >.</file >
8+
9+ <arg name =" basepath" value =" ." />
10+ <arg name =" colors" />
11+ <arg name =" parallel" value =" 75" />
12+ <arg value =" p" />
13+ </ruleset >
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ function tear_down() {
4+ rm -r tests/EndToEnd/Files/* .fixed
5+ }
6+
7+ function test_phpcbf_is_working() {
8+ OUTPUT=" $( bin/phpcbf --no-cache --standard=tests/EndToEnd/Files/phpcs.xml.dist tests/EndToEnd/Files/ClassOneWithoutStyleError.inc tests/EndToEnd/Files/ClassTwoWithoutStyleError.inc) "
9+
10+ assert_successful_code
11+ assert_contains " No violations were found" " $OUTPUT "
12+ }
13+
14+ function test_phpcbf_is_working_in_parallel() {
15+ OUTPUT=" $( bin/phpcbf --no-cache --parallel=2 --standard=tests/EndToEnd/Files/phpcs.xml.dist tests/EndToEnd/Files/ClassOneWithoutStyleError.inc tests/EndToEnd/Files/ClassTwoWithoutStyleError.inc) "
16+
17+ assert_successful_code
18+ assert_contains " No violations were found" " $OUTPUT "
19+ }
20+
21+ function test_phpcbf_returns_error_on_issues() {
22+ OUTPUT=" $( bin/phpcbf --no-colors --no-cache --suffix=.fixed --standard=tests/EndToEnd/Files/phpcs.xml.dist tests/EndToEnd/Files/ClassWithStyleError.inc) "
23+ assert_exit_code 1
24+
25+ assert_contains " F 1 / 1 (100%)" " $OUTPUT "
26+ assert_contains " A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE" " $OUTPUT "
27+ }
28+
29+ function test_phpcbf_bug_1112() {
30+ # See https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/1112
31+ if [[ " $( uname) " == " Darwin" ]]; then
32+ # Perform some magic with `& fg` to prevent the processes from turning into a background job.
33+ assert_successful_code " $( bash -ic ' bash --init-file <(echo "echo \"Subprocess\"") -c "bin/phpcbf --no-cache --parallel=2 --standard=tests/EndToEnd/Files/phpcs.xml.dist tests/EndToEnd/Files/ClassOneWithoutStyleError.inc tests/EndToEnd/Files/ClassTwoWithoutStyleError.inc" & fg' ) "
34+ else
35+ # This is not needed on Linux / GitHub Actions
36+ assert_successful_code " $( bash -ic ' bash --init-file <(echo "echo \"Subprocess\"") -c "bin/phpcbf --no-cache --parallel=2 --standard=tests/EndToEnd/Files/phpcs.xml.dist tests/EndToEnd/Files/ClassOneWithoutStyleError.inc tests/EndToEnd/Files/ClassTwoWithoutStyleError.inc"' ) "
37+ fi
38+ }
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ function test_phpcs_is_working() {
4+ assert_successful_code " $( bin/phpcs --no-cache --standard=tests/EndToEnd/Files/phpcs.xml.dist tests/EndToEnd/Files/ClassOneWithoutStyleError.inc tests/EndToEnd/Files/ClassTwoWithoutStyleError.inc) "
5+ }
6+
7+ function test_phpcs_is_working_in_parallel() {
8+ assert_successful_code " $( bin/phpcs --no-cache --parallel=2 --standard=tests/EndToEnd/Files/phpcs.xml.dist tests/EndToEnd/Files/ClassOneWithoutStyleError.inc tests/EndToEnd/Files/ClassTwoWithoutStyleError.inc) "
9+ }
10+
11+ function test_phpcs_returns_error_on_issues() {
12+ OUTPUT=" $( bin/phpcs --no-colors --no-cache --standard=tests/EndToEnd/Files/phpcs.xml.dist tests/EndToEnd/Files/ClassWithStyleError.inc) "
13+ assert_exit_code 2
14+
15+ assert_contains " E 1 / 1 (100%)" " $OUTPUT "
16+ assert_contains " FOUND 1 ERROR AFFECTING 1 LINE" " $OUTPUT "
17+ }
18+
19+ function test_phpcs_bug_1112() {
20+ # See https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/1112
21+ if [[ " $( uname) " == " Darwin" ]]; then
22+ # Perform some magic with `& fg` to prevent the processes from turning into a background job.
23+ assert_successful_code " $( bash -ic ' bash --init-file <(echo "echo \"Subprocess\"") -c "bin/phpcs --no-cache --parallel=2 --standard=tests/EndToEnd/Files/phpcs.xml.dist tests/EndToEnd/Files/ClassOneWithoutStyleError.inc tests/EndToEnd/Files/ClassTwoWithoutStyleError.inc" & fg' ) "
24+ else
25+ # This is not needed on Linux / GitHub Actions
26+ assert_successful_code " $( bash -ic ' bash --init-file <(echo "echo \"Subprocess\"") -c "bin/phpcs --no-cache --parallel=2 --standard=tests/EndToEnd/Files/phpcs.xml.dist tests/EndToEnd/Files/ClassOneWithoutStyleError.inc tests/EndToEnd/Files/ClassTwoWithoutStyleError.inc"' ) "
27+ fi
28+ }
You can’t perform that action at this time.
0 commit comments