Passed
Push — main ( 225a1c...d5eb66 )
by Peter
02:35
created

UpdateTest::testUpdateSimple()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.8666
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\UpdateTest as GenericUpdateTest;
9
10
class UpdateTest extends GenericUpdateTest
11
{
12
    public function testToStringComplex()
13
    {
14
        $sql = (string)$this->getSut('foo')
15
            ->addModifier(Update::LOW_PRIORITY)
16
            ->setValues(['id' => '1234', 'bar_id' => '2345'])
17
            ->addWhere('foo.bar = "foo-bar"', new Expr('bar.foo = ?', ['bar-foo']))
18
            ->setLimit(10);
19
20
        $parts   = [];
21
        $parts[] = 'UPDATE LOW_PRIORITY foo';
22
        $parts[] = 'SET id = ?, bar_id = ?';
23
        $parts[] = 'WHERE foo.bar = "foo-bar" AND bar.foo = ?';
24
        $parts[] = 'LIMIT 10';
25
26
        $expectedSql = implode(PHP_EOL, $parts);
27
28
        $this->assertSame($expectedSql, $sql);
29
    }
30
31
    /**
32
     * @param string ...$tables
33
     *
34
     * @return Update
35
     */
36
    protected function getSut(string ...$tables): Update
37
    {
38
        return (new Update())->addFrom(...$tables);
39
    }
40
}
41