diff --git a/src/Runner.php b/src/Runner.php index 60118c5394..a835b0dd02 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -957,12 +957,12 @@ private function registerOutOfMemoryShutdownMessage($command) // Allocate all needed memory beforehand as much as possible. $errorMsg = PHP_EOL.'The PHP_CodeSniffer "%1$s" command ran out of memory.'.PHP_EOL; $errorMsg .= 'Either raise the "memory_limit" of PHP in the php.ini file or raise the memory limit at runtime'.PHP_EOL; - $errorMsg .= 'using `%1$s -d memory_limit=512M` (replace 512M with the desired memory limit).'.PHP_EOL; + $errorMsg .= 'using "%1$s -d memory_limit=512M" (replace 512M with the desired memory limit).'.PHP_EOL; $errorMsg = sprintf($errorMsg, $command); $memoryError = 'Allowed memory size of'; $errorArray = [ 'type' => 42, - 'message' => 'Some random dummy string to take up memory and take up some more memory and some more', + 'message' => 'Some random dummy string to take up memory and take up some more memory and some more and more and more and more', 'file' => 'Another random string, which would be a filename this time. Should be relatively long to allow for deeply nested files', 'line' => 31427, ]; diff --git a/tests/EndToEnd/outofmemory_test.sh b/tests/EndToEnd/outofmemory_test.sh new file mode 100644 index 0000000000..221bd89437 --- /dev/null +++ b/tests/EndToEnd/outofmemory_test.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +function tear_down() { + rm -f tests/EndToEnd/Fixtures/*.fixed +} + +function test_phpcs_out_of_memory_error_handling() { + OUTPUT="$(bin/phpcs -d memory_limit=4M --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/)" + # Exit code can't currently be tested as it looks like it may be 255 or 139 depending on the PHP version. + # Related feature request upstream: https://github.com/TypedDevs/bashunit/issues/505 + # assert_exit_code 255 + + assert_contains "The PHP_CodeSniffer \"phpcs\" command ran out of memory." "$OUTPUT" + assert_contains "Either raise the \"memory_limit\" of PHP in the php.ini file or raise the memory limit at runtime" "$OUTPUT" + assert_contains "using \"phpcs -d memory_limit=512M\" (replace 512M with the desired memory limit)." "$OUTPUT" +} + +function test_phpcbf_out_of_memory_error_handling() { + OUTPUT="$(bin/phpcbf -d memory_limit=4M --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ --suffix=.fixed)" + # Exit code can't currently be tested as it looks like it may be 255 or 139 depending on the PHP version. + # Related feature request upstream: https://github.com/TypedDevs/bashunit/issues/505 + # assert_exit_code 255 + + assert_contains "The PHP_CodeSniffer \"phpcbf\" command ran out of memory." "$OUTPUT" + assert_contains "Either raise the \"memory_limit\" of PHP in the php.ini file or raise the memory limit at runtime" "$OUTPUT" + assert_contains "using \"phpcbf -d memory_limit=512M\" (replace 512M with the desired memory limit)." "$OUTPUT" +}