Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
Expand Down
27 changes: 27 additions & 0 deletions tests/EndToEnd/outofmemory_test.sh
Original file line number Diff line number Diff line change
@@ -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"
}