|
6 | 6 |
|
7 | 7 | use Closure; |
8 | 8 | use JsonException; |
| 9 | +use LogicException; |
9 | 10 | use PHPUnit\Framework\Attributes\DataProvider; |
10 | 11 | use PHPUnit\Framework\Attributes\DataProviderExternal; |
11 | 12 | use PHPUnit\Framework\TestCase; |
@@ -306,7 +307,7 @@ public function testBuildIssue15653(): void |
306 | 307 |
|
307 | 308 | $qb = $db->getQueryBuilder(); |
308 | 309 | $query = (new Query($db))->from('admin_user')->where(['is_deleted' => false]); |
309 | | - $query->where([])->andWhere(['in', 'id', ['1', '0']]); |
| 310 | + $query->setWhere([])->andWhere(['in', 'id', ['1', '0']]); |
310 | 311 |
|
311 | 312 | [$sql, $params] = $qb->build($query); |
312 | 313 |
|
@@ -474,6 +475,28 @@ public function testBuildLikeCondition( |
474 | 475 | } |
475 | 476 | } |
476 | 477 |
|
| 478 | + /** |
| 479 | + * @throws LogicException |
| 480 | + */ |
| 481 | + public function testOverwriteWhereCondition(): void |
| 482 | + { |
| 483 | + $db = $this->getConnection(); |
| 484 | +
|
| 485 | + try { |
| 486 | + (new Query($db)) |
| 487 | + ->where(['like', 'name', 'foo%']) |
| 488 | + ->where(['not like', 'name', 'foo%']); |
| 489 | + } catch (LogicException $e) { |
| 490 | + $this->assertEquals('The `where` condition was set earlier. Use the `setWhere()`, `andWhere()` or `orWhere()` method.', $e->getMessage()); |
| 491 | + } |
| 492 | +
|
| 493 | + $query = (new Query($db)) |
| 494 | + ->where(['like', 'name', 'foo%']) |
| 495 | + ->setWhere(['not like', 'name', 'foo%']); |
| 496 | +
|
| 497 | + $this->assertEquals(['not like', 'name', 'foo%'], $query->getWhere()); |
| 498 | + } |
| 499 | +
|
477 | 500 | public function testBuildLimit(): void |
478 | 501 | { |
479 | 502 | $db = $this->getConnection(); |
|
0 commit comments