Skip to content
Merged
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
19 changes: 17 additions & 2 deletions client-php/tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testWarningAndUncaughtException(): void
{
[$exitCode, $output, $events] = $this->runScript('errors.php');

self::assertSame(255, $exitCode);
self::assertSame(255, $exitCode, $output);
self::assertStringContainsString('Order 7 not found', $output, 'PHP still reports the uncaught exception');
self::assertStringContainsString('Undefined index: discount', $output, 'and the warning');
self::assertSame(['request_start', 'message', 'error', 'error', 'request_end'], array_column($events, 'type'));
Expand All @@ -51,16 +51,31 @@ public function testWarningAndUncaughtException(): void

public function testFatalError(): void
{
if (!self::phpRunsShutdownAfterOutOfMemory()) {
self::markTestSkipped('This PHP build exits with code 1 on running out of memory and skips shutdown functions, '
. 'without the library too (seen in setup-php builds of PHP 7.4-8.1 from October 2026)');
}
[$exitCode, $output, $events] = $this->runScript('fatal.php');

self::assertSame(255, $exitCode);
self::assertSame(255, $exitCode, $output);
self::assertStringContainsString('Allowed memory size', $output);
self::assertSame(['request_start', 'error', 'request_end'], array_column($events, 'type'));
self::assertSame('fatal', $events[1]['kind']);
self::assertSame('E_ERROR', $events[1]['error_type']);
self::assertSame(255, $events[2]['exit_code']);
}

/** Whether bare PHP, with no extensions and no library, still runs shutdown functions after running out of memory. */
private static function phpRunsShutdownAfterOutOfMemory(): bool
{
$code = 'register_shutdown_function(function () { echo "shutdown"; }); '
. 'while (true) { $chunks[] = str_repeat("x", 1024 * 1024); }';
$command = sprintf('%s -n -d memory_limit=16M -d display_errors=0 -r %s 2>&1', escapeshellarg(PHP_BINARY), escapeshellarg($code));
exec($command, $output, $exitCode);

return $exitCode === 255 && implode("\n", $output) === 'shutdown';
}

public function testProjectOfLibraryV1WithoutComposer(): void
{
[$exitCode, $output, $events] = $this->runScript('compat.php', [
Expand Down
Loading