Utilities.php

<?php

namespace Tlf\Tester;

/**
 * Convenience methods to call from inside tests
 */
trait Utilities {


    protected function startOb(){
        return \Tlf\Tester\Utility::startOb();
    }
    protected function endOb($ob_level){
        return \Tlf\Tester\Utility::endOb($ob_level);
    }

    /**
     * get path to a file inside the current working directory
     */
    public function file($rel_path){
        return $this->cli->pwd.'/'.$rel_path;
    }

    /**
     * Delete all files in a directory
     * @param $dir the directory to delete
     * @param $recursive pass true for recursive deletion
     */
    public function empty_dir($dir, $recursive=false){
        if (!is_dir($dir))return;
        foreach (scandir($dir) as $f){
            if ($f=='.' || $f == '..')continue;
            if (is_file($dir.'/'.$f)){
                unlink($dir.'/'.$f);
            } else if ($recursive===true&&is_dir($dir.'/'.$f)){
                $this->empty_dir($dir.'/'.$f);
            }
        }
    }
}