diff options
author | Andreas Gohr <andi@splitbrain.org> | 2012-05-01 12:38:41 -0700 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2012-05-01 12:38:41 -0700 |
commit | 3c0d44f1aa44d3ac3d8b9e652d172b1eda680bbf (patch) | |
tree | 5a9a42fb720a774c2bb8c393d3046d7beb11bf8f /_test/core/TestUtils.php | |
parent | e67fdd7b79e8f05b9e7e9164691114222e3c377c (diff) | |
parent | 1831d8a0f848f2e0dd5ef195791b6beaa5d1acb7 (diff) | |
download | rpg-3c0d44f1aa44d3ac3d8b9e652d172b1eda680bbf.tar.gz rpg-3c0d44f1aa44d3ac3d8b9e652d172b1eda680bbf.tar.bz2 |
Merge pull request #96 from dom-mel/phpunit
Replace SimpleTest with PHPUnit
Diffstat (limited to '_test/core/TestUtils.php')
-rw-r--r-- | _test/core/TestUtils.php | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/_test/core/TestUtils.php b/_test/core/TestUtils.php new file mode 100644 index 000000000..2750a3edf --- /dev/null +++ b/_test/core/TestUtils.php @@ -0,0 +1,70 @@ +<?php + +/** + * Helper class with some filesystem utilities. + */ +class TestUtils { + + /** + * helper for recursive copy() + * + * @static + * @param $destdir string + * @param $source string + */ + public static function rcopy($destdir, $source) { + if (!is_dir($source)) { + copy($source, $destdir.'/'.basename($source)); + } else { + $newdestdir = $destdir.'/'.basename($source); + if (!is_dir($newdestdir)) { + 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 + * @param $target string + */ + public 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 + * @param $file string + * @param $text string + */ + public static function fappend($file, $text) { + $fh = fopen($file, 'a'); + fwrite($fh, $text); + fclose($fh); + } + +} |