adlawson/vfs
Virtual file system for PHP using the stream wrapper API. Mount a vfs:// scheme and use built-in functions (fopen, require, file_get_contents) or filesystem libraries like Symfony/Laravel. Emulates real streams, including PHP warnings and edge cases.
Illuminate\Filesystem and Illuminate\Filesystem\FilesystemAdapter, enabling seamless mocking of Storage::disk() or Storage::cloud() in tests.artisan storage:link).eval() risks.vfs://), requiring no Laravel-specific modifications. This ensures compatibility with existing codebases.Filesystem, Cache, or custom classes) for testing, following Laravel’s service container patterns.// In a test case:
$fs = \Vfs\FileSystem::factory('vfs://');
$fs->mount();
Storage::fake('local'); // Laravel's fake disk
Storage::disk('local')->put('test.txt', 'Hello');
$this->assertEquals('Hello', file_get_contents('vfs://test.txt'));
vfs://. Mitigation: Use a unique prefix (e.g., laravel-vfs://).| Risk Area | Assessment |
|---|---|
| Compatibility | High: Uses PHP’s standard stream API, ensuring broad compatibility with Laravel’s filesystem abstractions and third-party libraries (e.g., Symfony’s Filesystem). |
| Performance | Medium: In-memory operations are fast, but stream wrapper overhead may introduce minor latency for large-scale file operations (e.g., testing bulk uploads). Benchmark against Laravel’s Storage::fake(). |
| Testing Coverage | Medium: Package has unit tests, but Laravel-specific edge cases (e.g., interaction with Illuminate\Filesystem\FilesystemAdapter) may need validation. |
| Maintenance | Low: MIT-licensed and actively maintained, though lacking advanced features (symlinks, locks). Contributions or forks could address gaps. |
| Security | Low: Isolated to VFS; no direct filesystem access. Runtime require operations are safe as long as paths are sanitized (e.g., using Vfs\Node interfaces). |
| Laravel-Specific Risks | Medium: Custom adapters may be needed for Illuminate\Filesystem\FilesystemAdapter or cloud storage simulations. |
Storage::fake() or supplement it? For example, can VFS handle cloud storage simulations (e.g., S3) that Storage::fake() doesn’t support?require 'vfs://generated.php') interact with Laravel’s autoloader or class aliasing?Storage::fake() or tmpfs?Illuminate\Filesystem\FilesystemAdapter with memory://)?vfs:// mounts)?Mockery, tmpfs, or Laravel’s Storage::fake()) that better fit specific use cases?Storage facade operations (e.g., put, get, delete).Storage::fake() for disk/cloud operations.Illuminate\Filesystem or League\Flysystem integrations.artisan storage:link).eval() for runtime file execution.file_put_contents, Storage::disk()->put(), or Storage::cloud()->put() with VFS equivalents.// Before (real filesystem)
Storage::disk('local')->put('test.txt', 'Hello');
// After (VFS)
$fs = \Vfs\FileSystem::factory('vfs://');
$fs->mount();
file_put_contents('vfs://test.txt', 'Hello');
FilesystemManager to support VFS:
Storage::extend('vfs', function ($app, $config) {
$fs = \Vfs\FileSystem::factory('vfs://');
$fs->mount();
return new \Illuminate\Filesystem\FilesystemAdapter(
new \Vfs\Adapter\StreamWrapperAdapter('vfs://'),
'vfs',
$config
);
});
Storage::fake('vfs');
Storage::disk('vfs')->put('file.txt', 'Content');
Storage events (e.g., filesystem.created).$fs = \Vfs\FileSystem::factory('vfs://');
$fs->mount();
file_put_contents('vfs://PluginConfig.php', '<?php return ["key" => "value"];');
$config = require 'vfs://PluginConfig.php';
Storage::fake():
Storage::fake() for cloud storage in the same test suite.Storage::fake(['local' => true, 's3' => false]); // VFS for local, fake for S3
| Component | Compatibility Notes |
|---|---|
| Laravel Filesystem | High: Works seamlessly with Illuminate\Filesystem and |
How can I help you explore Laravel packages today?