Skip to content

Commit 3535845

Browse files
authored
Merge pull request php-vcr#212 from mjanser/add-file-check
Add a file check to StreamProcessor
2 parents 14e5413 + 7ed3417 commit 3535845

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,33 @@ public function streamOpenAppendFilterProvider()
5858
);
5959
}
6060

61+
public function streamOpenFileModesWhichDoNotCreateFiles()
62+
{
63+
return array(
64+
array('r'),
65+
array('rb'),
66+
array('rt'),
67+
array('r+')
68+
);
69+
}
70+
/**
71+
* @dataProvider streamOpenFileModesWhichDoNotCreateFiles
72+
*/
73+
public function testStreamOpenShouldNotFailOnNonExistingFile($fileMode)
74+
{
75+
$test = $this;
76+
set_error_handler(function ($errno, $errstr, $errfile, $errline) use ($test) {
77+
$test->fail('should not throw errors');
78+
});
79+
80+
$processor = new StreamProcessor();
81+
82+
$result = $processor->stream_open('tests/fixtures/unknown', $fileMode, StreamProcessor::STREAM_OPEN_FOR_INCLUDE, $fullPath);
83+
$this->assertFalse($result);
84+
85+
restore_error_handler();
86+
}
87+
6188
public function testUrlStatSuccessfully()
6289
{
6390
$test = $this;

0 commit comments

Comments
 (0)