ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
TestUtil.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre;
4
5class TestUtil {
6
12 static function clearTempDir() {
13
14 self::deleteTree(SABRE_TEMPDIR, false);
15
16 }
17
18
19 private static 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 static function getPgSqlDB() {
59
60 //try {
61 $pdo = new \PDO(SABRE_PGSQLDSN);
62 $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
63 return $pdo;
64 //} catch (\PDOException $e) {
65 // return null;
66 //}
67
68 }
69
70
71}
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
static clearTempDir()
This function deletes all the contents of the temporary directory.
Definition: TestUtil.php:12
static getSQLiteDB()
Definition: TestUtil.php:50
static getPgSqlDB()
Definition: TestUtil.php:58
static deleteTree($path, $deleteRoot=true)
Definition: TestUtil.php:19
static getMySQLDB()
Definition: TestUtil.php:38
$pdo
Definition: migrateto20.php:62