2015-10-13 18:08:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test: query exceptions.
|
2015-11-04 14:36:38 +01:00
|
|
|
* @dataProvider ../databases.ini sqlite
|
2015-10-13 18:08:04 +02:00
|
|
|
*/
|
|
|
|
|
2017-06-09 22:20:47 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-10-13 18:08:04 +02:00
|
|
|
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');
|
2018-09-17 13:28:10 +02:00
|
|
|
}, Dibi\DriverException::class, '%a%', 1);
|
2015-10-13 18:08:04 +02:00
|
|
|
|
|
|
|
Assert::same('SELECT', $e->getSql());
|
|
|
|
|
|
|
|
|
|
|
|
$e = Assert::exception(function () use ($conn) {
|
|
|
|
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
|
2017-07-11 12:28:13 +02:00
|
|
|
}, Dibi\UniqueConstraintViolationException::class, null, 19);
|
2015-10-13 18:08:04 +02:00
|
|
|
|
|
|
|
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)');
|
2017-07-11 12:28:13 +02:00
|
|
|
}, Dibi\NotNullConstraintViolationException::class, null, 19);
|
2015-10-13 18:08:04 +02:00
|
|
|
|
|
|
|
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)');
|
2017-07-11 12:28:13 +02:00
|
|
|
}, Dibi\ForeignKeyConstraintViolationException::class, null, 19);
|
2015-10-13 18:08:04 +02:00
|
|
|
|
|
|
|
Assert::same('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)', $e->getSql());
|