vfs = vfsStream::setup('root'); $this->vfsPath = vfsStream::url('root'); $this->fs = new Filesystem(); clearstatcache(); } public function testMkdir(): void { $path = $this->vfsPath . DS . 'tests' . DS . 'first' . DS . 'second' . DS . 'third'; $this->fs->mkdir($path); $this->assertTrue(is_dir($path)); } public function testDumpFile(): void { $path = $this->vfsPath . DS . 'foo.txt'; $this->fs->dumpFile($path, 'bar'); $this->assertEquals(file_get_contents($path), 'bar'); $path = $this->vfsPath . DS . 'empty.txt'; $this->fs->dumpFile($path, ''); $this->assertSame(file_get_contents($path), ''); } public function testCopyDir(): void { $return = $this->fs->copyDir(WWW_ROOT, $this->vfsPath . DS . 'dest'); $this->assertTrue($return); } public function testDeleteDir(): void { $structure = [ 'Core' => [ 'AbstractFactory' => [ 'test.php' => 'some text content', 'other.php' => 'Some more text content', 'Invalid.csv' => 'Something else', ], 'AnEmptyFolder' => [], 'badlocation.php' => 'some bad content', ], ]; vfsStream::create($structure); $return = $this->fs->deleteDir($this->vfsPath . DS . 'Core'); $this->assertTrue($return); } /** * Tests deleteDir() on directory that contains symlinks */ public function testDeleteDirWithLinks(): void { $path = TMP . 'fs_links_test'; // phpcs:ignore @mkdir($path); $target = $path . DS . 'target'; // phpcs:ignore @mkdir($target); $link = $path . DS . 'link'; // phpcs:ignore @symlink($target, $link); $this->assertTrue($this->fs->deleteDir($path)); $this->assertFalse(file_exists($link)); } }