InsertTest::getSut()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace QB\MySQL\Statement;
6
7
use QB\Generic\Clause\Column;
8
use QB\Generic\Expr\Expr;
9
use QB\Generic\Statement\InsertTest as GenericInsertTest;
10
11
class InsertTest extends GenericInsertTest
12
{
13
    public function testOnDuplicateKeyUpdate()
14
    {
15
        $sql = (string)$this->getSut('foo')
16
            ->modifier(Insert::HIGH_PRIORITY)
17
            ->values('1234', '2345')
18
            ->setOnDuplicateKeyUpdate(new Expr('bar = bar + 1'));
19
20
        $parts   = [];
21
        $parts[] = 'INSERT HIGH_PRIORITY INTO foo';
22
        $parts[] = 'VALUES (1234, 2345)';
23
        $parts[] = 'ON DUPLICATE KEY UPDATE bar = bar + 1';
24
25
        $expectedSql = implode(PHP_EOL, $parts);
26
27
        $this->assertSame($expectedSql, $sql);
28
    }
29
30
    public function testComplex()
31
    {
32
        $select = new Select();
33
        $select->columns(new Column('1', 'f'));
34
35
        $sql = (string)$this->getSut('foo')
36
            ->modifier(Insert::IGNORE)
37
            ->select($select);
38
39
        $parts   = [];
40
        $parts[] = 'INSERT IGNORE INTO foo';
41
        $parts[] = 'SELECT 1 AS f';
42
43
        $expectedSql = implode(PHP_EOL, $parts);
44
45
        $this->assertSame($expectedSql, $sql);
46
    }
47
48
    /**
49
     * @param string $table
50
     *
51
     * @return Insert
52
     */
53
    protected function getSut(string $table): Insert
54
    {
55
        return (new Insert())->into($table);
56
    }
57
}
58