1<?php
2
3namespace Sabre;
4
5class TestUtil {
6
7    /**
8     * This function deletes all the contents of the temporary directory.
9     *
10     * @return void
11     */
12    static function clearTempDir() {
13
14        self::deleteTree(SABRE_TEMPDIR,false);
15
16    }
17
18
19    static private function deleteTree($path,$deleteRoot = true) {
20
21        foreach(scandir($path) as $node) {
22
23            if ($node=='.' || $node=='..') continue;
24            $myPath = $path.'/'. $node;
25            if (is_file($myPath)) {
26                unlink($myPath);
27            } else {
28                self::deleteTree($myPath);
29            }
30
31        }
32        if ($deleteRoot) {
33            rmdir($path);
34        }
35
36    }
37
38    static function getMySQLDB() {
39
40        try {
41            $pdo = new \PDO(SABRE_MYSQLDSN,SABRE_MYSQLUSER,SABRE_MYSQLPASS);
42            $pdo->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION);
43            return $pdo;
44        } catch (\PDOException $e) {
45            return null;
46        }
47
48    }
49
50    static function getSQLiteDB() {
51
52        $pdo = new \PDO('sqlite:'.SABRE_TEMPDIR.'/pdobackend');
53        $pdo->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION);
54        return $pdo;
55
56    }
57
58}
59