-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSQLiteConnectionTest.php
84 lines (75 loc) · 2.06 KB
/
SQLiteConnectionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/*
* This file is part of the DriftPHP Project
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <[email protected]>
*/
declare(strict_types=1);
namespace Drift\DBAL\Tests;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Drift\DBAL\Connection;
use Drift\DBAL\Credentials;
use Drift\DBAL\Driver\SQLiteDriver;
use Drift\DBAL\Exception\TableNotFoundException;
use React\EventLoop\LoopInterface;
use React\Promise\PromiseInterface;
/**
* Class SQLiteConnectionTest.
*/
class SQLiteConnectionTest extends ConnectionTest
{
/**
* {@inheritdoc}
*/
public function getConnection(LoopInterface $loop): Connection
{
$mysqlPlatform = new SqlitePlatform();
return Connection::createConnected(new SQLiteDriver(
$loop
), new Credentials(
'',
'',
'root',
'root',
':memory:'
), $mysqlPlatform);
}
/**
* Create database and table.
*
* @param Connection $connection
*
* @return PromiseInterface
*/
protected function createInfrastructure(Connection $connection): PromiseInterface
{
return $connection
->queryBySQL('CREATE TABLE test (id VARCHAR(255) PRIMARY KEY, field1 VARCHAR(255), field2 VARCHAR (255))')
->then(function () use ($connection) {
return $connection;
});
}
/**
* Drop infrastructure.
*
* @param Connection $connection
*
* @return PromiseInterface
*/
protected function dropInfrastructure(Connection $connection): PromiseInterface
{
return $connection
->queryBySQL('DROP TABLE test')
->then(function () use ($connection) {
return $connection;
}, function (TableNotFoundException $exception) use ($connection) {
// Silent pass
return $connection;
});
}
}