Passed
Push — master ( b0ca68...10680f )
by Wilmer
27:02 queued 23:37
created

CommonConnectionTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testTransactionShortcutException() 0 20 1
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