dantudor/mockfs

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


README

Mock FileSystem for use with your PHPUnit tests.

Build Status

Installation

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

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

Features

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)

Priming

Add a Directory

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

Add a File

# 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')
;

Setting Permissions, Owner Id and Group Id

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

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

All file system objects are created recursively by default.