mirror of
https://github.com/dg/dibi.git
synced 2025-07-31 19:30:30 +02:00
tests: improved ini quering, removed duplicated tests
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
[sqlite3] ; default
|
||||
[sqlite] ; default
|
||||
driver = sqlite3
|
||||
database = :memory:
|
||||
system = sqlite
|
||||
|
||||
[sqlite-pdo]
|
||||
[sqlite pdo]
|
||||
driver = pdo
|
||||
dsn = "sqlite::memory:"
|
||||
system = sqlite
|
||||
@@ -16,7 +16,7 @@ password =
|
||||
charset = utf8
|
||||
system = mysql
|
||||
|
||||
[mysqli]
|
||||
[mysql improved]
|
||||
driver = mysqli
|
||||
host = 127.0.0.1
|
||||
username = root
|
||||
@@ -24,7 +24,7 @@ password =
|
||||
charset = utf8
|
||||
system = mysql
|
||||
|
||||
[mysql-pdo]
|
||||
[mysql pdo]
|
||||
driver = pdo
|
||||
dsn = "mysql:host=127.0.0.1"
|
||||
username = root
|
||||
@@ -38,7 +38,7 @@ username = postgres
|
||||
password =
|
||||
system = postgre
|
||||
|
||||
[postgre-pdo]
|
||||
[postgre pdo]
|
||||
driver = pdo
|
||||
dsn = "pgsql:host=127.0.0.1;dbname=dibi_test"
|
||||
username = postgres
|
||||
@@ -50,7 +50,7 @@ driver = odbc
|
||||
dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=data/odbc.mdb"
|
||||
system = odbc
|
||||
|
||||
[odbc-pdo]
|
||||
[odbc pdo]
|
||||
driver = pdo
|
||||
dsn = "odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=data/odbc.mdb"
|
||||
username =
|
||||
@@ -64,7 +64,7 @@ username = dibi
|
||||
password =
|
||||
system = sqlsrv
|
||||
|
||||
[sqlsrv-pdo]
|
||||
[sqlsrv pdo]
|
||||
driver = pdo
|
||||
dsn = "sqlsrv:Server=127.0.0.1"
|
||||
username = dibi
|
||||
@@ -77,7 +77,7 @@ username = dibi
|
||||
password =
|
||||
system = oracle
|
||||
|
||||
[oracle-pdo]
|
||||
[oracle pdo]
|
||||
driver = pdo
|
||||
dsn = "oci:dbname=dibi"
|
||||
username = dibi
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini mysql
|
||||
* @dataProvider? ../databases.ini mysql
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
@@ -1,17 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini
|
||||
* @dataProvider? ../databases.ini sqlsrv
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
if ($config['system'] !== 'mssql') {
|
||||
Tester\Environment::skip("Not supported system '$config[system]'.");
|
||||
}
|
||||
|
||||
$tests = function ($conn) {
|
||||
$version = $conn->getDriver()->getResource()->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
|
||||
|
@@ -1,17 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini
|
||||
* @dataProvider? ../databases.ini postgre
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
if ($config['system'] !== 'postgre') {
|
||||
Tester\Environment::skip("Not supported system '$config[system]'.");
|
||||
}
|
||||
|
||||
|
||||
$tests = function ($conn) {
|
||||
Assert::false($conn->query("SELECT 'AAxBB' LIKE %~like~", 'A_B')->fetchSingle());
|
||||
|
@@ -1,17 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini
|
||||
* @dataProvider ../databases.ini !=odbc
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
if ($config['system'] === 'odbc') {
|
||||
Tester\Environment::skip('Not supported.');
|
||||
}
|
||||
|
||||
$conn = new Dibi\Connection($config);
|
||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini mysqli
|
||||
* @dataProvider ../databases.ini
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Test: query exceptions.
|
||||
* @dataProvider ../databases.ini mysql-pdo
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
$conn = new Dibi\Connection($config);
|
||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('SELECT');
|
||||
}, 'Dibi\DriverException', "%a% error in your SQL syntax;%a%", 1064);
|
||||
|
||||
Assert::same('SELECT', $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
|
||||
}, 'Dibi\UniqueConstraintViolationException', "SQLSTATE[23000]: Duplicate entry '1' for key 'PRIMARY'", 1062);
|
||||
|
||||
Assert::same("INSERT INTO products (product_id, title) VALUES (1, 'New')", $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (title) VALUES (NULL)');
|
||||
}, 'Dibi\NotNullConstraintViolationException', "SQLSTATE[23000]: Column 'title' cannot be null", 1048);
|
||||
|
||||
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)');
|
||||
}, 'Dibi\ForeignKeyConstraintViolationException', '%a% a foreign key constraint fails %a%', 1452);
|
||||
|
||||
Assert::same('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)', $e->getSql());
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* Test: query exceptions.
|
||||
* @dataProvider ../databases.ini mysql
|
||||
* @dataProvider? ../databases.ini mysql
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
@@ -22,14 +22,14 @@ Assert::same('SELECT', $e->getSql());
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
|
||||
}, 'Dibi\UniqueConstraintViolationException', "Duplicate entry '1' for key 'PRIMARY'", 1062);
|
||||
}, 'Dibi\UniqueConstraintViolationException', "%a?%Duplicate entry '1' for key 'PRIMARY'", 1062);
|
||||
|
||||
Assert::same("INSERT INTO products (product_id, title) VALUES (1, 'New')", $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (title) VALUES (NULL)');
|
||||
}, 'Dibi\NotNullConstraintViolationException', "Column 'title' cannot be null", 1048);
|
||||
}, 'Dibi\NotNullConstraintViolationException', "%a?%Column 'title' cannot be null", 1048);
|
||||
|
||||
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
||||
|
||||
|
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Test: query exceptions.
|
||||
* @dataProvider ../databases.ini mysqli
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
$conn = new Dibi\Connection($config);
|
||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('SELECT');
|
||||
}, 'Dibi\DriverException', "%a% error in your SQL syntax;%a%", 1064);
|
||||
|
||||
Assert::same('SELECT', $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
|
||||
}, 'Dibi\UniqueConstraintViolationException', "Duplicate entry '1' for key 'PRIMARY'", 1062);
|
||||
|
||||
Assert::same("INSERT INTO products (product_id, title) VALUES (1, 'New')", $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (title) VALUES (NULL)');
|
||||
}, 'Dibi\NotNullConstraintViolationException', "Column 'title' cannot be null", 1048);
|
||||
|
||||
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)');
|
||||
}, 'Dibi\ForeignKeyConstraintViolationException', '%a% a foreign key constraint fails %a%', 1452);
|
||||
|
||||
Assert::same('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)', $e->getSql());
|
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Test: query exceptions.
|
||||
* @dataProvider ../databases.ini postgre-pdo
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
$conn = new Dibi\Connection($config);
|
||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('SELECT INTO');
|
||||
}, 'Dibi\DriverException', '%a% syntax error %A%');
|
||||
|
||||
Assert::same('SELECT INTO', $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
|
||||
}, 'Dibi\UniqueConstraintViolationException', '%a% violates unique constraint %A%', '23505');
|
||||
|
||||
Assert::same("INSERT INTO products (product_id, title) VALUES (1, 'New')", $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (title) VALUES (NULL)');
|
||||
}, 'Dibi\NotNullConstraintViolationException', '%a% null value in column "title" violates not-null constraint%A?%', '23502');
|
||||
|
||||
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)');
|
||||
}, 'Dibi\ForeignKeyConstraintViolationException', '%a% violates foreign key constraint %A%', '23503');
|
||||
|
||||
Assert::same('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)', $e->getSql());
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* Test: query exceptions.
|
||||
* @dataProvider ../databases.ini postgre
|
||||
* @dataProvider? ../databases.ini postgre
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
@@ -15,7 +15,7 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('SELECT INTO');
|
||||
}, 'Dibi\DriverException', 'syntax error %A%');
|
||||
}, 'Dibi\DriverException', '%a?%syntax error %A%');
|
||||
|
||||
Assert::same('SELECT INTO', $e->getSql());
|
||||
|
||||
@@ -29,7 +29,7 @@ Assert::same("INSERT INTO products (product_id, title) VALUES (1, 'New')", $e->g
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (title) VALUES (NULL)');
|
||||
}, 'Dibi\NotNullConstraintViolationException', 'null value in column "title" violates not-null constraint%A%', '23502');
|
||||
}, 'Dibi\NotNullConstraintViolationException', '%a?%null value in column "title" violates not-null constraint%A?%', '23502');
|
||||
|
||||
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
||||
|
||||
|
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Test: query exceptions.
|
||||
* @dataProvider ../databases.ini sqlite-pdo
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
$conn = new Dibi\Connection($config);
|
||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('SELECT');
|
||||
}, 'Dibi\DriverException', '%a% syntax error', 1);
|
||||
|
||||
Assert::same('SELECT', $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
|
||||
}, 'Dibi\UniqueConstraintViolationException', 'SQLSTATE[23000]: %a%', 19);
|
||||
|
||||
Assert::same("INSERT INTO products (product_id, title) VALUES (1, 'New')", $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (title) VALUES (NULL)');
|
||||
}, 'Dibi\NotNullConstraintViolationException', 'SQLSTATE[23000]: %a%', 19);
|
||||
|
||||
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('PRAGMA foreign_keys=true');
|
||||
$conn->query('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)');
|
||||
}, 'Dibi\ForeignKeyConstraintViolationException', 'SQLSTATE[23000]: %a%', 19);
|
||||
|
||||
Assert::same('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)', $e->getSql());
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* Test: query exceptions.
|
||||
* @dataProvider ../databases.ini sqlite3
|
||||
* @dataProvider ../databases.ini sqlite
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
@@ -22,7 +22,7 @@ Assert::same('SELECT', $e->getSql());
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
|
||||
}, 'Dibi\UniqueConstraintViolationException', '%a%', 19);
|
||||
}, 'Dibi\UniqueConstraintViolationException', NULL, 19);
|
||||
|
||||
Assert::same("INSERT INTO products (product_id, title) VALUES (1, 'New')", $e->getSql());
|
||||
|
||||
|
@@ -1,22 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini
|
||||
* @dataProvider ../databases.ini !=odbc
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
if ($config['system'] === 'odbc' || $config['driver'] === 'pdo') {
|
||||
Tester\Environment::skip('Not supported.');
|
||||
}
|
||||
|
||||
$conn = new Dibi\Connection($config);
|
||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
|
||||
$meta = $conn->getDatabaseInfo();
|
||||
try {
|
||||
$meta = $conn->getDatabaseInfo();
|
||||
} catch (Dibi\NotSupportedException $e) {
|
||||
Tester\Environment::skip($e->getMessage());
|
||||
}
|
||||
|
||||
Assert::same(3, count($meta->getTables()));
|
||||
|
||||
|
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini mysql-pdo
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
$conn = new Dibi\Connection($config);
|
||||
|
||||
$conn->query('USE dibi_test');
|
||||
$conn->query('DROP TABLE IF EXISTS timetest');
|
||||
$conn->query('CREATE TABLE timetest (col TIME NOT NULL) ENGINE=InnoDB');
|
||||
$conn->query('INSERT INTO timetest VALUES ("12:30:40")');
|
||||
Assert::equal(new DateInterval('PT12H30M40S'), $conn->fetchSingle('SELECT * FROM timetest'));
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini mysql
|
||||
* @dataProvider? ../databases.ini mysql
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini mysqli
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
$conn = new Dibi\Connection($config);
|
||||
|
||||
$conn->query('USE dibi_test');
|
||||
$conn->query('DROP TABLE IF EXISTS timetest');
|
||||
$conn->query('CREATE TABLE timetest (col TIME NOT NULL) ENGINE=InnoDB');
|
||||
$conn->query('INSERT INTO timetest VALUES ("12:30:40")');
|
||||
Assert::equal(new DateInterval('PT12H30M40S'), $conn->fetchSingle('SELECT * FROM timetest'));
|
Reference in New Issue
Block a user