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

InsertTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 41
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testInsertSimple() 0 11 1
A getSut() 0 3 1
A testComplex() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace QB\Generic\Statement;
6
7
use PHPUnit\Framework\TestCase;
8
9
class InsertTest extends TestCase
10
{
11
    public function testInsertSimple()
12
    {
13
        $sql = (string)$this->getSut('foo')->addValues('1234', '2345');
14
15
        $parts   = [];
16
        $parts[] = 'INSERT INTO foo';
17
        $parts[] = 'VALUES (?, ?)';
18
19
        $expectedSql = implode(PHP_EOL, $parts);
20
21
        $this->assertSame($expectedSql, $sql);
22
    }
23
24
    public function testComplex()
25
    {
26
        $sql = (string)$this->getSut('foo')
27
            ->addModifier('BAR')
28
            ->addColumns('id', 'bar_id', 'baz')
29
            ->addValues('1234', '2345', 'a')
30
            ->addValues('3456', '4567', 'b');
31
32
        $parts   = [];
33
        $parts[] = 'INSERT BAR INTO foo (id, bar_id, baz)';
34
        $parts[] = 'VALUES (?, ?, ?),';
35
        $parts[] = '(?, ?, ?)';
36
37
        $expectedSql = implode(PHP_EOL, $parts);
38
39
        $this->assertSame($expectedSql, $sql);
40
    }
41
42
    /**
43
     * @param string $table
44
     *
45
     * @return IInsert
46
     */
47
    protected function getSut(string $table): IInsert
48
    {
49
        return (new Insert())->setInto($table);
50
    }
51
}
52