1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-24 10:53:17 +01:00
php-dibi/tests/dibi/Connection.transactions.phpt

51 lines
1.1 KiB
Plaintext
Raw Normal View History

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-01-12 05:33:41 +01:00
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
$conn = new Dibi\Connection($config);
2015-01-12 05:33:41 +01:00
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
2015-06-19 03:11:36 +02:00
/*Assert::exception(function () use ($conn) {
2015-01-12 05:33:41 +01:00
$conn->rollback();
}, Dibi\Exception::class);
2015-01-12 05:33:41 +01:00
2015-06-19 03:11:36 +02:00
Assert::exception(function () use ($conn) {
2015-01-12 05:33:41 +01:00
$conn->commit();
}, Dibi\Exception::class);
2015-01-12 05:33:41 +01:00
$conn->begin();
2015-06-19 03:11:36 +02:00
Assert::exception(function () use ($conn) {
2015-01-12 05:33:41 +01:00
$conn->begin();
}, Dibi\Exception::class);
2015-01-12 05:33:41 +01:00
*/
$conn->begin();
Assert::same(3, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
2015-10-06 01:39:01 +02:00
$conn->query('INSERT INTO [products]', [
2015-01-12 05:33:41 +01:00
'title' => 'Test product',
2015-10-06 01:39:01 +02:00
]);
2015-01-12 05:33:41 +01:00
Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
$conn->rollback();
Assert::same(3, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
$conn->begin();
2015-10-06 01:39:01 +02:00
$conn->query('INSERT INTO [products]', [
2015-01-12 05:33:41 +01:00
'title' => 'Test product',
2015-10-06 01:39:01 +02:00
]);
2015-01-12 05:33:41 +01:00
$conn->commit();
Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());