2015-01-12 05:33:41 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider ../databases.ini
|
|
|
|
*/
|
|
|
|
|
2017-06-09 22:20:47 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-10-08 02:13:22 +02:00
|
|
|
use Dibi\Connection;
|
2017-07-11 12:27:26 +02:00
|
|
|
use Tester\Assert;
|
2015-01-12 05:33:41 +01:00
|
|
|
|
|
|
|
require __DIR__ . '/bootstrap.php';
|
|
|
|
|
|
|
|
|
2020-08-16 16:10:27 +02:00
|
|
|
test('', function () use ($config) {
|
2015-10-08 02:13:22 +02:00
|
|
|
$conn = new Connection($config);
|
2015-01-12 05:33:41 +01:00
|
|
|
Assert::true($conn->isConnected());
|
|
|
|
|
|
|
|
$conn->disconnect();
|
|
|
|
Assert::false($conn->isConnected());
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-08-16 16:10:27 +02:00
|
|
|
test('lazy', function () use ($config) {
|
2017-07-11 12:28:13 +02:00
|
|
|
$conn = new Connection($config + ['lazy' => true]);
|
2015-01-12 05:33:41 +01:00
|
|
|
Assert::false($conn->isConnected());
|
|
|
|
|
|
|
|
$conn->query('SELECT 1');
|
|
|
|
Assert::true($conn->isConnected());
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-08-16 16:10:27 +02:00
|
|
|
test('', function () use ($config) {
|
2018-04-17 15:01:30 +02:00
|
|
|
$conn = new Connection($config);
|
2015-01-12 05:33:41 +01:00
|
|
|
Assert::true($conn->isConnected());
|
|
|
|
|
|
|
|
Assert::null($conn->getConfig('lazy'));
|
|
|
|
Assert::same($config['driver'], $conn->getConfig('driver'));
|
2017-06-09 12:21:23 +02:00
|
|
|
Assert::type(Dibi\Driver::class, $conn->getDriver());
|
2015-01-12 05:33:41 +01:00
|
|
|
});
|
2016-06-13 21:17:57 +02:00
|
|
|
|
|
|
|
|
2020-08-16 16:10:27 +02:00
|
|
|
test('', function () use ($config) {
|
2016-06-13 21:17:57 +02:00
|
|
|
$conn = new Connection($config);
|
|
|
|
Assert::true($conn->isConnected());
|
|
|
|
|
|
|
|
$conn->disconnect();
|
|
|
|
Assert::false($conn->isConnected());
|
|
|
|
|
|
|
|
$conn->disconnect();
|
|
|
|
Assert::false($conn->isConnected());
|
|
|
|
});
|
2018-09-17 12:55:47 +02:00
|
|
|
|
|
|
|
|
2020-08-16 16:10:27 +02:00
|
|
|
test('', function () use ($config) {
|
2020-02-14 12:40:54 +01:00
|
|
|
$conn = new Connection($config);
|
|
|
|
Assert::equal('hello', $conn->query('SELECT %s', 'hello')->fetchSingle());
|
|
|
|
|
|
|
|
$conn->disconnect();
|
|
|
|
|
|
|
|
$conn->connect();
|
|
|
|
Assert::equal('hello', $conn->query('SELECT %s', 'hello')->fetchSingle());
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2021-12-12 03:54:42 +01:00
|
|
|
test('', function () use ($config) {
|
|
|
|
$conn = new Connection($config);
|
|
|
|
Assert::true($conn->isConnected());
|
|
|
|
|
|
|
|
$conn->__destruct();
|
|
|
|
Assert::false($conn->isConnected());
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-08-16 16:10:27 +02:00
|
|
|
test('', function () use ($config) {
|
2018-09-17 12:55:47 +02:00
|
|
|
Assert::exception(function () use ($config) {
|
|
|
|
new Connection($config + ['onConnect' => '']);
|
|
|
|
}, InvalidArgumentException::class, "Configuration option 'onConnect' must be array.");
|
|
|
|
|
|
|
|
$e = Assert::exception(function () use ($config) {
|
|
|
|
new Connection($config + ['onConnect' => ['STOP']]);
|
|
|
|
}, Dibi\DriverException::class);
|
|
|
|
Assert::same('STOP', $e->getSql());
|
|
|
|
|
|
|
|
$e = Assert::exception(function () use ($config) {
|
|
|
|
new Connection($config + ['onConnect' => [['STOP %i', 123]]]);
|
|
|
|
}, Dibi\DriverException::class);
|
|
|
|
Assert::same('STOP 123', $e->getSql());
|
|
|
|
|
|
|
|
// lazy
|
|
|
|
$conn = new Connection($config + ['lazy' => true, 'onConnect' => ['STOP']]);
|
|
|
|
$e = Assert::exception(function () use ($conn) {
|
|
|
|
$conn->query('SELECT 1');
|
|
|
|
}, Dibi\DriverException::class);
|
|
|
|
Assert::same('STOP', $e->getSql());
|
|
|
|
});
|