1<?php
2
3namespace Sabre\CardDAV\Backend;
4
5require_once 'Sabre/TestUtil.php';
6
7class PDOSqliteTest extends AbstractPDOTest {
8
9    function tearDown() {
10
11        if (file_exists(SABRE_TEMPDIR . '/pdobackend')) unlink(SABRE_TEMPDIR . '/pdobackend');
12        if (file_exists(SABRE_TEMPDIR . '/pdobackend2')) unlink(SABRE_TEMPDIR . '/pdobackend2');
13
14    }
15
16    /**
17     * @return PDO
18     */
19    function getPDO() {
20
21        if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
22        $pdo = new \PDO('sqlite:'.SABRE_TEMPDIR.'/pdobackend');
23        $pdo->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION);
24
25        $pdo->query("DROP TABLE IF EXISTS addressbooks");
26        $pdo->query("DROP TABLE IF EXISTS addressbookchanges");
27        $pdo->query("DROP TABLE IF EXISTS cards");
28
29        $queries = explode(
30            ';',
31            file_get_contents(__DIR__ . '/../../../../examples/sql/sqlite.addressbooks.sql')
32        );
33
34        foreach($queries as $query) {
35            $query = trim($query," \r\n\t");
36            if ($query)
37                $pdo->exec($query);
38        }
39
40        return $pdo;
41
42    }
43
44}
45
46