diff options
author | Andreas Gohr <gohr@cosmocode.de> | 2012-04-17 15:38:03 +0200 |
---|---|---|
committer | Andreas Gohr <gohr@cosmocode.de> | 2012-04-17 15:38:03 +0200 |
commit | e048653b52aad13b5964e1626192ffee2211870b (patch) | |
tree | d5aaa7168f1496aa8262920ad2320a5d3668b6a5 /_testing/core/TestUtils.php | |
parent | c45ce44912e3e54ecdf0a19af2d7df1960aa2962 (diff) | |
download | rpg-e048653b52aad13b5964e1626192ffee2211870b.tar.gz rpg-e048653b52aad13b5964e1626192ffee2211870b.tar.bz2 |
moved functions and classes out of bootstrap
There's still more that I'd like to moved out. bootstrap should not
contain any logic but only call the appropriate functions for setup the
test environment.
Diffstat (limited to '_testing/core/TestUtils.php')
-rw-r--r-- | _testing/core/TestUtils.php | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/_testing/core/TestUtils.php b/_testing/core/TestUtils.php new file mode 100644 index 000000000..4fd56e85d --- /dev/null +++ b/_testing/core/TestUtils.php @@ -0,0 +1,52 @@ +<?php + +class TestUtils { + + /** + * helper for recursive copy() + */ + static function rcopy($destdir, $source) { + if (!is_dir($source)) { + copy($source, $destdir.'/'.basename($source)); + } else { + $newdestdir = $destdir.'/'.basename($source); + mkdir($newdestdir); + + $dh = dir($source); + while (false !== ($entry = $dh->read())) { + if ($entry == '.' || $entry == '..') { + continue; + } + TestUtils::rcopy($newdestdir, $source.'/'.$entry); + } + $dh->close(); + } + } + + /** + * helper for recursive rmdir()/unlink() + */ + static function rdelete($target) { + if (!is_dir($target)) { + unlink($target); + } else { + $dh = dir($target); + while (false !== ($entry = $dh->read())) { + if ($entry == '.' || $entry == '..') { + continue; + } + TestUtils::rdelete("$target/$entry"); + } + $dh->close(); + rmdir($target); + } + } + + // helper to append text to a file + static function fappend($file, $text) { + $fh = fopen($file, 'a'); + fwrite($fh, $text); + fclose($fh); + } + +} |