diff --git a/qit b/qit index 6386279d..0a431377 100755 Binary files a/qit and b/qit differ diff --git a/src/src/LocalTests/PrepareQMLog.php b/src/src/LocalTests/PrepareQMLog.php index cfaf2f4c..32d818ee 100644 --- a/src/src/LocalTests/PrepareQMLog.php +++ b/src/src/LocalTests/PrepareQMLog.php @@ -92,7 +92,7 @@ public function extract_fatal_errors_from_debug_file( string $file_path ): array if ( $handle ) { while ( ( $line = fgets( $handle ) ) !== false ) { // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition - if ( str_contains( $line, 'PHP Fatal error:' ) ) { + if ( str_contains( $line, 'PHP Fatal error:' ) || str_contains( $line, 'PHP Parse error:' ) ) { $lines[] = $line; } } @@ -114,35 +114,45 @@ public function extract_fatal_errors_from_debug_file( string $file_path ): array public function extract_error_info( array $lines ): array { $fatal_errors = []; foreach ( $lines as $line ) { - preg_match( '/PHP Fatal error: (.*?) in (.*?) on line (\d+)/', $line, $matches1 ); + // First pattern: `on line X`. + preg_match( + '/PHP (Fatal|Parse) error: (.*?) in (.*?) on line (\d+)/', + $line, + $matches1 + ); if ( isset( $matches1[1] ) && isset( $matches1[2] ) && - isset( $matches1[3] ) + isset( $matches1[3] ) && + isset( $matches1[4] ) ) { $fatal_errors[] = [ - 'message' => $matches1[1], - 'file' => str_replace( '/var/www/html/', '', $matches1[2] ), - 'line' => $matches1[3], + 'message' => $matches1[2], + 'file' => str_replace( '/var/www/html/', '', $matches1[3] ), + 'line' => $matches1[4], ]; - continue; } - preg_match( '/PHP Fatal error: (.*?) in (.*?):(\d+)/', $line, $matches2 ); + // Second pattern: `in path:line`. + preg_match( + '/PHP (Fatal|Parse) error: (.*?) in (.*?):(\d+)/', + $line, + $matches2 + ); if ( isset( $matches2[1] ) && isset( $matches2[2] ) && - isset( $matches2[3] ) + isset( $matches2[3] ) && + isset( $matches2[4] ) ) { $fatal_errors[] = [ - 'message' => $matches2[1], - 'file' => str_replace( '/var/www/html/', '', $matches2[2] ), - 'line' => $matches2[3], + 'message' => $matches2[2], + 'file' => str_replace( '/var/www/html/', '', $matches2[3] ), + 'line' => $matches2[4], ]; - continue; } diff --git a/src/tests/LocalTests/PrepareQMLogTest.php b/src/tests/LocalTests/PrepareQMLogTest.php new file mode 100644 index 00000000..01b9dd28 --- /dev/null +++ b/src/tests/LocalTests/PrepareQMLogTest.php @@ -0,0 +1,23 @@ +assertMatchesJsonSnapshot( $sut->extract_error_info( explode( "\n", $debug_log ) ) ); + } +} \ No newline at end of file diff --git a/src/tests/LocalTests/__snapshots__/PrepareQMLogTest__test_parses_fatal_and_parse_errors__1.json b/src/tests/LocalTests/__snapshots__/PrepareQMLogTest__test_parses_fatal_and_parse_errors__1.json new file mode 100644 index 00000000..c353a05a --- /dev/null +++ b/src/tests/LocalTests/__snapshots__/PrepareQMLogTest__test_parses_fatal_and_parse_errors__1.json @@ -0,0 +1,17 @@ +[ + { + "message": " syntax error, unexpected '|', expecting variable (T_VARIABLE)", + "file": "wp-content\/plugins\/foo-slug\/vendor\/phpunit\/phpunit\/src\/Framework\/Assert\/Functions.php", + "line": "83" + }, + { + "message": " Exception thrown without a stack frame", + "file": "Unknown", + "line": "0" + }, + { + "message": " Uncaught Exception: Foo", + "file": "wp-content\/plugins\/foo-slug\/foo-slug.php", + "line": "29" + } +]