summaryrefslogtreecommitdiffstats
path: root/tests/Builder/TransactionStatementTest.php
blob: 5cd28c6c5bb9ec3d7a5e8277bffffc0afbd2da85 (plain)
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
<?php
declare(strict_types=1);

namespace PhpMyAdmin\SqlParser\Tests\Builder;

use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Tests\TestCase;

class TransactionStatementTest extends TestCase
{
    public function testBuilder()
    {
        $query = 'START TRANSACTION;' .
            'SELECT @A:=SUM(salary) FROM table1 WHERE type=1;' .
            'UPDATE table2 SET summary=@A WHERE type=1;' .
            'COMMIT;';

        $parser = new Parser($query);
        $stmt = $parser->statements[0];

        $this->assertEquals(
            'START TRANSACTION;' .
            'SELECT @A:=SUM(salary) FROM table1 WHERE type=1;' .
            'UPDATE table2 SET summary = @A WHERE type=1;' .
            'COMMIT',
            $stmt->build()
        );
    }
}