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

DeleteTest::testDeleteSimple()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A DeleteTest::testToStringThrowsAnExceptionIfNotInitialized() 0 5 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