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 if (!is_dir($newdestdir)) { 21 mkdir($newdestdir); 22 } 23 24 $dh = dir($source); 25 while (false !== ($entry = $dh->read())) { 26 if ($entry == '.' || $entry == '..') { 27 continue; 28 } 29 TestUtils::rcopy($newdestdir, $source.'/'.$entry); 30 } 31 $dh->close(); 32 } 33 } 34 35 /** 36 * helper for recursive rmdir()/unlink() 37 * 38 * @static 39 * @param $target string 40 */ 41 public static function rdelete($target) { 42 if (!is_dir($target)) { 43 unlink($target); 44 } else { 45 $dh = dir($target); 46 while (false !== ($entry = $dh->read())) { 47 if ($entry == '.' || $entry == '..') { 48 continue; 49 } 50 TestUtils::rdelete("$target/$entry"); 51 } 52 $dh->close(); 53 rmdir($target); 54 } 55 } 56 57 /** 58 * helper to append text to a file 59 * 60 * @static 61 * @param $file string 62 * @param $text string 63 */ 64 public static function fappend($file, $text) { 65 $fh = fopen($file, 'a'); 66 fwrite($fh, $text); 67 fclose($fh); 68 } 69 70} 71