Skip to content

Commit a086211

Browse files
committed
Add a file check to StreamProcessor
If a file which StreamProcessor should process doesn't exist, `fopen` gives a warning. In PHPUnit context this warning will be translated into an exception which will then leave StreamProcessor in disabled state.
1 parent 2c5ddde commit a086211

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/VCR/Util/StreamProcessor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ protected function shouldProcess($uri)
171171
*/
172172
public function stream_open($path, $mode, $options, &$openedPath)
173173
{
174+
if ('r' === substr($mode, 0, 1) && !is_file($path)) {
175+
return false;
176+
}
177+
174178
$this->restore();
175179

176180
if (isset($this->context)) {

tests/VCR/Util/StreamProcessorTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ public function streamOpenAppendFilterProvider()
5858
);
5959
}
6060

61+
public function testStreamOpenShouldNotFailOnInexistingFile()
62+
{
63+
$test = $this;
64+
set_error_handler(function ($errno, $errstr, $errfile, $errline) use ($test) {
65+
$test->fail('should not throw errors');
66+
});
67+
68+
$processor = new StreamProcessor();
69+
70+
$result = $processor->stream_open('tests/fixtures/unknown', 'r', StreamProcessor::STREAM_OPEN_FOR_INCLUDE, $fullPath);
71+
$this->assertFalse($result);
72+
73+
restore_error_handler();
74+
}
75+
6176
public function testUrlStatSuccessfully()
6277
{
6378
$test = $this;

0 commit comments

Comments
 (0)