Total Complexity | 3 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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 |
||
55 | } |
||
56 | } |
||
57 |