-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathConnectionTest.php
98 lines (79 loc) · 2.77 KB
/
ConnectionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
declare(strict_types=1);
namespace Yiisoft\Db\Mssql\Tests;
use PDO;
use Throwable;
use Yiisoft\Db\Driver\Pdo\PdoConnectionInterface;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Mssql\Column\ColumnFactory;
use Yiisoft\Db\Mssql\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\Common\CommonConnectionTest;
use Yiisoft\Db\Transaction\TransactionInterface;
/**
* @group mssql
*
* @psalm-suppress PropertyNotSetInConstructor
*/
final class ConnectionTest extends CommonConnectionTest
{
use TestTrait;
/**
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
* @throws Throwable
*/
public function testTransactionIsolation(): void
{
$db = $this->getConnection(true);
$transaction = $db->beginTransaction(TransactionInterface::READ_UNCOMMITTED);
$transaction->commit();
$transaction = $db->beginTransaction(TransactionInterface::READ_COMMITTED);
$transaction->commit();
$transaction = $db->beginTransaction(TransactionInterface::REPEATABLE_READ);
$transaction->commit();
$transaction = $db->beginTransaction(TransactionInterface::SERIALIZABLE);
$transaction->commit();
/* should not be any exception so far */
$this->assertTrue(true);
}
/**
* @throws Exception
* @throws InvalidConfigException
* @throws Throwable
*/
public function testTransactionShortcutCustom(): void
{
$db = $this->getConnection();
$result = $db->transaction(
static function (PdoConnectionInterface $db): bool {
$db->createCommand()->insert('profile', ['description' => 'test transaction shortcut'])->execute();
return true;
},
TransactionInterface::READ_UNCOMMITTED,
);
$this->assertTrue($result, 'transaction shortcut valid value should be returned from callback');
$profilesCount = $db->createCommand(
<<<SQL
SELECT COUNT(*) FROM profile WHERE description = 'test transaction shortcut'
SQL,
)->queryScalar();
$this->assertSame('1', $profilesCount, 'profile should be inserted in transaction shortcut');
}
/**
* @throws Exception
* @throws InvalidConfigException
*/
public function testSettingDefaultAttributes(): void
{
$db = $this->getConnection();
$this->assertSame(PDO::ERRMODE_EXCEPTION, $db->getActivePDO()?->getAttribute(PDO::ATTR_ERRMODE));
}
public function testGetColumnFactory(): void
{
$db = $this->getConnection();
$this->assertInstanceOf(ColumnFactory::class, $db->getColumnFactory());
}
}