mikey179/vfsstream
vfsStream provides a PHP stream wrapper for an in-memory virtual file system, ideal for unit tests. Mock files, directories, permissions, and content without touching disk, and use it with PHPUnit, SimpleTest, or any test framework.
Install via Composer: composer require --dev mikey179/vfsstream. Start by replacing direct filesystem operations in your tests with vfsStream::url('root/some/file.txt') and set up your virtual filesystem using vfsStream::setup('root', $structure). The most common first use case: mocking file reads/writes in a service class during unit tests—e.g., test a config reader without touching real files.
vfsStream::setup() at the beginning of a test (e.g., in setUp() or inline) to define directory/file hierarchy with optional content or custom file content types (vfsStreamContent, vfsStreamDirectory).vfsStream::url('root') as the base stream URL for all simulated I/O. Replace file_get_contents('/path/to/config.yml') with file_get_contents(vfsStream::url('root/config.yml')).org\bovigo\vfs\content\Content or extend vfsStreamFile to simulate special file types (e.g., empty but writable file, or one that throws on write).::setUpBeforeClass() or ::assertFileEquals() to validate expected outputs.stream_context_create()), set it via vfsStreamWrapper::setContext() before usage—especially useful for testing wrapper options or vfsStreamWrapper::register()/::unregister() in isolation tests.vfsStream::path() (deprecated) and vfsStream::url() differ: url() returns the full stream wrapper URL (vfs://root/file.txt), while path() returns a normalized path relative to root—but avoid path() as it's deprecated.0) as keys or names requires care—v1.6.3+ fixes some edge cases here.write() must return int|false, not just int).php://stream aliases—use vfsStreamWrapper::register()/::unregister() explicitly when testing stream wrapper registrations.fopen() with 'w+', ensure the target file or parent directory exists (create via vfsStream::create() or full structure), as vfsStream emulates real filesystem path existence checks.var_dump(vfsStream::root()->children()) to inspect the virtual structure after operations.How can I help you explore Laravel packages today?