summaryrefslogtreecommitdiff
path: root/_test/core/TestUtils.php
diff options
context:
space:
mode:
authorGuy Brand <gb@unistra.fr>2012-09-10 17:04:45 +0200
committerGuy Brand <gb@unistra.fr>2012-09-10 17:04:45 +0200
commit0f8ac4e8c5872a6b68b350f96a9ecde0291edefa (patch)
treead7938bb4143d5e5a38fd7a8d131e4171aec657d /_test/core/TestUtils.php
parent58ec8fa9128e4581749955de87530f432e387588 (diff)
parentb31fcef02fd24b3e746c9618e77152c7b84c2f2a (diff)
downloadrpg-0f8ac4e8c5872a6b68b350f96a9ecde0291edefa.tar.gz
rpg-0f8ac4e8c5872a6b68b350f96a9ecde0291edefa.tar.bz2
Merge branch 'master' into stable
Diffstat (limited to '_test/core/TestUtils.php')
-rw-r--r--_test/core/TestUtils.php70
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);
+ }
+
+}