streams/vendor/sabre/dav/tests/Sabre/TestUtil.php

72 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace Sabre;
class TestUtil {
/**
* This function deletes all the contents of the temporary directory.
*
* @return void
*/
static function clearTempDir() {
2016-05-28 15:46:24 +00:00
self::deleteTree(SABRE_TEMPDIR, false);
}
2016-05-28 15:46:24 +00:00
private static function deleteTree($path, $deleteRoot = true) {
2016-05-28 15:46:24 +00:00
foreach (scandir($path) as $node) {
2016-05-28 15:46:24 +00:00
if ($node == '.' || $node == '..') continue;
$myPath = $path . '/' . $node;
if (is_file($myPath)) {
unlink($myPath);
} else {
self::deleteTree($myPath);
}
}
if ($deleteRoot) {
rmdir($path);
}
}
static function getMySQLDB() {
try {
2016-05-28 15:46:24 +00:00
$pdo = new \PDO(SABRE_MYSQLDSN, SABRE_MYSQLUSER, SABRE_MYSQLPASS);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return $pdo;
} catch (\PDOException $e) {
return null;
}
}
static function getSQLiteDB() {
2016-05-28 15:46:24 +00:00
$pdo = new \PDO('sqlite:' . SABRE_TEMPDIR . '/pdobackend');
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return $pdo;
}
2016-05-28 15:46:24 +00:00
static function getPgSqlDB() {
//try {
$pdo = new \PDO(SABRE_PGSQLDSN);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return $pdo;
//} catch (\PDOException $e) {
// return null;
//}
}
}