Passed
Pull Request — master (#420)
by Wilmer
02:59
created

testTransactionShortcutException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 20
rs 9.8666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests\Common;
6
7
use Throwable;
8
use Yiisoft\Db\Exception\Exception;
9
use Yiisoft\Db\Exception\InvalidConfigException;
10
use Yiisoft\Db\Tests\AbstractConnectionTest;
11
12
abstract class CommonConnectionTest extends AbstractConnectionTest
13
{
14
    /**
15
     * @throws InvalidConfigException
16
     * @throws Throwable
17
     */
18
    public function testTransactionShortcutException(): void
19
    {
20
        $db = $this->getConnection(true);
21
22
        $this->expectException(Exception::class);
23
24
        $db->transaction(
25
            static function () use ($db) {
26
                $db->createCommand()->insert('profile', ['description' => 'test transaction shortcut'])->execute();
27
28
                throw new Exception('Exception in transaction shortcut');
29
            }
30
        );
31
        $profilesCount = $db->createCommand(
32
            <<<SQL
33
            SELECT COUNT(*) FROM {{profile}} WHERE [[description]] = 'test transaction shortcut'
34
            SQL
35
        )->queryScalar();
36
37
        $this->assertSame(0, $profilesCount, 'profile should not be inserted in transaction shortcut');
38
    }
39
}
40