Passed
Pull Request — master (#380)
by Wilmer
02:58
created

ExceptionTest::testCheckIntegrityException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests\QueryBuilder;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Db\Exception\Exception;
9
use Yiisoft\Db\Exception\InvalidArgumentException;
10
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
11
use Yiisoft\Db\Tests\Support\Mock;
12
use Yiisoft\Db\Tests\Support\Stubs\ExpressionStub;
13
14
/**
15
 * @group db
16
 */
17
final class ExceptionTest extends TestCase
18
{
19
    private QueryBuilderInterface $queryBuilder;
20
    private Mock $mock;
21
22
    public function setUp(): void
23
    {
24
        parent::setUp();
25
26
        $this->mock = new Mock();
27
        $this->queryBuilder = $this->mock->queryBuilder();
28
    }
29
30
    public function tearDown(): void
31
    {
32
        parent::tearDown();
33
34
        unset($this->queryBuilder, $this->mock);
35
    }
36
37
    public function testAddDefaultValue(): void
38
    {
39
        $this->expectException(Exception::class);
40
        $this->expectExceptionMessage(
41
            'Yiisoft\Db\Tests\Support\Stubs\DDLQueryBuilder does not support adding default value constraints.'
42
        );
43
        $this->queryBuilder->addDefaultValue('name', 'table', 'column', 'value');
44
    }
45
46
    public function testBuilColumnStringException(): void
47
    {
48
        $this->expectException(InvalidArgumentException::class);
49
        $this->expectExceptionMessage(
50
            'Column name must be a string or an instance of ExpressionInterface.'
51
        );
52
53
        $this->queryBuilder->buildColumns([1]);
54
    }
55
56
    public function testBuildJoinException(): void
57
    {
58
        $this->expectException(Exception::class);
59
        $this->expectExceptionMessage(
60
            'A join clause must be specified as an array of join type, join table, and optionally join condition.'
61
        );
62
63
        $params = [];
64
        $this->queryBuilder->buildJoin([1], $params);
65
    }
66
67
    public function testCheckIntegrityException(): void
68
    {
69
        $this->expectException(Exception::class);
70
        $this->expectExceptionMessage(
71
            'Yiisoft\Db\Tests\Support\Stubs\DDLQueryBuilder does not support enabling/disabling integrity check.'
72
        );
73
74
        $this->queryBuilder->checkIntegrity('schema', 'table', true);
75
    }
76
77
    public function testDropDefaultValueException(): void
78
    {
79
        $this->expectException(Exception::class);
80
        $this->expectExceptionMessage(
81
            'Yiisoft\Db\Tests\Support\Stubs\DDLQueryBuilder does not support dropping default value constraints.'
82
        );
83
84
        $this->queryBuilder->dropDefaultValue('name', 'table', 'column');
0 ignored issues
show
Unused Code introduced by
The call to Yiisoft\Db\QueryBuilder\...ace::dropDefaultValue() has too many arguments starting with 'column'. ( Ignorable by Annotation )

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

84
        $this->queryBuilder->/** @scrutinizer ignore-call */ 
85
                             dropDefaultValue('name', 'table', 'column');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
85
    }
86
87
    public function testGetExpressionBuilderException(): void
88
    {
89
        $this->expectException(InvalidArgumentException::class);
90
        $this->expectExceptionMessage(
91
            'Expression of class Yiisoft\Db\Tests\Support\Stubs\ExpressionStub can not be built in Yiisoft\Db\Tests\Support\Stubs\DQLQueryBuilder'
92
        );
93
94
        $this->queryBuilder->getExpressionBuilder(new ExpressionStub());
95
    }
96
97
    public function testResetSequenceException(): void
98
    {
99
        $this->expectException(Exception::class);
100
        $this->expectExceptionMessage(
101
            'Yiisoft\Db\Tests\Support\Stubs\DMLQueryBuilder does not support resetting sequence.'
102
        );
103
104
        $this->queryBuilder->resetSequence('table', 'column');
105
    }
106
107
    public function testUpsertException(): void
108
    {
109
        $this->expectException(Exception::class);
110
        $this->expectExceptionMessage(
111
            'Yiisoft\Db\Tests\Support\Stubs\DMLQueryBuilder does not support upsert.'
112
        );
113
114
        $params = [];
115
        $this->queryBuilder->upsert('table', ['column' => 'value'], [], $params);
116
    }
117
}
118