Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a mock system object to make it easier to create/remove mock syst…
…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.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
package/Aura.Framework/tests/Aura/Framework/Mock/System.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |