-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMysqlConnectionTest.php
88 lines (79 loc) · 2.26 KB
/
MysqlConnectionTest.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
85
86
87
88
<?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\MySqlPlatform;
use Drift\DBAL\Connection;
use Drift\DBAL\Credentials;
use Drift\DBAL\Driver\MysqlDriver;
use Drift\DBAL\Exception\TableNotFoundException;
use React\EventLoop\LoopInterface;
use React\Promise\PromiseInterface;
/**
* Class MysqlConnectionTest.
*/
class MysqlConnectionTest extends ConnectionTest
{
/**
* {@inheritdoc}
*/
protected function getConnection(LoopInterface $loop): Connection
{
$mysqlPlatform = new MySqlPlatform();
return Connection::createConnected(new MysqlDriver(
$loop
), new Credentials(
'127.0.0.1',
'3306',
'root',
'root',
'test'
), $mysqlPlatform);
}
/**
* Create database and table.
*
* @param Connection $connection
*
* @return PromiseInterface
*/
protected function createInfrastructure(Connection $connection): PromiseInterface
{
return $connection
->queryBySQL('CREATE TABLE IF NOT EXISTS test (id VARCHAR(255) PRIMARY KEY, field1 VARCHAR(255), field2 VARCHAR (255))')
->then(function () use ($connection) {
return $connection
->queryBySQL('TRUNCATE TABLE test')
->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;
});
}
}