📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials PHPUnit Testing Testing File System

Testing File System

5 min read
Test file system code safely with vfsStream virtual filesystem — no real disk I/O required.

Virtual File System Testing

composer require --dev mikey179/vfsstream

use org\bovigo\vfs\vfsStream;

class FileTest extends TestCase {
    protected function setUp(): void {
        $this->root = vfsStream::setup("root", null, [
            "uploads" => ["photo.jpg" => "fake data"],
        ]);
    }
    public function testProcessesFile(): void {
        $proc = new FileProcessor(vfsStream::url("root/uploads"));
        $this->assertTrue($proc->process("photo.jpg"));
        $this->assertFileExists(vfsStream::url("root/uploads/thumb.jpg"));
    }
}