1<?php 2 3/** 4 * Helper class with some filesystem utilities. 5 */ 6class TestUtils { 7 8 /** 9 * helper for recursive copy() 10 * 11 * @static 12 * @param $destdir string 13 * @param $source string 14 */ 15 public static function rcopy($destdir, $source) { 16 if (!is_dir($source)) { 17 copy($source, $destdir.'/'.basename($source)); 18 } else { 19 $newdestdir = $destdir.'/'.basename($source); 20 mkdir($newdestdir); 21 22 $dh = dir($source); 23 while (false !== ($entry = $dh->read())) { 24 if ($entry == '.' || $entry == '..') { 25 continue; 26 } 27 TestUtils::rcopy($newdestdir, $source.'/'.$entry); 28 } 29 $dh->close(); 30 } 31 } 32 33 /** 34 * helper for recursive rmdir()/unlink() 35 * 36 * @static 37 * @param $target string 38 */ 39 public static function rdelete($target) { 40 if (!is_dir($target)) { 41 unlink($target); 42 } else { 43 $dh = dir($target); 44 while (false !== ($entry = $dh->read())) { 45 if ($entry == '.' || $entry == '..') { 46 continue; 47 } 48 TestUtils::rdelete("$target/$entry"); 49 } 50 $dh->close(); 51 rmdir($target); 52 } 53 } 54 55 /** 56 * helper to append text to a file 57 * 58 * @static 59 * @param $file string 60 * @param $text string 61 */ 62 public static function fappend($file, $text) { 63 $fh = fopen($file, 'a'); 64 fwrite($fh, $text); 65 fclose($fh); 66 } 67 68} 69