|
323 | 323 | }); |
324 | 324 |
|
325 | 325 | it('sets file path on unreadable file exception', function (): void { |
326 | | - // Create an unreadable file |
327 | | - $tempFile = tempnam(sys_get_temp_dir(), 'jsonstream_test_'); |
328 | | - chmod($tempFile, 0000); |
329 | | - |
330 | | - try { |
331 | | - StreamReader::fromFile($tempFile); |
332 | | - expect(false)->toBeTrue(); // Should not reach here |
333 | | - } catch (IOException $e) { |
334 | | - expect($e->getFilePath())->toBe($tempFile); |
335 | | - } finally { |
336 | | - chmod($tempFile, 0644); |
| 326 | + if (DIRECTORY_SEPARATOR === '\\') { |
| 327 | + // Windows: chmod does not restrict access; use a directory instead |
| 328 | + // fopen() on a directory fails on Windows, triggering IOException |
| 329 | + $tempFile = tempnam(sys_get_temp_dir(), 'jsonstream_test_'); |
337 | 330 | unlink($tempFile); |
| 331 | + mkdir($tempFile); |
| 332 | + |
| 333 | + try { |
| 334 | + StreamReader::fromFile($tempFile); |
| 335 | + expect(false)->toBeTrue(); // Should not reach here |
| 336 | + } catch (IOException $e) { |
| 337 | + expect($e->getFilePath())->toBe($tempFile); |
| 338 | + } finally { |
| 339 | + rmdir($tempFile); |
| 340 | + } |
| 341 | + } else { |
| 342 | + // Unix: chmod makes the file unreadable |
| 343 | + $tempFile = tempnam(sys_get_temp_dir(), 'jsonstream_test_'); |
| 344 | + chmod($tempFile, 0000); |
| 345 | + |
| 346 | + try { |
| 347 | + StreamReader::fromFile($tempFile); |
| 348 | + expect(false)->toBeTrue(); // Should not reach here |
| 349 | + } catch (IOException $e) { |
| 350 | + expect($e->getFilePath())->toBe($tempFile); |
| 351 | + } finally { |
| 352 | + chmod($tempFile, 0644); |
| 353 | + unlink($tempFile); |
| 354 | + } |
338 | 355 | } |
339 | 356 | }); |
340 | 357 | }); |
|
0 commit comments