This package is abandoned and no longer maintained. No replacement package was suggested.

0.1 2013-05-22 09:56 UTC

This package is not auto-updated.

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


Mock FileSystem for use with your PHPUnit tests.

Build Status


To install via composer add dantudor/mockfs as a dev dependency in your composer.json file:

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


As this is still in development only the following commands have been tested and confirmed:

  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)


Add a Directory

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

Add a File

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

Setting Permissions, Owner Id and Group Id

$mockFs = new MockFs\MockFs();

$directory = $mockFs->getFileSystem()->getChild('Directory');

All file system objects are created recursively by default.