From cf21b7cd64ee319be94943f2eeb5c1776fe1c5cf Mon Sep 17 00:00:00 2001 From: Chris Mellor Date: Fri, 27 Nov 2026 11:45:37 +0000 Subject: [PATCH] fix(tia): report why an include failed as plain PHP does (#2082) Co-authored-by: Punyapal Shah --- src/Plugins/Tia/ReadCapture.php | 2 +- tests/.snapshots/success.txt | 3 ++- tests/Unit/Plugins/Tia/ReadCapture.php | 34 ++++++++++++++++++++++++++ tests/Visual/Parallel.php | 2 +- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/Plugins/Tia/ReadCapture.php b/src/Plugins/Tia/ReadCapture.php index e363f5fb..b7b16e42 100644 --- a/src/Plugins/Tia/ReadCapture.php +++ b/src/Plugins/Tia/ReadCapture.php @@ -314,7 +314,7 @@ final class ReadCapture */ private function openNatively(string $path, string $mode, int $options): mixed { - return ($options & STREAM_REPORT_ERRORS) !== 0 + return ($options & (STREAM_REPORT_ERRORS | self::STREAM_OPEN_FOR_INCLUDE)) !== 0 ? fopen($path, $mode, ($options & STREAM_USE_PATH) !== 0, $this->context) : @fopen($path, $mode, ($options & STREAM_USE_PATH) !== 0, $this->context); } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index a70675ac..30b40bd3 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -2163,6 +2163,7 @@ ✓ the file wrapper → it passes filesystem operations through while a test records ✓ the file wrapper → it writes with LOCK_EX while a test records ✓ the file wrapper → it reports a missing path to the error handler as plain PHP does while a test records + ✓ the file wrapper → it reports why an include failed as plain PHP does while a test records ✓ the file wrapper → it keeps no memory for each filesystem call while a test records ✓ the file wrapper → it keeps no memory for each test it records ✓ the file wrapper → it is restored quietly when the test already restored it @@ -2717,4 +2718,4 @@ ✓ pass with dataset with ('my-datas-set-value') ✓ within describe → pass with dataset with ('my-datas-set-value') - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 39 skipped, 2000 passed (4505 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 39 skipped, 2001 passed (4506 assertions) \ No newline at end of file diff --git a/tests/Unit/Plugins/Tia/ReadCapture.php b/tests/Unit/Plugins/Tia/ReadCapture.php index 90e4bb83..594b6d06 100644 --- a/tests/Unit/Plugins/Tia/ReadCapture.php +++ b/tests/Unit/Plugins/Tia/ReadCapture.php @@ -239,6 +239,40 @@ describe('the file wrapper', function (): void { ]); }); + it('reports why an include failed as plain PHP does while a test records', function (): void { + $missing = sys_get_temp_dir().DIRECTORY_SEPARATOR.'pest-read-capture-missing-'.bin2hex(random_bytes(8)).'.php'; + $results = []; + $errorReporting = error_reporting(E_ALL); + + set_error_handler(function (int $level, string $message, string $file, int $line): bool { + if ((error_reporting() & $level) === 0) { + return false; + } + + throw new ErrorException($message, 0, $level, $file, $line); + }); + + try { + tiaReadCaptureLinks(function () use ($missing, &$results): void { + try { + include $missing; + } catch (ErrorException $exception) { + $results['include'] = str_contains($exception->getMessage(), 'No such file or directory'); + } + + $results['silenced include'] = @include $missing; + }); + } finally { + restore_error_handler(); + error_reporting($errorReporting); + } + + expect($results)->toBe([ + 'include' => true, + 'silenced include' => false, + ]); + }); + it('keeps no memory for each filesystem call while a test records', function (): void { $growth = 0; diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 5976e3ad..9ea2d67d 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -21,7 +21,7 @@ test('parallel', function () use ($run): void { $output = implode("\n", array_slice(explode("\n", (string) $output), -10)); $profileOutput = $run('tests/Fixtures/Suites/SuccessOnly.php', '--profile'); - $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 31 skipped, 1872 passed (3978 assertions)'; + $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 31 skipped, 1873 passed (3979 assertions)'; expect($output) ->toContain("Tests: {$expected}")