Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enableLibraryHooks doesn't correctly disable stream_wrapper functions #274

Open
Gberzi01 opened this issue Apr 30, 2019 · 0 comments
Open

Comments

@Gberzi01
Copy link

Gberzi01 commented Apr 30, 2019

Trying to implement php-vcr with Laravel dusk tests I ran into a problem where \Cache::rememberForever always throws an error
ErrorException: unserialize(): Error at offset 2 of 8182 bytes

Reading the documentation it mentions that stream_wrapper is the hook responsible for php functions like fopen. But only enabling the curl and soap hooks still threw the error. So after further inspection it seems that the function fopen still returns a handle that has a StreamProcessor attached to it even when the library hook for stream_wrapper is disabled. This causes large files to have cut off endings when performing fread on them (which is basically what the Cache::rememberForever inside Laravel Filesystem does). The code sample can be broken down to:

\VCR\VCR::configure()->enableLibraryHooks(['curl', 'soap']);
\VCR\VCR::turnOn();
\VCR\VCR::insertCassette('fread');

$path = base_path('composer.lock');
$size = filesize($path);

$handle = fopen($path, 'rb');
$contents = fread($handle, $size ?: 1);
dump($size, strlen($contents));

\VCR\VCR::eject();
\VCR\VCR::turnOff();
The output is:
size = 306089
strlen($contents) = 8192

Expected output:
size = 306089
strlen($contents) = 306089

php: 7.2.14
php-vcr: 1.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant