|
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
|
|
|
|
|
21
|
|
|
public function setUp(): void |
|
22
|
|
|
{ |
|
23
|
|
|
parent::setUp(); |
|
24
|
|
|
|
|
25
|
|
|
$this->queryBuilder = Mock::getConnection()->getQueryBuilder(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function tearDown(): void |
|
29
|
|
|
{ |
|
30
|
|
|
parent::tearDown(); |
|
31
|
|
|
|
|
32
|
|
|
unset($this->queryBuilder); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testAddDefaultValue(): void |
|
36
|
|
|
{ |
|
37
|
|
|
$this->expectException(Exception::class); |
|
38
|
|
|
$this->expectExceptionMessage( |
|
39
|
|
|
'Yiisoft\Db\Tests\Support\Stubs\DDLQueryBuilder does not support adding default value constraints.' |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
$this->queryBuilder->addDefaultValue('name', 'table', 'column', 'value'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testBuilColumnStringException(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
48
|
|
|
$this->expectExceptionMessage( |
|
49
|
|
|
'Column name must be a string or an instance of ExpressionInterface.' |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
$this->queryBuilder->buildColumns([1]); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testBuildJoinException(): void |
|
56
|
|
|
{ |
|
57
|
|
|
$this->expectException(Exception::class); |
|
58
|
|
|
$this->expectExceptionMessage( |
|
59
|
|
|
'A join clause must be specified as an array of join type, join table, and optionally join condition.' |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
$params = []; |
|
63
|
|
|
$this->queryBuilder->buildJoin([1], $params); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testCheckIntegrityException(): void |
|
67
|
|
|
{ |
|
68
|
|
|
$this->expectException(Exception::class); |
|
69
|
|
|
$this->expectExceptionMessage( |
|
70
|
|
|
'Yiisoft\Db\Tests\Support\Stubs\DDLQueryBuilder does not support enabling/disabling integrity check.' |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
$this->queryBuilder->checkIntegrity('schema', 'table', true); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function testDropDefaultValueException(): void |
|
77
|
|
|
{ |
|
78
|
|
|
$this->expectException(Exception::class); |
|
79
|
|
|
$this->expectExceptionMessage( |
|
80
|
|
|
'Yiisoft\Db\Tests\Support\Stubs\DDLQueryBuilder does not support dropping default value constraints.' |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
$this->queryBuilder->dropDefaultValue('name', 'table', 'column'); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function testGetExpressionBuilderException(): void |
|
87
|
|
|
{ |
|
88
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
89
|
|
|
$this->expectExceptionMessage( |
|
90
|
|
|
'Expression of class Yiisoft\Db\Tests\Support\Stubs\ExpressionStub can not be built in Yiisoft\Db\Tests\Support\Stubs\DQLQueryBuilder' |
|
91
|
|
|
); |
|
92
|
|
|
|
|
93
|
|
|
$this->queryBuilder->getExpressionBuilder(new ExpressionStub()); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function testResetSequenceException(): void |
|
97
|
|
|
{ |
|
98
|
|
|
$this->expectException(Exception::class); |
|
99
|
|
|
$this->expectExceptionMessage( |
|
100
|
|
|
'Yiisoft\Db\Tests\Support\Stubs\DMLQueryBuilder does not support resetting sequence.' |
|
101
|
|
|
); |
|
102
|
|
|
|
|
103
|
|
|
$this->queryBuilder->resetSequence('table', 'column'); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testUpsertException(): void |
|
107
|
|
|
{ |
|
108
|
|
|
$this->expectException(Exception::class); |
|
109
|
|
|
$this->expectExceptionMessage( |
|
110
|
|
|
'Yiisoft\Db\Tests\Support\Stubs\DMLQueryBuilder does not support upsert.' |
|
111
|
|
|
); |
|
112
|
|
|
|
|
113
|
|
|
$params = []; |
|
114
|
|
|
$this->queryBuilder->upsert('table', ['column' => 'value'], [], $params); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
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.