Passed
Push — main ( 4b03c8...85c7ac )
by Peter
02:31
created

InsertTest::testInsertSelect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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