Passed
Push — main ( bbfba8...2e1d9e )
by Peter
02:52
created

CombiningQueryTest::testConstructValidation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace QB\MySQL\Clause;
6
7
use PHPUnit\Framework\TestCase;
8
use QB\Generic\IQueryPart;
9
use QB\MySQL\Statement\Select;
10
11
class CombiningQueryTest extends TestCase
12
{
13
    protected IQueryPart $queryPart;
14
15
    public function setUp(): void
16
    {
17
        $this->queryPart = (new Select())->addColumn('2');
18
    }
19
20
    /**
21
     * @return array[]
22
     */
23
    public function toStringProvider(): array
24
    {
25
        return [
26
            [CombiningQuery::TYPE_UNION, null, "UNION\nSELECT 2"],
27
            [CombiningQuery::TYPE_UNION, CombiningQuery::MODIFIER_DISTINCT, "UNION DISTINCT\nSELECT 2"],
28
            [CombiningQuery::TYPE_UNION, CombiningQuery::MODIFIER_ALL, "UNION ALL\nSELECT 2"],
29
        ];
30
    }
31
32
    /**
33
     * @dataProvider toStringProvider
34
     *
35
     * @param string      $type
36
     * @param string|null $modifier
37
     * @param string      $expectedSql
38
     */
39
    public function testToString(string $type, ?string $modifier, string $expectedSql)
40
    {
41
        $lock = new CombiningQuery($type, $this->queryPart, $modifier);
42
        $sql  = (string)$lock;
43
44
        $this->assertSame($expectedSql, $sql);
45
    }
46
47
    /**
48
     * @return array[]
49
     */
50
    public function constructValidationProvider(): array
51
    {
52
        return [
53
            'invalid type'     => ['foo', null],
54
            'invalid modifier' => [CombiningQuery::TYPE_UNION, 'foo'],
55
        ];
56
    }
57
58
    /**
59
     * @dataProvider constructValidationProvider
60
     *
61
     * @suppress     PhanNoopNew
62
     *
63
     * @param string|null $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);
0 ignored issues
show
Bug introduced by
It seems like $type can also be of type null; however, parameter $type of QB\MySQL\Clause\CombiningQuery::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

70
        new CombiningQuery(/** @scrutinizer ignore-type */ $type, $this->queryPart, $modifier);
Loading history...
71
    }
72
}
73