Passed
Push — main ( 486097...4094a3 )
by Peter
02:37
created

JoinTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 62.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 56
ccs 10
cts 16
cp 0.625
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toStringGetParamsProvider() 0 18 1
A testToStringGetParamsProvider() 0 15 1
A testInvalidType() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace QB\Generic\Clause;
6
7
use PHPUnit\Framework\TestCase;
8
use QB\Generic\Expr\Expr;
9
use QB\Generic\IQueryPart;
10
11
class JoinTest extends TestCase
12
{
13
    public function toStringGetParamsProvider(): array
14
    {
15
        return [
16
            [
17
                IJoin::TYPE_INNER_JOIN,
18
                'foo',
19
                new Expr('f.id = bar.foo_id AND ?', [1]),
20
                'f',
21
                'INNER JOIN foo AS f ON f.id = bar.foo_id AND ?',
22
                [[1, \PDO::PARAM_INT]],
23
            ],
24
            [
25
                IJoin::TYPE_LEFT_JOIN,
26
                'foo',
27
                'foo.id = bar.foo_id',
28
                null,
29
                'LEFT JOIN foo ON foo.id = bar.foo_id',
30
                [],
31
            ],
32
        ];
33
    }
34
35
    /**
36
     * @dataProvider toStringGetParamsProvider
37
     *
38
     * @param string            $type
39
     * @param string            $tableName
40
     * @param IQueryPart|string $on
41
     * @param string|null       $alias
42
     * @param string            $expectedSql
43
     * @param array             $expectedParams
44
     */
45 2
    public function testToStringGetParamsProvider(
46
        string $type,
47
        string $tableName,
48
        IQueryPart|string $on,
49
        ?string $alias,
50
        string $expectedSql,
51
        array $expectedParams
52
    ) {
53 2
        $sut = new Join($type, $tableName, $on, $alias);
54
55 2
        $actualSql    = (string)$sut;
56 2
        $actualParams = $sut->getParams();
57
58 2
        $this->assertSame($expectedSql, $actualSql);
59 2
        $this->assertSame($expectedParams, $actualParams);
60 2
    }
61
62 1
    public function testInvalidType()
63
    {
64 1
        $this->expectException(\InvalidArgumentException::class);
65
66 1
        new Join('foo', 'bar', 'bar.id = foo.bar_id', 'b');
67
    }
68
}
69