Skip to content

Commit a0734c7

Browse files
committed
Stop intercepting calls to /dev/urandom. This commit fixes php-vcr#239.
1 parent a45aa4c commit a0734c7

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/VCR/Util/StreamProcessor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ 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)) {
174+
// file_exists catches paths like /dev/urandom that are missed by is_file.
175+
if ('r' === substr($mode, 0, 1) && !file_exists($path)) {
175176
return false;
176177
}
177178

tests/VCR/VCRTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ public function testShouldInterceptSoapLibrary()
7676
VCR::turnOff();
7777
}
7878

79+
public function testShouldNotInterceptCallsToDevUrandom()
80+
{
81+
if ('\\' === DIRECTORY_SEPARATOR) {
82+
$this->markTestSkipped('/dev/urandom is not supported on Windows');
83+
}
84+
85+
VCR::configure()->enableLibraryHooks(array('stream_wrapper'));
86+
VCR::turnOn();
87+
VCR::insertCassette('unittest_urandom_test');
88+
89+
// Just trying to open this will cause an exception if you're using is_file to filter
90+
// which paths to intercept.
91+
$output = file_get_contents('/dev/urandom', false, null, 0, 16);
92+
93+
VCR::eject();
94+
VCR::turnOff();
95+
}
96+
7997
public function testShouldThrowExceptionIfNoCassettePresent()
8098
{
8199
$this->setExpectedException(

tests/fixtures/unittest_urandom_test

Whitespace-only changes.

0 commit comments

Comments
 (0)