diff --git a/src/Plugins/Tia/ReadCapture.php b/src/Plugins/Tia/ReadCapture.php index 4cf38fcb..945eb968 100644 --- a/src/Plugins/Tia/ReadCapture.php +++ b/src/Plugins/Tia/ReadCapture.php @@ -286,21 +286,13 @@ final class ReadCapture public function url_stat(string $path, int $flags): array|false { return $this->withOriginalWrapper(function () use ($path, $flags): array|false { - $isQuiet = ($flags & STREAM_URL_STAT_QUIET) !== 0; + set_error_handler(static fn (): bool => true); - if (($flags & STREAM_URL_STAT_LINK) !== 0) { - if ($isQuiet && ! is_link($path) && ! file_exists($path)) { - return false; - } - - return @lstat($path); + try { + return ($flags & STREAM_URL_STAT_LINK) !== 0 ? lstat($path) : stat($path); + } finally { + restore_error_handler(); } - - if ($isQuiet && ! file_exists($path)) { - return false; - } - - return @stat($path); }); } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 9f563bee..b27140c3 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -2079,6 +2079,7 @@ ✓ the file wrapper → it is restored when the recorder resets ✓ 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 symlinks as links while a test records with dataset "a link to an existing file" ✓ the file wrapper → it reports symlinks as links while a test records with dataset "a dangling link" ✓ a wrapper already registered for file:// → it opens reads through it and still links them @@ -2601,4 +2602,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, 38 skipped, 1893 passed (4339 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 38 skipped, 1894 passed (4340 assertions) \ No newline at end of file diff --git a/tests/Unit/Plugins/Tia/ReadCapture.php b/tests/Unit/Plugins/Tia/ReadCapture.php index 16038c4f..5e580f29 100644 --- a/tests/Unit/Plugins/Tia/ReadCapture.php +++ b/tests/Unit/Plugins/Tia/ReadCapture.php @@ -205,6 +205,39 @@ describe('the file wrapper', function (): void { } }); + it('reports a missing path to the error handler 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)); + $warnings = []; + $results = []; + + set_error_handler(function (int $level, string $message) use (&$warnings): bool { + $warnings[] = $message; + + return true; + }); + + try { + tiaReadCaptureLinks(function () use ($missing, &$warnings, &$results): void { + clearstatcache(); + + $results['quiet'] = [file_exists($missing), is_file($missing), is_dir($missing), is_link($missing)]; + $results['warnings after quiet probes'] = count($warnings); + + $results['stat'] = stat($missing); + $results['warnings after stat'] = count($warnings); + }); + } finally { + restore_error_handler(); + } + + expect($results)->toBe([ + 'quiet' => [false, false, false, false], + 'warnings after quiet probes' => 0, + 'stat' => false, + 'warnings after stat' => 1, + ]); + }); + it('reports symlinks as links while a test records', function (bool $targetExists, bool $expectedExists): void { $directory = sys_get_temp_dir().DIRECTORY_SEPARATOR.'pest-read-capture-'.bin2hex(random_bytes(8)); mkdir($directory); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 4d20ee0f..bc2a9179 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, 30 skipped, 1766 passed (3814 assertions)'; + $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 30 skipped, 1767 passed (3815 assertions)'; expect($output) ->toContain("Tests: {$expected}")