From 5aab1ff023bf6dd751ad360252e90201976cc324 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 4 Nov 2015 14:36:38 +0100 Subject: [PATCH] tests: improved ini quering, removed duplicated tests --- tests/databases.sample.ini | 16 +++++----- tests/dibi/Fluent.fetch.limit.phpt | 2 +- tests/dibi/PdoMssql.limits.phpt | 6 +--- tests/dibi/Postgre.like.phpt | 6 +--- tests/dibi/Result.meta.phpt | 6 +--- tests/dibi/Row.phpt | 2 +- tests/dibi/exceptions.mysql-pdo.phpt | 41 ------------------------- tests/dibi/exceptions.mysql.phpt | 6 ++-- tests/dibi/exceptions.mysqli.phpt | 41 ------------------------- tests/dibi/exceptions.postgre-pdo.phpt | 41 ------------------------- tests/dibi/exceptions.postgre.phpt | 6 ++-- tests/dibi/exceptions.sqlite-pdo.phpt | 42 -------------------------- tests/dibi/exceptions.sqlite.phpt | 4 +-- tests/dibi/meta.phpt | 13 ++++---- tests/dibi/mysql-pdo.time.phpt | 17 ----------- tests/dibi/mysql.time.phpt | 2 +- tests/dibi/mysqli.time.phpt | 17 ----------- 17 files changed, 28 insertions(+), 240 deletions(-) delete mode 100644 tests/dibi/exceptions.mysql-pdo.phpt delete mode 100644 tests/dibi/exceptions.mysqli.phpt delete mode 100644 tests/dibi/exceptions.postgre-pdo.phpt delete mode 100644 tests/dibi/exceptions.sqlite-pdo.phpt delete mode 100644 tests/dibi/mysql-pdo.time.phpt delete mode 100644 tests/dibi/mysqli.time.phpt diff --git a/tests/databases.sample.ini b/tests/databases.sample.ini index 990b7c38..eac7d0c1 100644 --- a/tests/databases.sample.ini +++ b/tests/databases.sample.ini @@ -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 diff --git a/tests/dibi/Fluent.fetch.limit.phpt b/tests/dibi/Fluent.fetch.limit.phpt index 70e4b609..6695b786 100644 --- a/tests/dibi/Fluent.fetch.limit.phpt +++ b/tests/dibi/Fluent.fetch.limit.phpt @@ -1,7 +1,7 @@ getDriver()->getResource()->getAttribute(PDO::ATTR_SERVER_VERSION); diff --git a/tests/dibi/Postgre.like.phpt b/tests/dibi/Postgre.like.phpt index 3e4febd4..716bb0f7 100644 --- a/tests/dibi/Postgre.like.phpt +++ b/tests/dibi/Postgre.like.phpt @@ -1,17 +1,13 @@ query("SELECT 'AAxBB' LIKE %~like~", 'A_B')->fetchSingle()); diff --git a/tests/dibi/Result.meta.phpt b/tests/dibi/Result.meta.phpt index 1731cd6d..0357384f 100644 --- a/tests/dibi/Result.meta.phpt +++ b/tests/dibi/Result.meta.phpt @@ -1,17 +1,13 @@ loadFile(__DIR__ . "/data/$config[system].sql"); diff --git a/tests/dibi/Row.phpt b/tests/dibi/Row.phpt index 90950ca7..b9aed1d3 100644 --- a/tests/dibi/Row.phpt +++ b/tests/dibi/Row.phpt @@ -1,7 +1,7 @@ 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()); diff --git a/tests/dibi/exceptions.mysql.phpt b/tests/dibi/exceptions.mysql.phpt index 78751917..4f20c517 100644 --- a/tests/dibi/exceptions.mysql.phpt +++ b/tests/dibi/exceptions.mysql.phpt @@ -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()); diff --git a/tests/dibi/exceptions.mysqli.phpt b/tests/dibi/exceptions.mysqli.phpt deleted file mode 100644 index 8af4775a..00000000 --- a/tests/dibi/exceptions.mysqli.phpt +++ /dev/null @@ -1,41 +0,0 @@ -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()); diff --git a/tests/dibi/exceptions.postgre-pdo.phpt b/tests/dibi/exceptions.postgre-pdo.phpt deleted file mode 100644 index 5b4d2f07..00000000 --- a/tests/dibi/exceptions.postgre-pdo.phpt +++ /dev/null @@ -1,41 +0,0 @@ -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()); diff --git a/tests/dibi/exceptions.postgre.phpt b/tests/dibi/exceptions.postgre.phpt index 3c705569..de38df98 100644 --- a/tests/dibi/exceptions.postgre.phpt +++ b/tests/dibi/exceptions.postgre.phpt @@ -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()); diff --git a/tests/dibi/exceptions.sqlite-pdo.phpt b/tests/dibi/exceptions.sqlite-pdo.phpt deleted file mode 100644 index df447ae8..00000000 --- a/tests/dibi/exceptions.sqlite-pdo.phpt +++ /dev/null @@ -1,42 +0,0 @@ -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()); diff --git a/tests/dibi/exceptions.sqlite.phpt b/tests/dibi/exceptions.sqlite.phpt index cf0d5c2d..e0fc3d54 100644 --- a/tests/dibi/exceptions.sqlite.phpt +++ b/tests/dibi/exceptions.sqlite.phpt @@ -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()); diff --git a/tests/dibi/meta.phpt b/tests/dibi/meta.phpt index 4b62581a..a435943e 100644 --- a/tests/dibi/meta.phpt +++ b/tests/dibi/meta.phpt @@ -1,22 +1,21 @@ 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())); diff --git a/tests/dibi/mysql-pdo.time.phpt b/tests/dibi/mysql-pdo.time.phpt deleted file mode 100644 index 1b09290f..00000000 --- a/tests/dibi/mysql-pdo.time.phpt +++ /dev/null @@ -1,17 +0,0 @@ -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')); diff --git a/tests/dibi/mysql.time.phpt b/tests/dibi/mysql.time.phpt index cb7b7656..f0fd1cd7 100644 --- a/tests/dibi/mysql.time.phpt +++ b/tests/dibi/mysql.time.phpt @@ -1,7 +1,7 @@ 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'));