Skip to content

Commit

Permalink
add a mock system object to make it easier to create/remove mock syst…
Browse files Browse the repository at this point in the history
…em setups
  • Loading branch information
Paul M. Jones committed Jan 2, 2012
1 parent c8072e8 commit c578e33
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions package/Aura.Framework/tests/Aura/Framework/Mock/System.php
@@ -0,0 +1,48 @@
<?php
namespace Aura\Framework\Mock;
use Aura\Framework\System as RealSystem;
class System extends RealSystem
{
static public function newInstance()
{
$root = dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'tmp';
$system = new self($root);
return $system;
}

public function create()
{
$dir = $this->getRootPath();

if (is_dir($dir)) {
$this->remove();
}

if (! is_dir($dir)) {
mkdir($dir);
}

mkdir($this->getConfigPath());
mkdir($this->getIncludePath());
mkdir($this->getPackagePath());
mkdir($this->getTmpPath());
mkdir($this->getWebPath());
}

public function remove()
{
$dir = $this->getRootPath();
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($iterator as $path) {
if ($path->isDir()) {
rmdir($path->__toString());
} else {
unlink($path->__toString());
}
}
rmdir($dir);
}
}

0 comments on commit c578e33

Please sign in to comment.