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

DeleteTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 57
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSut() 0 3 1
A testToStringSimple() 0 10 1
A testToStringThrowsAnExceptionIfNotInitialized() 0 5 1
A testToStringComplex() 0 12 1
A testGetParams() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace QB\Generic\Statement;
6
7
use PDO;
8
use PHPUnit\Framework\TestCase;
9
use QB\Generic\Expr\Expr;
10
11
class DeleteTest extends TestCase
12
{
13
    /**
14
     * @suppress PhanNoopCast
15
     */
16
    public function testToStringThrowsAnExceptionIfNotInitialized()
17
    {
18
        $this->expectException(\RuntimeException::class);
19
20
        (string)$this->getSut();
21
    }
22
23
    public function testToStringSimple()
24
    {
25
        $sql = (string)$this->getSut('foo');
26
27
        $parts   = [];
28
        $parts[] = 'DELETE FROM foo';
29
30
        $expectedSql = implode(PHP_EOL, $parts);
31
32
        $this->assertSame($expectedSql, $sql);
33
    }
34
35
    public function testToStringComplex()
36
    {
37
        $sql = (string)$this->getSut('foo')
38
            ->addWhere('foo.bar = "foo-bar"', 'bar.foo = 17');
39
40
        $parts   = [];
41
        $parts[] = 'DELETE FROM foo';
42
        $parts[] = 'WHERE foo.bar = "foo-bar" AND bar.foo = 17';
43
44
        $expectedSql = implode(PHP_EOL, $parts);
45
46
        $this->assertSame($expectedSql, $sql);
47
    }
48
49
    public function testGetParams()
50
    {
51
        $expectedParams = [['bar-foo', PDO::PARAM_STR]];
52
        $query = $this->getSut('foo')
53
            ->addWhere('foo.bar = "foo-bar"', new Expr('bar.foo = ?', ['bar-foo']));
54
55
        $params = $query->getParams();
56
57
        $this->assertSame($expectedParams, $params);
58
    }
59
60
    /**
61
     * @param string ...$tables
62
     *
63
     * @return IDelete
64
     */
65
    protected function getSut(string ...$tables): IDelete
66
    {
67
        return (new Delete())->addFrom(...$tables);
68
    }
69
}
70