3

I have set up a vfsstream block device and I'm trying to call file_get_contents() on it. However the call to vfsStreamWrapper::stream_open fails and therefore the stream cannot be opened.

Here is my code:

$this->root = vfsStream::setup('root');
$this->root->addChild(new vfsStreamBlock('test_block_device'));
$this->root->addChild(new vfsStreamFile('not_block_device'));
echo file_get_contents('vfs://root/test_block_device/size');

Here is the error:

file_get_contents(vfs://root/test_block_device/size): failed to open stream: "org\bovigo\vfs\vfsStreamWrapper::stream_open" call failed

Here is the closest issue I've found on this

However his was an issue with phpunit's teardown and mine happens mid-test.

Conor Wright
  • 41
  • 1
  • 3

2 Answers2

1

From the docs it seems that you need to add some content to your block device before you read from it: https://github.com/mikey179/vfsStream/wiki/BlockDevices

frak
  • 858
  • 1
  • 10
  • 30
0

Since I'm testing I didn't care about file_get_contents being run, just what it returned. So even though I didn't find out the issue. I solved my problem by overriding get_file_contents within the namespace of my test to return what I wanted.

If someone does find an answer to this issue I will gladly test their answer.

Conor Wright
  • 41
  • 1
  • 3