You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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
The text was updated successfully, but these errors were encountered: