此包已被弃用且不再维护。未建议替代包。

0.1 2013-05-22 09:56 UTC

This package is not auto-updated.

Last update: 2018-10-01 00:16:13 UTC


README

为与您的PHPUnit测试一起使用而设计的Mock文件系统。

Build Status

安装

要通过Composer安装,请在您的 composer.json 文件中将 dantudor/mockfs 添加为开发依赖项

{
    "require-dev": {
        "dantudor/mockfs": "dev/master"
    }
}

功能

由于仍在开发中,以下命令已测试并确认

  1. is_dir (string $filename)
  2. mkdir (string $pathname)
  3. rmdir (string $dirname)
  4. file_exists (string $filename)
  5. is_readable (string $filename)
  6. file_get_contents (string $filename)
  7. rename (string $pathFrom, string $pathTo)

初始化

添加目录

# addDirectory($name, $path = '/', $recursive = true)
$mockFs = new MockFs\MockFs();
$mockFs->getFileSystem()
    ->addDirectory('Directory')
    ->addDirectory('Another Directory, '/Directory')
    ->addDirectory('Me too', '/New Folder')
;

添加文件

# addFile($name, $contents = null, $path = '/', $recursive = true)
$mockFs = new MockFs\MockFs();
$mockFs->getFileSystem()
    ->addFile('file.txt', 'File Contents')
    ->addFile('file.txt', 'File Contents', '/New Folder')
;

设置权限、所有者ID和组ID

$mockFs = new MockFs\MockFs();
$mockFs->getFileSystem()
    ->addDirectory('Directory')
;

$directory = $mockFs->getFileSystem()->getChild('Directory');
$directory
    ->setPermissions(0600)
    ->setOwnerId(501)
    ->setGroupId(100)
;

默认情况下,所有文件系统对象都是递归创建的。