@@ -6,6 +6,7 @@ FIX_DIR="tests/EndToEndBash/Fixtures"
66# Validate that stdin is well-formed CTRF. Asserts via exit code so callers can
77# follow up with `assert_successful_code`.
88function _validate_ctrf_from_stdin() {
9+ # shellcheck disable=SC2016 # PHP code is intentionally inside single quotes.
910 php -r '
1011 $json = stream_get_contents(STDIN);
1112 $d = json_decode($json, true);
@@ -48,27 +49,34 @@ function _validate_ctrf_from_stdin() {
4849
4950
5051function test_phpcs_ctrf_report_runs_sequentially() {
51- OUTPUT=" $( { bin/phpcs --no-cache --report=ctrf --standard=$ENDTOEND_STD $FIX_DIR /ClassWithStyleError.inc $FIX_DIR /ClassOneWithoutStyleError.inc; } 2>&1 ) "
52+ # PHPCS prints a "Time: Xms; Memory: YMB" line to stderr after the report; suppress it
53+ # so the captured stdout is pure JSON.
54+ OUTPUT=" $( bin/phpcs --no-colors --no-cache --report=ctrf --standard=" $ENDTOEND_STD " " $FIX_DIR /ClassWithStyleError.inc" " $FIX_DIR /ClassOneWithoutStyleError.inc" 2> /dev/null) "
5255 echo " $OUTPUT " | _validate_ctrf_from_stdin
5356 assert_successful_code
5457}
5558
5659
5760function test_phpcs_ctrf_report_runs_in_parallel() {
58- OUTPUT=" $( { bin/phpcs --no-cache --parallel=2 --report=ctrf --standard=$ENDTOEND_STD $FIX_DIR /ClassWithStyleError.inc $FIX_DIR /ClassOneWithoutStyleError.inc $FIX_DIR /ClassWithTwoStyleErrors.inc; } 2>&1 ) "
61+ OUTPUT=" $( bin/phpcs --no-colors --no- cache --parallel=2 --report=ctrf --standard=" $ENDTOEND_STD " " $FIX_DIR /ClassWithStyleError.inc" " $FIX_DIR /ClassOneWithoutStyleError.inc" " $FIX_DIR /ClassWithTwoStyleErrors.inc" 2> /dev/null ) "
5962 echo " $OUTPUT " | _validate_ctrf_from_stdin
6063 assert_successful_code
6164}
6265
6366
6467function test_phpcs_ctrf_parallel_matches_sequential() {
65- # Same input, same set of test entries ( regardless of order) .
66- SEQ=" $( { bin/phpcs --no-cache --report=ctrf --standard=$ENDTOEND_STD $FIX_DIR /ClassWithStyleError.inc $FIX_DIR /ClassOneWithoutStyleError.inc $FIX_DIR /ClassWithTwoStyleErrors.inc; } 2>&1 ) "
67- PAR=" $( { bin/phpcs --no-cache --parallel=2 --report=ctrf --standard=$ENDTOEND_STD $FIX_DIR /ClassWithStyleError.inc $FIX_DIR /ClassOneWithoutStyleError.inc $FIX_DIR /ClassWithTwoStyleErrors.inc; } 2>&1 ) "
68+ # Same input must produce the same set of test entries regardless of order.
69+ SEQ=" $( bin/phpcs --no-colors --no- cache --report=ctrf --standard=" $ENDTOEND_STD " " $FIX_DIR /ClassWithStyleError.inc" " $FIX_DIR /ClassOneWithoutStyleError.inc" " $FIX_DIR /ClassWithTwoStyleErrors.inc" 2> /dev/null ) "
70+ PAR=" $( bin/phpcs --no-colors --no- cache --parallel=2 --report=ctrf --standard=" $ENDTOEND_STD " " $FIX_DIR /ClassWithStyleError.inc" " $FIX_DIR /ClassOneWithoutStyleError.inc" " $FIX_DIR /ClassWithTwoStyleErrors.inc" 2> /dev/null ) "
6871
72+ # shellcheck disable=SC2016 # PHP code is intentionally inside single quotes.
6973 RESULT=" $( php -r '
70- $seq = json_decode($argv[1], true)["results"]["tests"];
71- $par = json_decode($argv[2], true)["results"]["tests"];
74+ $seq = json_decode($argv[1], true)["results"]["tests"] ?? null;
75+ $par = json_decode($argv[2], true)["results"]["tests"] ?? null;
76+ if (!is_array($seq) || !is_array($par)) {
77+ echo "INVALID";
78+ exit(0);
79+ }
7280 $proj = function ($t) { return ($t["status"] ?? "") . "|" . ($t["name"] ?? ""); };
7381 $seqKeys = array_map($proj, $seq);
7482 $parKeys = array_map($proj, $par);
@@ -82,22 +90,24 @@ function test_phpcs_ctrf_parallel_matches_sequential() {
8290
8391function test_phpcs_ctrf_report_to_file() {
8492 OUT_FILE=" $( mktemp /tmp/phpcs-ctrf-XXXXXX.json) "
85- bin/phpcs --no-cache --report-ctrf=" $OUT_FILE " --standard=$ENDTOEND_STD $FIX_DIR /ClassWithStyleError.inc > /dev/null 2>&1
86- cat " $OUT_FILE " | _validate_ctrf_from_stdin
87- RC=$?
93+ bin/phpcs --no-colors --no-cache --report-ctrf=" $OUT_FILE " --standard=" $ENDTOEND_STD " " $FIX_DIR /ClassWithStyleError.inc" > /dev/null 2>&1
94+ CONTENTS=" $( cat " $OUT_FILE " ) "
8895 rm -f " $OUT_FILE "
89- return $RC
96+
97+ echo " $CONTENTS " | _validate_ctrf_from_stdin
98+ assert_successful_code
99+ assert_contains ' "reportFormat":"CTRF"' " $CONTENTS "
90100}
91101
92102
93103function test_phpcs_ctrf_clean_file_emits_passed_test() {
94- OUTPUT=" $( { bin/phpcs --no-cache --report=ctrf --standard=$ENDTOEND_STD $FIX_DIR /ClassOneWithoutStyleError.inc; } 2>&1 ) "
104+ OUTPUT=" $( bin/phpcs --no-colors --no- cache --report=ctrf --standard=" $ENDTOEND_STD " " $FIX_DIR /ClassOneWithoutStyleError.inc" 2> /dev/null ) "
95105 assert_contains ' "status":"passed"' " $OUTPUT "
96106}
97107
98108
99109function test_phpcs_ctrf_error_emits_failed_test() {
100- OUTPUT=" $( { bin/phpcs --no-cache --report=ctrf --standard=$ENDTOEND_STD $FIX_DIR /ClassWithStyleError.inc; } 2>&1 ) "
110+ OUTPUT=" $( bin/phpcs --no-colors --no- cache --report=ctrf --standard=" $ENDTOEND_STD " " $FIX_DIR /ClassWithStyleError.inc" 2> /dev/null ) "
101111 assert_contains ' "status":"failed"' " $OUTPUT "
102112 assert_contains ' "rawStatus":"ERROR"' " $OUTPUT "
103113}
0 commit comments