diff --git a/client-php/tests/ProcessTest.php b/client-php/tests/ProcessTest.php index 3819b8c..b3c1f77 100644 --- a/client-php/tests/ProcessTest.php +++ b/client-php/tests/ProcessTest.php @@ -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')); @@ -51,9 +51,13 @@ 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']); @@ -61,6 +65,17 @@ public function testFatalError(): void 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', [