diff --git a/tests/Database.Tracy/ConnectionPanel.phpt b/tests/Database.Tracy/ConnectionPanel.phpt
new file mode 100644
index 000000000..4dba1b30c
--- /dev/null
+++ b/tests/Database.Tracy/ConnectionPanel.phpt
@@ -0,0 +1,62 @@
+beginTransaction();
+ $connection->query('SELECT 1');
+ $connection->commit();
+ try {
+ $connection->query('SELECT');
+ } catch (Throwable) {
+ }
+
+ Assert::matchFile(__DIR__ . '/tab.html', $panel->getTab());
+ Assert::matchFile(__DIR__ . '/panel.html', $panel->getPanel());
+});
+
+test('Bluescreen Panel', function () {
+ $connection = new Connection('sqlite::memory:');
+ try {
+ $connection->query('SELECT');
+ } catch (Throwable $e) {
+ }
+
+ Assert::same(
+ [
+ 'tab' => 'SQL',
+ 'panel' => "
SELECT
\n",
+ ],
+ ConnectionPanel::renderException($e),
+ );
+});
+
+test('deprecated initialization', function () {
+ $connection = new Connection('sqlite::memory:');
+ $panel = Nette\Database\Helpers::initializeTracy($connection, addBarPanel: true, name: 'foo');
+
+ $connection->beginTransaction();
+ $connection->query('SELECT 1');
+ $connection->commit();
+ try {
+ $connection->query('SELECT');
+ } catch (Throwable) {
+ }
+
+ Assert::matchFile(__DIR__ . '/tab.html', $panel->getTab());
+ Assert::matchFile(__DIR__ . '/panel.html', $panel->getPanel());
+});
diff --git a/tests/Database.Tracy/panel.html b/tests/Database.Tracy/panel.html
new file mode 100644
index 000000000..1ec032563
--- /dev/null
+++ b/tests/Database.Tracy/panel.html
@@ -0,0 +1,36 @@
+%A%
+Queries: 4, time: %a% ms, foo
+
+
diff --git a/tests/Database.Tracy/tab.html b/tests/Database.Tracy/tab.html
new file mode 100644
index 000000000..1ca7dbd67
--- /dev/null
+++ b/tests/Database.Tracy/tab.html
@@ -0,0 +1,3 @@
+
+
diff --git a/tests/Database/Connection.exceptions.mysql.phpt b/tests/Database/Connection.exceptions.mysql.phpt
index 6908adb3f..1d60d5adc 100644
--- a/tests/Database/Connection.exceptions.mysql.phpt
+++ b/tests/Database/Connection.exceptions.mysql.phpt
@@ -12,24 +12,80 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
$connection = connectToDB()->getConnection();
+Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
-$options = Tester\Environment::loadData();
-$e = Assert::exception(
- fn() => new Nette\Database\Connection($options['dsn'], 'unknown', 'unknown'),
- Nette\Database\ConnectionException::class,
- '%a% Access denied for user %a%',
-);
+test('Exception thrown for invalid database credentials', function () {
+ $options = Tester\Environment::loadData();
+ $e = Assert::exception(
+ fn() => new Nette\Database\Connection($options['dsn'], 'unknown', 'unknown'),
+ Nette\Database\ConnectionException::class,
+ '%a% Access denied for user %a%',
+ );
-Assert::same(1045, $e->getDriverCode());
-Assert::contains($e->getSqlState(), ['HY000', '28000']);
-Assert::same($e->getCode(), $e->getSqlState());
+ Assert::same(1045, $e->getDriverCode());
+ Assert::contains($e->getSqlState(), ['HY000', '28000']);
+ Assert::same($e->getCode(), $e->getSqlState());
+});
-$e = Assert::exception(
- fn() => $connection->rollback(),
- Nette\Database\DriverException::class,
- 'There is no active transaction',
- 0,
-);
+test('Exception thrown when calling rollback with no active transaction', function () use ($connection) {
+ $e = Assert::exception(
+ fn() => $connection->rollback(),
+ Nette\Database\DriverException::class,
+ 'There is no active transaction',
+ 0,
+ );
+ Assert::same(null, $e->getDriverCode());
+});
-Assert::same(null, $e->getDriverCode());
+
+test('Exception thrown for syntax error in SQL query', function () use ($connection) {
+ $e = Assert::exception(
+ fn() => $connection->query('SELECT'),
+ Nette\Database\DriverException::class,
+ '%a% Syntax error %a%',
+ '42000',
+ );
+
+ Assert::same(1064, $e->getDriverCode());
+ Assert::same($e->getCode(), $e->getSqlState());
+});
+
+
+test('Exception thrown for unique constraint violation', function () use ($connection) {
+ $e = Assert::exception(
+ fn() => $connection->query('INSERT INTO author (id, name, web, born) VALUES (11, "", "", NULL)'),
+ Nette\Database\UniqueConstraintViolationException::class,
+ '%a% Integrity constraint violation: %a%',
+ '23000',
+ );
+
+ Assert::same(1062, $e->getDriverCode());
+ Assert::same($e->getCode(), $e->getSqlState());
+});
+
+
+test('Exception thrown for not null constraint violation', function () use ($connection) {
+ $e = Assert::exception(
+ fn() => $connection->query('INSERT INTO author (name, web, born) VALUES (NULL, "", NULL)'),
+ Nette\Database\NotNullConstraintViolationException::class,
+ '%a% Integrity constraint violation: %a%',
+ '23000',
+ );
+
+ Assert::same(1048, $e->getDriverCode());
+ Assert::same($e->getCode(), $e->getSqlState());
+});
+
+
+test('Exception thrown for foreign key constraint violation', function () use ($connection) {
+ $e = Assert::exception(
+ fn() => $connection->query('INSERT INTO book (author_id, translator_id, title) VALUES (999, 12, "")'),
+ Nette\Database\ForeignKeyConstraintViolationException::class,
+ '%a% a foreign key constraint fails %a%',
+ '23000',
+ );
+
+ Assert::same(1452, $e->getDriverCode());
+ Assert::same($e->getCode(), $e->getSqlState());
+});
diff --git a/tests/Database/Connection.exceptions.postgre.phpt b/tests/Database/Connection.exceptions.postgre.phpt
index 82223805a..717245d38 100644
--- a/tests/Database/Connection.exceptions.postgre.phpt
+++ b/tests/Database/Connection.exceptions.postgre.phpt
@@ -12,24 +12,82 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
$connection = connectToDB()->getConnection();
+Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
-$options = Tester\Environment::loadData();
-$e = Assert::exception(
- fn() => new Nette\Database\Connection($options['dsn'], 'unknown', 'unknown'),
- Nette\Database\ConnectionException::class,
- null,
- '08006',
-);
-Assert::same(7, $e->getDriverCode());
-Assert::same($e->getCode(), $e->getSqlState());
+test('Exception thrown for invalid database credentials', function () {
+ $options = Tester\Environment::loadData();
+ $e = Assert::exception(
+ fn() => new Nette\Database\Connection($options['dsn'], 'unknown', 'unknown'),
+ Nette\Database\ConnectionException::class,
+ null,
+ '08006',
+ );
+ Assert::same(7, $e->getDriverCode());
+ Assert::same($e->getCode(), $e->getSqlState());
+});
-$e = Assert::exception(
- fn() => $connection->rollback(),
- Nette\Database\DriverException::class,
- 'There is no active transaction',
- 0,
-);
-Assert::same(null, $e->getDriverCode());
+test('Exception thrown when calling rollback with no active transaction', function () use ($connection) {
+ $e = Assert::exception(
+ fn() => $connection->rollback(),
+ Nette\Database\DriverException::class,
+ 'There is no active transaction',
+ 0,
+ );
+
+ Assert::same(null, $e->getDriverCode());
+});
+
+
+test('Exception thrown for syntax error in SQL query', function () use ($connection) {
+ $e = Assert::exception(
+ fn() => $connection->query('SELECT INTO'),
+ Nette\Database\DriverException::class,
+ '%a% syntax error %A%',
+ '42601',
+ );
+
+ Assert::same(7, $e->getDriverCode());
+ Assert::same($e->getCode(), $e->getSqlState());
+});
+
+
+test('Exception thrown for unique constraint violation', function () use ($connection) {
+ $e = Assert::exception(
+ fn() => $connection->query("INSERT INTO author (id, name, web, born) VALUES (11, '', '', NULL)"),
+ Nette\Database\UniqueConstraintViolationException::class,
+ '%a% Unique violation: %A%',
+ '23505',
+ );
+
+ Assert::same(7, $e->getDriverCode());
+ Assert::same($e->getCode(), $e->getSqlState());
+});
+
+
+test('Exception thrown for not null constraint violation', function () use ($connection) {
+ $e = Assert::exception(
+ fn() => $connection->query("INSERT INTO author (name, web, born) VALUES (NULL, '', NULL)"),
+ Nette\Database\NotNullConstraintViolationException::class,
+ '%a% Not null violation: %A%',
+ '23502',
+ );
+
+ Assert::same(7, $e->getDriverCode());
+ Assert::same($e->getCode(), $e->getSqlState());
+});
+
+
+test('Exception thrown for foreign key constraint violation', function () use ($connection) {
+ $e = Assert::exception(
+ fn() => $connection->query("INSERT INTO book (author_id, translator_id, title) VALUES (999, 12, '')"),
+ Nette\Database\ForeignKeyConstraintViolationException::class,
+ '%a% Foreign key violation: %A%',
+ '23503',
+ );
+
+ Assert::same(7, $e->getDriverCode());
+ Assert::same($e->getCode(), $e->getSqlState());
+});
diff --git a/tests/Database/Connection.exceptions.sqlite.phpt b/tests/Database/Connection.exceptions.sqlite.phpt
index 484434e27..dbd66d5cb 100644
--- a/tests/Database/Connection.exceptions.sqlite.phpt
+++ b/tests/Database/Connection.exceptions.sqlite.phpt
@@ -12,23 +12,79 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
$connection = connectToDB()->getConnection();
+Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
-$e = Assert::exception(
- fn() => new Nette\Database\Connection('sqlite:.'),
- Nette\Database\ConnectionException::class,
- 'SQLSTATE[HY000] [14] unable to open database file',
- 'HY000',
-);
-Assert::same(14, $e->getDriverCode());
-Assert::same($e->getCode(), $e->getSqlState());
+test('Exception thrown for unable to open database file', function () {
+ $e = Assert::exception(
+ fn() => new Nette\Database\Connection('sqlite:.'),
+ Nette\Database\ConnectionException::class,
+ 'SQLSTATE[HY000] [14] unable to open database file',
+ 'HY000',
+ );
+ Assert::same(14, $e->getDriverCode());
+ Assert::same($e->getCode(), $e->getSqlState());
+});
-$e = Assert::exception(
- fn() => $connection->rollback(),
- Nette\Database\DriverException::class,
- 'There is no active transaction',
- 0,
-);
-Assert::same(null, $e->getDriverCode());
+test('Exception thrown when calling rollback with no active transaction', function () use ($connection) {
+ $e = Assert::exception(
+ fn() => $connection->rollback(),
+ Nette\Database\DriverException::class,
+ 'There is no active transaction',
+ 0,
+ );
+
+ Assert::same(null, $e->getDriverCode());
+});
+
+
+test('Exception thrown for error in SQL query', function () use ($connection) {
+ $e = Assert::exception(
+ fn() => $connection->query('SELECT'),
+ Nette\Database\DriverException::class,
+ '%a% error%a%',
+ 'HY000',
+ );
+
+ Assert::same(1, $e->getDriverCode());
+ Assert::same($e->getCode(), $e->getSqlState());
+});
+
+
+test('Exception thrown for unique constraint violation', function () use ($connection) {
+ $e = Assert::exception(
+ fn() => $connection->query('INSERT INTO author (id, name, web, born) VALUES (11, "", "", NULL)'),
+ Nette\Database\UniqueConstraintViolationException::class,
+ '%a% Integrity constraint violation: %a%',
+ '23000',
+ );
+
+ Assert::same(19, $e->getDriverCode());
+ Assert::same($e->getCode(), $e->getSqlState());
+});
+
+
+test('Exception thrown for not null constraint violation', function () use ($connection) {
+ $e = Assert::exception(
+ fn() => $connection->query('INSERT INTO author (name, web, born) VALUES (NULL, "", NULL)'),
+ Nette\Database\NotNullConstraintViolationException::class,
+ '%a% Integrity constraint violation: %a%',
+ '23000',
+ );
+
+ Assert::same(19, $e->getDriverCode());
+ Assert::same($e->getCode(), $e->getSqlState());
+});
+
+
+test('Exception thrown for foreign key constraint violation', function () use ($connection) {
+ $e = Assert::exception(function () use ($connection) {
+ $connection->query('PRAGMA foreign_keys=true');
+ $connection->query('INSERT INTO book (author_id, translator_id, title) VALUES (999, 12, "")');
+ }, Nette\Database\ForeignKeyConstraintViolationException::class, '%a% Integrity constraint violation: %a%', '23000');
+
+ Assert::same(19, $e->getDriverCode());
+ Assert::same($e->getCode(), $e->getSqlState());
+});
diff --git a/tests/Database/Connection.getInsertId().mysql.phpt b/tests/Database/Connection.getInsertId().mysql.phpt
index e65f9b703..020ef596c 100644
--- a/tests/Database/Connection.getInsertId().mysql.phpt
+++ b/tests/Database/Connection.getInsertId().mysql.phpt
@@ -20,10 +20,10 @@ $connection->query('
');
$connection->query('INSERT INTO noprimarykey (col) VALUES (NULL)');
-Assert::equal('0', $connection->getInsertId());
+Assert::same('0', $connection->getInsertId());
$connection->query('INSERT INTO noprimarykey (col) VALUES (3)');
-Assert::equal('0', $connection->getInsertId());
+Assert::same('0', $connection->getInsertId());
$connection->query('
@@ -34,10 +34,10 @@ $connection->query('
');
$connection->query('INSERT INTO primarykey (prim) VALUES (5)');
-Assert::equal('0', $connection->getInsertId());
+Assert::same('0', $connection->getInsertId());
$connection->query('INSERT INTO primarykey (prim) VALUES (6)');
-Assert::equal('0', $connection->getInsertId());
+Assert::same('0', $connection->getInsertId());
$connection->query('
@@ -49,13 +49,13 @@ $connection->query('
');
$connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)');
-Assert::equal('1', $connection->getInsertId());
+Assert::same('1', $connection->getInsertId());
$connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)');
-Assert::equal('2', $connection->getInsertId());
+Assert::same('2', $connection->getInsertId());
$connection->query('INSERT INTO autoprimarykey (prim, col) VALUES (10, NULL)');
-Assert::equal('10', $connection->getInsertId());
+Assert::same('10', $connection->getInsertId());
$connection->query('
@@ -67,10 +67,10 @@ $connection->query('
');
$connection->query('INSERT INTO multiautoprimarykey (prim2) VALUES (3)');
-Assert::equal('1', $connection->getInsertId());
+Assert::same('1', $connection->getInsertId());
$connection->query('INSERT INTO multiautoprimarykey (prim2) VALUES (3)');
-Assert::equal('2', $connection->getInsertId());
+Assert::same('2', $connection->getInsertId());
$connection->query('INSERT INTO multiautoprimarykey (prim1, prim2) VALUES (10, 3)');
-Assert::equal('10', $connection->getInsertId());
+Assert::same('10', $connection->getInsertId());
diff --git a/tests/Database/Connection.getInsertId().postgre.phpt b/tests/Database/Connection.getInsertId().postgre.phpt
index b2824d0a2..2e46fd81e 100644
--- a/tests/Database/Connection.getInsertId().postgre.phpt
+++ b/tests/Database/Connection.getInsertId().postgre.phpt
@@ -27,7 +27,7 @@ if (PHP_VERSION_ID >= 70016) {
Nette\Database\DriverException::class,
);
} else {
- Assert::equal('0', $connection->getInsertId());
+ Assert::same('0', $connection->getInsertId());
}
@@ -40,13 +40,13 @@ $connection->query('
');
$connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)');
-Assert::equal('1', $connection->getInsertId('autoprimarykey_prim_seq'));
+Assert::same('1', $connection->getInsertId('autoprimarykey_prim_seq'));
$connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)');
-Assert::equal('2', $connection->getInsertId('autoprimarykey_prim_seq'));
+Assert::same('2', $connection->getInsertId('autoprimarykey_prim_seq'));
$connection->query('INSERT INTO autoprimarykey (prim, col) VALUES (10, NULL)');
-Assert::equal('2', $connection->getInsertId('autoprimarykey_prim_seq'));
+Assert::same('2', $connection->getInsertId('autoprimarykey_prim_seq'));
$connection->query('
@@ -58,10 +58,10 @@ $connection->query('
');
$connection->query('INSERT INTO multiautoprimarykey (prim2) VALUES (3)');
-Assert::equal('1', $connection->getInsertId('multiautoprimarykey_prim1_seq'));
+Assert::same('1', $connection->getInsertId('multiautoprimarykey_prim1_seq'));
$connection->query('INSERT INTO multiautoprimarykey (prim2) VALUES (3)');
-Assert::equal('2', $connection->getInsertId('multiautoprimarykey_prim1_seq'));
+Assert::same('2', $connection->getInsertId('multiautoprimarykey_prim1_seq'));
$connection->query('INSERT INTO multiautoprimarykey (prim1, prim2) VALUES (10, 3)');
-Assert::equal('2', $connection->getInsertId('multiautoprimarykey_prim1_seq'));
+Assert::same('2', $connection->getInsertId('multiautoprimarykey_prim1_seq'));
diff --git a/tests/Database/Connection.getInsertId().sqlite.phpt b/tests/Database/Connection.getInsertId().sqlite.phpt
index 8b4c09a73..26f57ac46 100644
--- a/tests/Database/Connection.getInsertId().sqlite.phpt
+++ b/tests/Database/Connection.getInsertId().sqlite.phpt
@@ -20,10 +20,10 @@ $connection->query('
');
$connection->query('INSERT INTO noprimarykey (col) VALUES (NULL)');
-Assert::equal('1', $connection->getInsertId());
+Assert::same('1', $connection->getInsertId());
$connection->query('INSERT INTO noprimarykey (col) VALUES (3)');
-Assert::equal('2', $connection->getInsertId());
+Assert::same('2', $connection->getInsertId());
$connection->query('
@@ -33,10 +33,10 @@ $connection->query('
');
$connection->query('INSERT INTO primarykey (prim) VALUES (5)');
-Assert::equal('5', $connection->getInsertId());
+Assert::same('5', $connection->getInsertId());
$connection->query('INSERT INTO primarykey (prim) VALUES (6)');
-Assert::equal('6', $connection->getInsertId());
+Assert::same('6', $connection->getInsertId());
$connection->query('
@@ -47,10 +47,10 @@ $connection->query('
');
$connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)');
-Assert::equal('1', $connection->getInsertId());
+Assert::same('1', $connection->getInsertId());
$connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)');
-Assert::equal('2', $connection->getInsertId());
+Assert::same('2', $connection->getInsertId());
$connection->query('INSERT INTO autoprimarykey (prim, col) VALUES (10, NULL)');
-Assert::equal('10', $connection->getInsertId());
+Assert::same('10', $connection->getInsertId());
diff --git a/tests/Database/Connection.getInsertId().sqlsrv.phpt b/tests/Database/Connection.getInsertId().sqlsrv.phpt
index 28652eb54..e971245c7 100644
--- a/tests/Database/Connection.getInsertId().sqlsrv.phpt
+++ b/tests/Database/Connection.getInsertId().sqlsrv.phpt
@@ -21,10 +21,10 @@ $connection->query('
');
$connection->query('INSERT INTO noprimarykey (col) VALUES (NULL)');
-Assert::equal('', $connection->getInsertId());
+Assert::same('', $connection->getInsertId());
$connection->query('INSERT INTO noprimarykey (col) VALUES (NULL)');
-Assert::equal('', $connection->getInsertId());
+Assert::same('', $connection->getInsertId());
$connection->query("IF OBJECT_ID('primarykey', 'U') IS NOT NULL DROP TABLE primarykey");
@@ -36,10 +36,10 @@ $connection->query('
');
$connection->query('INSERT INTO primarykey (prim) VALUES (5)');
-Assert::equal('', $connection->getInsertId());
+Assert::same('', $connection->getInsertId());
$connection->query('INSERT INTO primarykey (prim) VALUES (6)');
-Assert::equal('', $connection->getInsertId());
+Assert::same('', $connection->getInsertId());
$connection->query("IF OBJECT_ID('autoprimarykey', 'U') IS NOT NULL DROP TABLE autoprimarykey");
@@ -52,13 +52,13 @@ $connection->query('
');
$connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)');
-Assert::equal('1', $connection->getInsertId());
+Assert::same('1', $connection->getInsertId());
$connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)');
-Assert::equal('2', $connection->getInsertId());
+Assert::same('2', $connection->getInsertId());
$connection->query('SET IDENTITY_INSERT autoprimarykey ON; INSERT INTO autoprimarykey (prim, col) VALUES (10, NULL)');
-Assert::equal('10', $connection->getInsertId());
+Assert::same('10', $connection->getInsertId());
$connection->query("IF OBJECT_ID('multiautoprimarykey', 'U') IS NOT NULL DROP TABLE multiautoprimarykey");
@@ -71,10 +71,10 @@ $connection->query('
');
$connection->query('INSERT INTO multiautoprimarykey (prim2) VALUES (3)');
-Assert::equal('1', $connection->getInsertId());
+Assert::same('1', $connection->getInsertId());
$connection->query('INSERT INTO multiautoprimarykey (prim2) VALUES (3)');
-Assert::equal('2', $connection->getInsertId());
+Assert::same('2', $connection->getInsertId());
$connection->query('SET IDENTITY_INSERT multiautoprimarykey ON; INSERT INTO multiautoprimarykey (prim1, prim2) VALUES (10, 3)');
-Assert::equal('10', $connection->getInsertId());
+Assert::same('10', $connection->getInsertId());
diff --git a/tests/Database/Explorer/Explorer.cache.observer2.phpt b/tests/Database/Explorer/Explorer.cache.observer2.phpt
index bca6faa46..5eff0cf66 100644
--- a/tests/Database/Explorer/Explorer.cache.observer2.phpt
+++ b/tests/Database/Explorer/Explorer.cache.observer2.phpt
@@ -51,5 +51,5 @@ for ($i = 0; $i < 2; ++$i) {
}
}
-Assert::equal(reformat('SELECT [id], [name] FROM [author]'), $sql);
+Assert::same(reformat('SELECT [id], [name] FROM [author]'), $sql);
Assert::same(2, $cacheStorage->writes);
diff --git a/tests/Database/Explorer/Explorer.ref().phpt b/tests/Database/Explorer/Explorer.ref().phpt
index 8b4a5a961..a8a017087 100644
--- a/tests/Database/Explorer/Explorer.ref().phpt
+++ b/tests/Database/Explorer/Explorer.ref().phpt
@@ -50,5 +50,5 @@ test('', function () use ($explorer, $connection) {
$translator = $book->ref('author', 'translator_id');
}
- Assert::equal(2, $counter);
+ Assert::same(2, $counter);
});
diff --git a/tests/Database/Explorer/GroupedSelection.insert().phpt b/tests/Database/Explorer/GroupedSelection.insert().phpt
index c7e7dfd9e..60c239637 100644
--- a/tests/Database/Explorer/GroupedSelection.insert().phpt
+++ b/tests/Database/Explorer/GroupedSelection.insert().phpt
@@ -21,8 +21,8 @@ test('', function () use ($explorer) {
$book = $explorer->table('book')->get(1);
$book->related('book_tag')->insert(['tag_id' => 23]);
- Assert::equal(3, $book->related('book_tag')->count());
- Assert::equal(3, $book->related('book_tag')->count('*'));
+ Assert::same(3, $book->related('book_tag')->count());
+ Assert::same(3, $book->related('book_tag')->count('*'));
$book->related('book_tag')->where('tag_id', 23)->delete();
});
@@ -32,5 +32,5 @@ test('test counting already fetched rows', function () use ($explorer) {
$book = $explorer->table('book')->get(1);
iterator_to_array($book->related('book_tag'));
$book->related('book_tag')->insert(['tag_id' => 23]);
- Assert::equal(3, $book->related('book_tag')->count());
+ Assert::same(3, $book->related('book_tag')->count());
});
diff --git a/tests/Database/Explorer/Selection.insert().phpt b/tests/Database/Explorer/Selection.insert().phpt
index 48d625f61..2be743ac5 100644
--- a/tests/Database/Explorer/Selection.insert().phpt
+++ b/tests/Database/Explorer/Selection.insert().phpt
@@ -24,7 +24,7 @@ $book = $explorer->table('author')->insert([
]); // INSERT INTO `author` (`name`, `web`) VALUES (LOWER('Eddard Stark'), 'http://example.com', '2011-11-11 00:00:00')
// id = 14
-Assert::equal('eddard stark', $book->name);
+Assert::same('eddard stark', $book->name);
Assert::equal(new Nette\Database\DateTime('2011-11-11'), $book->born);
@@ -66,7 +66,7 @@ if ($driverName !== 'sqlsrv') {
};
$explorer->table('book')->insert($selection);
- Assert::equal(4, $explorer->table('book')->where('title LIKE', 'Biography%')->count('*'));
+ Assert::same(4, $explorer->table('book')->where('title LIKE', 'Biography%')->count('*'));
}
@@ -82,4 +82,4 @@ $inserted = $explorer->table('note')->insert([
'book_id' => 1,
'note' => 'Good one!',
]);
-Assert::equal(1, $inserted);
+Assert::same(1, $inserted);
diff --git a/tests/Database/Explorer/Selection.insert().primaryKeys.phpt b/tests/Database/Explorer/Selection.insert().primaryKeys.phpt
index ba0cea3d1..885a89e37 100644
--- a/tests/Database/Explorer/Selection.insert().primaryKeys.phpt
+++ b/tests/Database/Explorer/Selection.insert().primaryKeys.phpt
@@ -22,16 +22,16 @@ test('Insert into table with simple primary index (autoincrement)', function ()
]);
Assert::type(Nette\Database\Table\ActiveRow::class, $simplePkAutoincrementResult);
- Assert::equal(1, $simplePkAutoincrementResult->identifier1);
- Assert::equal('Some note here', $simplePkAutoincrementResult->note);
+ Assert::same(1, $simplePkAutoincrementResult->identifier1);
+ Assert::same('Some note here', $simplePkAutoincrementResult->note);
$simplePkAutoincrementResult2 = $explorer->table('simple_pk_autoincrement')->insert([
'note' => 'Some note here 2',
]);
Assert::type(Nette\Database\Table\ActiveRow::class, $simplePkAutoincrementResult2);
- Assert::equal(2, $simplePkAutoincrementResult2->identifier1);
- Assert::equal('Some note here 2', $simplePkAutoincrementResult2->note);
+ Assert::same(2, $simplePkAutoincrementResult2->identifier1);
+ Assert::same('Some note here 2', $simplePkAutoincrementResult2->note);
});
test('Insert into table with simple primary index (no autoincrement)', function () use ($explorer) {
@@ -41,8 +41,8 @@ test('Insert into table with simple primary index (no autoincrement)', function
]);
Assert::type(Nette\Database\Table\ActiveRow::class, $simplePkNoAutoincrementResult);
- Assert::equal(100, $simplePkNoAutoincrementResult->identifier1);
- Assert::equal('Some note here', $simplePkNoAutoincrementResult->note);
+ Assert::same(100, $simplePkNoAutoincrementResult->identifier1);
+ Assert::same('Some note here', $simplePkNoAutoincrementResult->note);
$simplePkNoAutoincrementResult2 = $explorer->table('simple_pk_no_autoincrement')->insert([
'identifier1' => 200,
@@ -50,8 +50,8 @@ test('Insert into table with simple primary index (no autoincrement)', function
]);
Assert::type(Nette\Database\Table\ActiveRow::class, $simplePkNoAutoincrementResult2);
- Assert::equal(200, $simplePkNoAutoincrementResult2->identifier1);
- Assert::equal('Some note here 2', $simplePkNoAutoincrementResult2->note);
+ Assert::same(200, $simplePkNoAutoincrementResult2->identifier1);
+ Assert::same('Some note here 2', $simplePkNoAutoincrementResult2->note);
});
test('Insert into table with multi column primary index (no autoincrement)', function () use ($explorer) {
@@ -62,9 +62,9 @@ test('Insert into table with multi column primary index (no autoincrement)', fun
]);
Assert::type(Nette\Database\Table\ActiveRow::class, $multiPkNoAutoincrementResult);
- Assert::equal(5, $multiPkNoAutoincrementResult->identifier1);
- Assert::equal(10, $multiPkNoAutoincrementResult->identifier2);
- Assert::equal('Some note here', $multiPkNoAutoincrementResult->note);
+ Assert::same(5, $multiPkNoAutoincrementResult->identifier1);
+ Assert::same(10, $multiPkNoAutoincrementResult->identifier2);
+ Assert::same('Some note here', $multiPkNoAutoincrementResult->note);
$multiPkNoAutoincrementResult2 = $explorer->table('multi_pk_no_autoincrement')->insert([
'identifier1' => 5,
@@ -73,9 +73,9 @@ test('Insert into table with multi column primary index (no autoincrement)', fun
]);
Assert::type(Nette\Database\Table\ActiveRow::class, $multiPkNoAutoincrementResult2);
- Assert::equal(5, $multiPkNoAutoincrementResult2->identifier1);
- Assert::equal(100, $multiPkNoAutoincrementResult2->identifier2);
- Assert::equal('Some note here 2', $multiPkNoAutoincrementResult2->note);
+ Assert::same(5, $multiPkNoAutoincrementResult2->identifier1);
+ Assert::same(100, $multiPkNoAutoincrementResult2->identifier2);
+ Assert::same('Some note here 2', $multiPkNoAutoincrementResult2->note);
});
test('Insert into table with multi column primary index (autoincrement)', function () use ($driverName, $explorer) {
@@ -86,9 +86,9 @@ test('Insert into table with multi column primary index (autoincrement)', functi
]);
Assert::type(Nette\Database\Table\ActiveRow::class, $multiPkAutoincrementResult);
- Assert::equal(1, $multiPkAutoincrementResult->identifier1);
- Assert::equal(999, $multiPkAutoincrementResult->identifier2);
- Assert::equal('Some note here', $multiPkAutoincrementResult->note);
+ Assert::same(1, $multiPkAutoincrementResult->identifier1);
+ Assert::same(999, $multiPkAutoincrementResult->identifier2);
+ Assert::same('Some note here', $multiPkAutoincrementResult->note);
$multiPkAutoincrementResult2 = $explorer->table('multi_pk_autoincrement')->insert([
'identifier2' => 999,
@@ -96,9 +96,9 @@ test('Insert into table with multi column primary index (autoincrement)', functi
]);
Assert::type(Nette\Database\Table\ActiveRow::class, $multiPkAutoincrementResult2);
- Assert::equal(2, $multiPkAutoincrementResult2->identifier1);
- Assert::equal(999, $multiPkAutoincrementResult2->identifier2);
- Assert::equal('Some note here 2', $multiPkAutoincrementResult2->note);
+ Assert::same(2, $multiPkAutoincrementResult2->identifier1);
+ Assert::same(999, $multiPkAutoincrementResult2->identifier2);
+ Assert::same('Some note here 2', $multiPkAutoincrementResult2->note);
}
});
@@ -106,5 +106,5 @@ test('Insert into table without primary key', function () use ($explorer) {
$noPkResult1 = $explorer->table('no_pk')->insert([
'note' => 'Some note here',
]);
- Assert::equal(1, $noPkResult1);
+ Assert::same(1, $noPkResult1);
});
diff --git a/tests/Database/Explorer/Selection.page().phpt b/tests/Database/Explorer/Selection.page().phpt
index 896d45073..ea05cad0a 100644
--- a/tests/Database/Explorer/Selection.page().phpt
+++ b/tests/Database/Explorer/Selection.page().phpt
@@ -26,39 +26,39 @@ test('first page, one item per page', function () use ($explorer) {
$numberOfPages = 0;
$tags = $explorer->table('tag')->page(1, 1, $numOfPages);
- Assert::equal(1, count($tags)); //one item on first page
- Assert::equal(4, $numOfPages); //four pages total
+ Assert::same(1, count($tags)); //one item on first page
+ Assert::same(4, $numOfPages); //four pages total
//calling the same without the $numOfPages reference
unset($tags);
$tags = $explorer->table('tag')->page(1, 1);
- Assert::equal(1, count($tags)); //one item on first page
+ Assert::same(1, count($tags)); //one item on first page
});
test('second page, three items per page', function () use ($explorer) {
$numberOfPages = 0;
$tags = $explorer->table('tag')->page(2, 3, $numOfPages);
- Assert::equal(1, count($tags)); //one item on second page
- Assert::equal(2, $numOfPages); //two pages total
+ Assert::same(1, count($tags)); //one item on second page
+ Assert::same(2, $numOfPages); //two pages total
//calling the same without the $numOfPages reference
unset($tags);
$tags = $explorer->table('tag')->page(2, 3);
- Assert::equal(1, count($tags)); //one item on second page
+ Assert::same(1, count($tags)); //one item on second page
});
test('page with no items', function () use ($explorer) {
$tags = $explorer->table('tag')->page(10, 4);
- Assert::equal(0, count($tags)); //one item on second page
+ Assert::same(0, count($tags)); //one item on second page
});
test('page with no items (page not in range)', function () use ($explorer) {
$tags = $explorer->table('tag')->page(100, 4);
- Assert::equal(0, count($tags)); //one item on second page
+ Assert::same(0, count($tags)); //one item on second page
});
test('less items than $itemsPerPage', function () use ($explorer) {
$tags = $explorer->table('tag')->page(1, 100);
- Assert::equal(4, count($tags)); //all four items from db
+ Assert::same(4, count($tags)); //all four items from db
});
diff --git a/tests/Database/Explorer/SqlBuilder.addWhere().phpt b/tests/Database/Explorer/SqlBuilder.addWhere().phpt
index 6dd477207..4d770e77c 100644
--- a/tests/Database/Explorer/SqlBuilder.addWhere().phpt
+++ b/tests/Database/Explorer/SqlBuilder.addWhere().phpt
@@ -41,7 +41,7 @@ test('?name', function () use ($explorer) {
test('test Selection as a parameter', function () use ($explorer) {
$sqlBuilder = new SqlBuilder('book', $explorer);
$sqlBuilder->addWhere('id', $explorer->table('book'));
- Assert::equal(reformat([
+ Assert::same(reformat([
'mysql' => 'SELECT * FROM `book` WHERE (`id` IN (?))',
'SELECT * FROM [book] WHERE ([id] IN (SELECT [id] FROM [book]))',
]), $sqlBuilder->buildSelectQuery());
@@ -52,7 +52,7 @@ test('test more Selection as a parameter', function () use ($explorer) {
$sqlBuilder = new SqlBuilder('book', $explorer);
$sqlBuilder->addWhere('id', $explorer->table('book'));
$sqlBuilder->addWhere('id', $explorer->table('book_tag')->select('book_id'));
- Assert::equal(reformat([
+ Assert::same(reformat([
'mysql' => 'SELECT * FROM `book` WHERE (`id` IN (?)) AND (`id` IN (?))',
'SELECT * FROM [book] WHERE ([id] IN (SELECT [id] FROM [book])) AND ([id] IN (SELECT [book_id] FROM [book_tag]))',
]), $sqlBuilder->buildSelectQuery());
@@ -62,7 +62,7 @@ test('test more Selection as a parameter', function () use ($explorer) {
test('test more Selection as one of more argument', function () use ($explorer) {
$sqlBuilder = new SqlBuilder('book', $explorer);
$sqlBuilder->addWhere('id ? AND id ?', $explorer->table('book')->where('id', 2), $explorer->table('book_tag')->select('book_id'));
- Assert::equal(reformat([
+ Assert::same(reformat([
'mysql' => 'SELECT * FROM `book` WHERE (`id` IN (?) AND `id` IN (?))',
'SELECT * FROM [book] WHERE ([id] IN (SELECT [id] FROM [book] WHERE ([id] = ?)) AND [id] IN (SELECT [book_id] FROM [book_tag]))',
]), $sqlBuilder->buildSelectQuery());
@@ -74,7 +74,7 @@ test('test more ActiveRow as a parameter', function () use ($explorer) {
$books = $explorer->table('book')->where('id', [1, 2])->fetchPairs('id');
$sqlBuilder->addWhere('id ?', $books[1]);
$sqlBuilder->addWhere('id ?', $books[2]);
- Assert::equal(reformat([
+ Assert::same(reformat([
'SELECT * FROM [book] WHERE ([id] = ?) AND ([id] = ?)',
]), $sqlBuilder->buildSelectQuery());
});
@@ -84,7 +84,7 @@ test('test Selection with parameters as a parameter', function () use ($explorer
$sqlBuilder = new SqlBuilder('book', $explorer);
$sqlBuilder->addWhere('id', $explorer->table('book')->having('COUNT(:book_tag.tag_id) >', 1));
$schemaSupported = $explorer->getConnection()->getDriver()->isSupported(Driver::SupportSchema);
- Assert::equal(reformat([
+ Assert::same(reformat([
'mysql' => 'SELECT * FROM `book` WHERE (`id` IN (?))',
'SELECT * FROM [book] WHERE ([id] IN (SELECT [id] FROM [book] LEFT JOIN ' . ($schemaSupported ? '[public].[book_tag] ' : '') . '[book_tag] ON [book].[id] = [book_tag].[book_id] HAVING COUNT([book_tag].[tag_id]) > ?))',
]), $sqlBuilder->buildSelectQuery());
@@ -95,7 +95,7 @@ test('test Selection with parameters as a parameter', function () use ($explorer
test('test Selection with column as a parameter', function () use ($explorer) {
$sqlBuilder = new SqlBuilder('book', $explorer);
$sqlBuilder->addWhere('id', $explorer->table('book')->select('id'));
- Assert::equal(reformat([
+ Assert::same(reformat([
'mysql' => 'SELECT * FROM `book` WHERE (`id` IN (?))',
'SELECT * FROM [book] WHERE ([id] IN (SELECT [id] FROM [book]))',
]), $sqlBuilder->buildSelectQuery());
@@ -105,7 +105,7 @@ test('test Selection with column as a parameter', function () use ($explorer) {
test('test multiple placeholder parameter', function () use ($explorer) {
$sqlBuilder = new SqlBuilder('book', $explorer);
$sqlBuilder->addWhere('id ? OR id ?', null, $explorer->table('book'));
- Assert::equal(reformat([
+ Assert::same(reformat([
'mysql' => 'SELECT * FROM `book` WHERE (`id` IS NULL OR `id` IN (?))',
'SELECT * FROM [book] WHERE ([id] IS NULL OR [id] IN (SELECT [id] FROM [book]))',
]), $sqlBuilder->buildSelectQuery());
@@ -182,7 +182,7 @@ test('tests NOT', function () use ($explorer) {
$sqlBuilder->addWhere('id NOT', [1, 2]);
$sqlBuilder->addWhere('id NOT', null);
$sqlBuilder->addWhere('id NOT', $explorer->table('book')->select('id'));
- Assert::equal(reformat([
+ Assert::same(reformat([
'mysql' => 'SELECT * FROM `book` WHERE (`id` NOT IN (?)) AND (`id` IS NOT NULL) AND (`id` NOT IN (?))',
'SELECT * FROM [book] WHERE ([id] NOT IN (?)) AND ([id] IS NOT NULL) AND ([id] NOT IN (SELECT [id] FROM [book]))',
]), $sqlBuilder->buildSelectQuery());
@@ -192,7 +192,7 @@ test('tests NOT', function () use ($explorer) {
test('tests multi column IN clause', function () use ($explorer) {
$sqlBuilder = new SqlBuilder('book_tag', $explorer);
$sqlBuilder->addWhere(['book_id', 'tag_id'], [[1, 11], [2, 12]]);
- Assert::equal(reformat([
+ Assert::same(reformat([
'sqlite' => 'SELECT * FROM [book_tag] WHERE (([book_id] = ? AND [tag_id] = ?) OR ([book_id] = ? AND [tag_id] = ?))',
'mysql' => 'SELECT * FROM `book_tag` WHERE ((`book_id` = ? AND `tag_id` = ?) OR (`book_id` = ? AND `tag_id` = ?))',
'SELECT * FROM [book_tag] WHERE (([book_id], [tag_id]) IN (?))',
diff --git a/tests/Database/Explorer/bugs/bug10.postgre.phpt b/tests/Database/Explorer/bugs/bug10.postgre.phpt
index 86f43d242..a902488db 100644
--- a/tests/Database/Explorer/bugs/bug10.postgre.phpt
+++ b/tests/Database/Explorer/bugs/bug10.postgre.phpt
@@ -26,4 +26,4 @@ $result = $explorer->table('Bug10')->insert([
'D1' => 123,
]);
-Tester\Assert::notEqual(null, $result);
+Tester\Assert::notSame(null, $result);
diff --git a/tests/Database/Explorer/bugs/bug216.phpt b/tests/Database/Explorer/bugs/bug216.phpt
index 287a65ef2..23db5de1e 100644
--- a/tests/Database/Explorer/bugs/bug216.phpt
+++ b/tests/Database/Explorer/bugs/bug216.phpt
@@ -24,5 +24,5 @@ $book = $explorer->table('author')->insert([
// id = 14
Assert::type(Nette\Database\Table\ActiveRow::class, $book);
-Assert::equal('eddard stark', $book->name);
+Assert::same('eddard stark', $book->name);
Assert::equal(new Nette\Database\DateTime('2011-11-11'), $book->born);
diff --git a/tests/Database/Helpers.parseColumnType.phpt b/tests/Database/Helpers.parseColumnType.phpt
index 19eba2292..fe665d92e 100644
--- a/tests/Database/Helpers.parseColumnType.phpt
+++ b/tests/Database/Helpers.parseColumnType.phpt
@@ -15,16 +15,16 @@ require __DIR__ . '/../bootstrap.php';
// Test basic type
$result = Helpers::parseColumnType('UNSIGNED INT');
-Assert::equal(['type' => 'UNSIGNED INT', 'length' => null, 'scale' => null, 'parameters' => null], $result);
+Assert::same(['type' => 'UNSIGNED INT', 'length' => null, 'scale' => null, 'parameters' => null], $result);
// Test type with length
$result = Helpers::parseColumnType('VARCHAR(255)');
-Assert::equal(['type' => 'VARCHAR', 'length' => 255, 'scale' => null, 'parameters' => null], $result);
+Assert::same(['type' => 'VARCHAR', 'length' => 255, 'scale' => null, 'parameters' => null], $result);
// Test type with precision and scale
$result = Helpers::parseColumnType('DECIMAL(10,2)');
-Assert::equal(['type' => 'DECIMAL', 'length' => 10, 'scale' => 2, 'parameters' => null], $result);
+Assert::same(['type' => 'DECIMAL', 'length' => 10, 'scale' => 2, 'parameters' => null], $result);
// Test type with additional parameters
$result = Helpers::parseColumnType("ENUM('value1','value2')");
-Assert::equal(['type' => 'ENUM', 'length' => null, 'scale' => null, 'parameters' => "'value1','value2'"], $result);
+Assert::same(['type' => 'ENUM', 'length' => null, 'scale' => null, 'parameters' => "'value1','value2'"], $result);
diff --git a/tests/Database/ResultSet.exceptions.mysql.phpt b/tests/Database/ResultSet.exceptions.mysql.phpt
deleted file mode 100644
index d7ad9c0dd..000000000
--- a/tests/Database/ResultSet.exceptions.mysql.phpt
+++ /dev/null
@@ -1,59 +0,0 @@
-getConnection();
-Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
-
-
-$e = Assert::exception(
- fn() => $connection->query('SELECT'),
- Nette\Database\DriverException::class,
- '%a% Syntax error %a%',
- '42000',
-);
-
-Assert::same(1064, $e->getDriverCode());
-Assert::same($e->getCode(), $e->getSqlState());
-
-
-$e = Assert::exception(
- fn() => $connection->query('INSERT INTO author (id, name, web, born) VALUES (11, "", "", NULL)'),
- Nette\Database\UniqueConstraintViolationException::class,
- '%a% Integrity constraint violation: %a%',
- '23000',
-);
-
-Assert::same(1062, $e->getDriverCode());
-Assert::same($e->getCode(), $e->getSqlState());
-
-
-$e = Assert::exception(
- fn() => $connection->query('INSERT INTO author (name, web, born) VALUES (NULL, "", NULL)'),
- Nette\Database\NotNullConstraintViolationException::class,
- '%a% Integrity constraint violation: %a%',
- '23000',
-);
-
-Assert::same(1048, $e->getDriverCode());
-Assert::same($e->getCode(), $e->getSqlState());
-
-
-$e = Assert::exception(
- fn() => $connection->query('INSERT INTO book (author_id, translator_id, title) VALUES (999, 12, "")'),
- Nette\Database\ForeignKeyConstraintViolationException::class,
- '%a% a foreign key constraint fails %a%',
- '23000',
-);
-
-Assert::same(1452, $e->getDriverCode());
-Assert::same($e->getCode(), $e->getSqlState());
diff --git a/tests/Database/ResultSet.exceptions.postgre.phpt b/tests/Database/ResultSet.exceptions.postgre.phpt
deleted file mode 100644
index 14583df8d..000000000
--- a/tests/Database/ResultSet.exceptions.postgre.phpt
+++ /dev/null
@@ -1,59 +0,0 @@
-getConnection();
-Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
-
-
-$e = Assert::exception(
- fn() => $connection->query('SELECT INTO'),
- Nette\Database\DriverException::class,
- '%a% syntax error %A%',
- '42601',
-);
-
-Assert::same(7, $e->getDriverCode());
-Assert::same($e->getCode(), $e->getSqlState());
-
-
-$e = Assert::exception(
- fn() => $connection->query("INSERT INTO author (id, name, web, born) VALUES (11, '', '', NULL)"),
- Nette\Database\UniqueConstraintViolationException::class,
- '%a% Unique violation: %A%',
- '23505',
-);
-
-Assert::same(7, $e->getDriverCode());
-Assert::same($e->getCode(), $e->getSqlState());
-
-
-$e = Assert::exception(
- fn() => $connection->query("INSERT INTO author (name, web, born) VALUES (NULL, '', NULL)"),
- Nette\Database\NotNullConstraintViolationException::class,
- '%a% Not null violation: %A%',
- '23502',
-);
-
-Assert::same(7, $e->getDriverCode());
-Assert::same($e->getCode(), $e->getSqlState());
-
-
-$e = Assert::exception(
- fn() => $connection->query("INSERT INTO book (author_id, translator_id, title) VALUES (999, 12, '')"),
- Nette\Database\ForeignKeyConstraintViolationException::class,
- '%a% Foreign key violation: %A%',
- '23503',
-);
-
-Assert::same(7, $e->getDriverCode());
-Assert::same($e->getCode(), $e->getSqlState());
diff --git a/tests/Database/ResultSet.exceptions.sqlite.phpt b/tests/Database/ResultSet.exceptions.sqlite.phpt
deleted file mode 100644
index 8bd5dcf7c..000000000
--- a/tests/Database/ResultSet.exceptions.sqlite.phpt
+++ /dev/null
@@ -1,57 +0,0 @@
-getConnection();
-Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
-
-
-$e = Assert::exception(
- fn() => $connection->query('SELECT'),
- Nette\Database\DriverException::class,
- '%a% error%a%',
- 'HY000',
-);
-
-Assert::same(1, $e->getDriverCode());
-Assert::same($e->getCode(), $e->getSqlState());
-
-
-$e = Assert::exception(
- fn() => $connection->query('INSERT INTO author (id, name, web, born) VALUES (11, "", "", NULL)'),
- Nette\Database\UniqueConstraintViolationException::class,
- '%a% Integrity constraint violation: %a%',
- '23000',
-);
-
-Assert::same(19, $e->getDriverCode());
-Assert::same($e->getCode(), $e->getSqlState());
-
-
-$e = Assert::exception(
- fn() => $connection->query('INSERT INTO author (name, web, born) VALUES (NULL, "", NULL)'),
- Nette\Database\NotNullConstraintViolationException::class,
- '%a% Integrity constraint violation: %a%',
- '23000',
-);
-
-Assert::same(19, $e->getDriverCode());
-Assert::same($e->getCode(), $e->getSqlState());
-
-
-$e = Assert::exception(function () use ($connection) {
- $connection->query('PRAGMA foreign_keys=true');
- $connection->query('INSERT INTO book (author_id, translator_id, title) VALUES (999, 12, "")');
-}, Nette\Database\ForeignKeyConstraintViolationException::class, '%a% Integrity constraint violation: %a%', '23000');
-
-Assert::same(19, $e->getDriverCode());
-Assert::same($e->getCode(), $e->getSqlState());
diff --git a/tests/Database/ResultSet.fetchAssoc().phpt b/tests/Database/ResultSet.fetchAssoc().phpt
index 2257e00da..01bd04391 100644
--- a/tests/Database/ResultSet.fetchAssoc().phpt
+++ b/tests/Database/ResultSet.fetchAssoc().phpt
@@ -28,7 +28,7 @@ test('', function () use ($connection) {
test('', function () use ($connection) {
$pairs = $connection->query('SELECT id FROM book ORDER BY id')->fetchAssoc('id');
- Assert::equal([
+ Assert::same([
1 => ['id' => 1],
2 => ['id' => 2],
3 => ['id' => 3],
@@ -38,7 +38,7 @@ test('', function () use ($connection) {
test('', function () use ($connection) {
$pairs = $connection->query('SELECT id FROM book ORDER BY id')->fetchAssoc('id[]=id');
- Assert::equal([
+ Assert::same([
1 => [1],
2 => [2],
3 => [3],
diff --git a/tests/Database/ResultSet.fetchPairs().phpt b/tests/Database/ResultSet.fetchPairs().phpt
index 63b5079c6..a0fc0ca8f 100644
--- a/tests/Database/ResultSet.fetchPairs().phpt
+++ b/tests/Database/ResultSet.fetchPairs().phpt
@@ -87,7 +87,7 @@ Assert::equal([
$pairs = $connection->query('SELECT id FROM book ORDER BY id')->fetchPairs(null, 'id');
-Assert::equal([
+Assert::same([
0 => 1,
1 => 2,
2 => 3,
@@ -96,7 +96,7 @@ Assert::equal([
$pairs = $connection->query('SELECT id FROM book ORDER BY id')->fetchPairs();
-Assert::equal([
+Assert::same([
0 => 1,
1 => 2,
2 => 3,
@@ -105,7 +105,7 @@ Assert::equal([
$pairs = $connection->query('SELECT id, id + 1 AS id1 FROM book ORDER BY id')->fetchPairs();
-Assert::equal([
+Assert::same([
1 => 2,
2 => 3,
3 => 4,
@@ -114,7 +114,7 @@ Assert::equal([
$pairs = $connection->query('SELECT id, id + 1 AS id1, title FROM book ORDER BY id')->fetchPairs();
-Assert::equal([
+Assert::same([
1 => 2,
2 => 3,
3 => 4,
@@ -132,7 +132,7 @@ Assert::same([
$pairs = $connection->query('SELECT 1.5 AS k, 1 AS v')->fetchPairs();
-Assert::equal([
+Assert::same([
'1.5' => 1,
], $pairs);
diff --git a/tests/Database/ResultSet.normalizeRow.mysql.phpt b/tests/Database/ResultSet.normalizeRow.mysql.phpt
index 799d72451..f78e86154 100644
--- a/tests/Database/ResultSet.normalizeRow.mysql.phpt
+++ b/tests/Database/ResultSet.normalizeRow.mysql.phpt
@@ -122,24 +122,21 @@ Assert::same([
$res = $connection->query('SELECT `int` AS a, `char` AS a FROM types');
-
Assert::same([
'a' => 'a',
], (array) @$res->fetch());
$res = $connection->query('SELECT sec_to_time(avg(time_to_sec(`time`))) AS `avg_time` FROM `avgs`');
-
$avgTime = new DateInterval('PT10H10M10S');
$avgTime->f = 0.5;
-
Assert::equal([
'avg_time' => $avgTime,
], (array) $res->fetch());
$res = $connection->query('SELECT SUM(`int`) AS int_sum, AVG(`int`) AS int_avg, SUM(`double`) AS float_sum, AVG(`double`) AS float_avg FROM types WHERE `int` = 1 GROUP BY `int`');
-Assert::equal([
+Assert::same([
'int_sum' => 1,
'int_avg' => 1.0,
'float_sum' => 1.1,
@@ -147,9 +144,16 @@ Assert::equal([
], (array) $res->fetch());
+$res = $connection->fetch('SELECT ? AS c1, ? AS c2, ? AS c3, ? as c4', fopen(__FILE__, 'r'), true, null, 123);
+Assert::same(
+ ['c1' => file_get_contents(__FILE__), 'c2' => 1, 'c3' => null, 'c4' => 123],
+ (array) $res,
+);
+
+
$connection->getPdo()->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$res = $connection->query('SELECT `int`, `decimal`, `decimal2`, `float`, `double` FROM types');
-Assert::equal([
+Assert::same([
'int' => 1,
'decimal' => 1,
'decimal2' => 1.1,
diff --git a/tests/Database/ResultSet.normalizeRow.postgre.phpt b/tests/Database/ResultSet.normalizeRow.postgre.phpt
index 77d887022..fd24a2315 100644
--- a/tests/Database/ResultSet.normalizeRow.postgre.phpt
+++ b/tests/Database/ResultSet.normalizeRow.postgre.phpt
@@ -128,16 +128,22 @@ Assert::same([
$res = $connection->query('SELECT "integer" AS a, "text" AS a FROM types');
-
Assert::same([
'a' => 'a',
], (array) @$res->fetch());
$res = $connection->query('SELECT SUM("integer") AS int_sum, AVG("integer") AS int_avg, SUM("double") AS float_sum, AVG("double") AS float_avg FROM types WHERE "integer" = 1 GROUP BY "integer"');
-Assert::equal([
+Assert::same([
'int_sum' => 1,
'int_avg' => 1.0,
'float_sum' => 1.11,
'float_avg' => 1.11,
], (array) $res->fetch());
+
+
+$res = $connection->fetch('SELECT ?::bool AS c1, ? AS c2, ?::int AS c3', true, null, 123);
+Assert::same(
+ ['c1' => true, 'c2' => null, 'c3' => 123],
+ (array) $res,
+);
diff --git a/tests/Database/ResultSet.normalizeRow.sqlite.phpt b/tests/Database/ResultSet.normalizeRow.sqlite.phpt
index 450fe892e..347cf977b 100644
--- a/tests/Database/ResultSet.normalizeRow.sqlite.phpt
+++ b/tests/Database/ResultSet.normalizeRow.sqlite.phpt
@@ -117,7 +117,7 @@ Assert::same([
$res = $connection->query('SELECT SUM([int]) AS int_sum, AVG([int]) AS int_avg, SUM([double]) AS float_sum, AVG([double]) AS float_avg FROM types WHERE [int] = 1 GROUP BY [int]');
-Assert::equal([
+Assert::same([
'int_sum' => 1,
'int_avg' => 1.0,
'float_sum' => 1.1,
diff --git a/tests/Database/ResultSet.parameters.mysql.phpt b/tests/Database/ResultSet.parameters.mysql.phpt
deleted file mode 100644
index 86b3799d5..000000000
--- a/tests/Database/ResultSet.parameters.mysql.phpt
+++ /dev/null
@@ -1,20 +0,0 @@
-getConnection();
-$res = $connection->fetch('SELECT ? AS c1, ? AS c2, ? AS c3, ? as c4', fopen(__FILE__, 'r'), true, null, 123);
-
-Assert::same(
- ['c1' => file_get_contents(__FILE__), 'c2' => 1, 'c3' => null, 'c4' => 123],
- (array) $res,
-);
diff --git a/tests/Database/ResultSet.parameters.postgre.phpt b/tests/Database/ResultSet.parameters.postgre.phpt
deleted file mode 100644
index 1a1d09ad0..000000000
--- a/tests/Database/ResultSet.parameters.postgre.phpt
+++ /dev/null
@@ -1,20 +0,0 @@
-getConnection();
-$res = $connection->fetch('SELECT ?::bool AS c1, ? AS c2, ?::int AS c3', true, null, 123);
-
-Assert::same(
- ['c1' => true, 'c2' => null, 'c3' => 123],
- (array) $res,
-);
diff --git a/tests/Database/Connection.lazy.phpt b/tests/Database/connection.option.lazy.phpt
similarity index 100%
rename from tests/Database/Connection.lazy.phpt
rename to tests/Database/connection.option.lazy.phpt
diff --git a/tests/Database/connection.options.mysql.phpt b/tests/Database/connection.options.mysql.phpt
new file mode 100644
index 000000000..f95c202c7
--- /dev/null
+++ b/tests/Database/connection.options.mysql.phpt
@@ -0,0 +1,74 @@
+ null])->getConnection();
+ $row = $connection->fetch("SHOW VARIABLES LIKE 'character_set_client'");
+ Assert::same('utf8mb4', $row->Value);
+});
+
+test('custom charset', function () {
+ $connection = connectToDB(['charset' => 'latin2'])->getConnection();
+ $row = $connection->fetch("SHOW VARIABLES LIKE 'character_set_client'");
+ Assert::same('latin2', $row->Value);
+});
+
+
+test('custom sqlmode', function () {
+ $desiredMode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION';
+ $connection = connectToDB(['sqlmode' => $desiredMode])->getConnection();
+ $field = $connection->fetchField('SELECT @@sql_mode');
+ Assert::same($desiredMode, $field);
+});
+
+
+test('default convertBoolean', function () {
+ $connection = connectToDB(['convertBoolean' => null])->getConnection();
+ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-nette_test3.sql');
+ $row = $connection->fetch('SELECT * FROM types');
+ Assert::same(1, $row->bool);
+});
+
+test('convertBoolean = true', function () {
+ $connection = connectToDB(['convertBoolean' => true])->getConnection();
+ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-nette_test3.sql');
+ $row = $connection->fetch('SELECT * FROM types');
+ Assert::same(true, $row->bool);
+});
+
+test('convertBoolean = false', function () {
+ $connection = connectToDB(['convertBoolean' => false])->getConnection();
+ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/files/mysql-nette_test3.sql');
+ $row = $connection->fetch('SELECT * FROM types');
+ Assert::same(1, $row->bool);
+});
+
+
+test('default newDateTime', function () {
+ $connection = connectToDB(['newDateTime' => null])->getConnection();
+ $field = $connection->fetchField('SELECT NOW()');
+ Assert::type(Nette\Utils\DateTime::class, $field);
+});
+
+test('newDateTime = false', function () {
+ $connection = connectToDB(['newDateTime' => false])->getConnection();
+ $field = $connection->fetchField('SELECT NOW()');
+ Assert::type(Nette\Utils\DateTime::class, $field);
+});
+
+test('newDateTime = true', function () {
+ $connection = connectToDB(['newDateTime' => true])->getConnection();
+ $field = $connection->fetchField('SELECT NOW()');
+ Assert::type(Nette\Database\DateTime::class, $field);
+});
diff --git a/tests/Database/connection.options.sqlite.phpt b/tests/Database/connection.options.sqlite.phpt
new file mode 100644
index 000000000..63b8536d4
--- /dev/null
+++ b/tests/Database/connection.options.sqlite.phpt
@@ -0,0 +1,25 @@
+ 'U'])->getConnection();
+ $driver = $connection->getDriver();
+ Assert::same('254358000', $driver->formatDateTime(new DateTime('1978-01-23 00:00:00')));
+});
+
+test('formatDateTime', function () {
+ $connection = connectToDB(['formatDateTime' => 'Y-m-d'])->getConnection();
+ $driver = $connection->getDriver();
+ Assert::same('1978-01-23', $driver->formatDateTime(new DateTime('1978-01-23 00:00:00')));
+});
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index be7d70629..f112e33ce 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -25,9 +25,10 @@ function getTempDir(): string
}
-function connectToDB(): Nette\Database\Explorer
+function connectToDB(array $options = []): Nette\Database\Explorer
{
$args = Tester\Environment::loadData() + ['username' => null, 'password' => null, 'options' => []];
+ $args['options'] = $options + $args['options'];
if ($args['dsn'] !== 'sqlite::memory:') {
Tester\Environment::lock($args['dsn'], getTempDir());