ColumnTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetParamsReturnsEmptyArrayIfColumnNameIsProvided() 0 9 1
A testToStringWithoutAliasAndParams() 0 9 1
A testToStringWithoutParams() 0 11 1
A testToStringWithoutAlias() 0 11 1
A testGetParamsReturnsExpressionParams() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace QB\Generic\Clause;
6
7
use PDO;
8
use PHPUnit\Framework\TestCase;
9
use QB\Generic\Expr\Expr;
10
11
class ColumnTest extends TestCase
12
{
13
    public function testToStringWithoutAliasAndParams()
14
    {
15
        $colName = 'col';
16
17
        $sut = new Column($colName);
18
19
        $actualSql = (string)$sut;
20
21
        $this->assertSame($colName, $actualSql);
22
    }
23
24
    public function testToStringWithoutParams()
25
    {
26
        $expr   = new Expr('COUNT(col)');
27
        $column = 'col_count';
28
29
        $sut = new Column($expr, $column);
30
31
        $expectedSql  = 'COUNT(col) AS col_count';
32
        $actualResult = (string)$sut;
33
34
        $this->assertSame($expectedSql, $actualResult);
35
    }
36
37
    public function testToStringWithoutAlias()
38
    {
39
        $expectedSql = 'COUNT(col)';
40
41
        $expr = new Expr($expectedSql);
42
43
        $sut = new Column($expr);
44
45
        $actualResult = (string)$sut;
46
47
        $this->assertSame($expectedSql, $actualResult);
48
    }
49
50
    public function testGetParamsReturnsEmptyArrayIfColumnNameIsProvided()
51
    {
52
        $expectedSql = 'foo';
53
54
        $sut = new Column($expectedSql);
55
56
        $actualParams = $sut->getParams();
57
58
        $this->assertSame([], $actualParams);
59
    }
60
61
    public function testGetParamsReturnsExpressionParams()
62
    {
63
        $expr   = new Expr('LENGTH(:word) > 5', [':word' => 'foobar']);
64
        $column = 'is_word_long';
65
66
        $sut = new Column($expr, $column);
67
68
        $expectedParams = [':word' => ['foobar', PDO::PARAM_STR]];
69
        $actualParams   = $sut->getParams();
70
71
        $this->assertSame($expectedParams, $actualParams);
72
    }
73
}
74