Skip to content
Guido Scialfa edited this page Feb 28, 2020 · 4 revisions

Available since release 1.4.0

Block devices can also be mocked in the filesystem. Allowing checks from commands like filetype to return block, while internally acting like a file. The block devices can be added like any other object in vfs.

$root = vfsStream::setup();

$block = vfsStream::newBlock('blockDevice');

// Since in a real file system, block devices are really just files
// vfsStream handles it the same way
$block->withContent('Content in block device');


$root->addChild($block);

Block devices can also be created easily with the complex structure method when mocking a large structure.

$structure = array(
                'Core' => array(
                    'AbstractFactory' => array(
                        'test.php' => 'some text content',
                        'other.php' => 'Some more text content',
                        'Invalid.csv' => 'Something else',
                    ),
                '[BlockDevice]' => 'Block Device Content',
                'badlocation.php' => 'some bad content',
            )
        );

Placing brackets around the filename will create a block device with the name enclosed inside it. The above example would be accessed:

filetype(vfsStream::url('root/BlockDevice'));
Clone this wiki locally