CombiningQueryTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructValidation() 0 5 1
A testToString() 0 6 1
A constructValidationProvider() 0 5 1
A toStringProvider() 0 6 1
A setUp() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace QB\MySQL\Clause;
6
7
use InvalidArgumentException;
8
use PHPUnit\Framework\TestCase;
9
use QB\Generic\IQueryPart;
10
use QB\MySQL\Statement\Select;
11
12
class CombiningQueryTest extends TestCase
13
{
14
    protected IQueryPart $queryPart;
15
16
    public function setUp(): void
17
    {
18
        $this->queryPart = (new Select())->columns('2');
19
    }
20
21
    /**
22
     * @return array[]
23
     */
24
    public function toStringProvider(): array
25
    {
26
        return [
27
            [CombiningQuery::TYPE_UNION, null, "UNION\nSELECT 2"],
28
            [CombiningQuery::TYPE_UNION, CombiningQuery::MODIFIER_DISTINCT, "UNION DISTINCT\nSELECT 2"],
29
            [CombiningQuery::TYPE_UNION, CombiningQuery::MODIFIER_ALL, "UNION ALL\nSELECT 2"],
30
        ];
31
    }
32
33
    /**
34
     * @dataProvider toStringProvider
35
     *
36
     * @param string      $type
37
     * @param string|null $modifier
38
     * @param string      $expectedSql
39
     */
40
    public function testToString(string $type, ?string $modifier, string $expectedSql)
41
    {
42
        $lock = new CombiningQuery($type, $this->queryPart, $modifier);
43
        $sql  = (string)$lock;
44
45
        $this->assertSame($expectedSql, $sql);
46
    }
47
48
    /**
49
     * @return array[]
50
     */
51
    public function constructValidationProvider(): array
52
    {
53
        return [
54
            'invalid type'     => ['foo', null],
55
            'invalid modifier' => [CombiningQuery::TYPE_UNION, 'foo'],
56
        ];
57
    }
58
59
    /**
60
     * @dataProvider constructValidationProvider
61
     * @suppress     PhanNoopNew
62
     *
63
     * @param string      $type
64
     * @param string|null $modifier
65
     */
66
    public function testConstructValidation(string $type, ?string $modifier)
67
    {
68
        $this->expectException(InvalidArgumentException::class);
69
70
        new CombiningQuery($type, $this->queryPart, $modifier);
71
    }
72
}
73