mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
fix(tia): report why an include failed as plain PHP does (#2082)
Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 39 skipped, 2001 passed (4506 assertions)
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user