|
4 | 4 |
|
5 | 5 | namespace Yiisoft\Db\Pgsql\Tests; |
6 | 6 |
|
| 7 | +use InvalidArgumentException; |
| 8 | +use LogicException; |
7 | 9 | use Throwable; |
8 | 10 | use Yiisoft\Db\Exception\Exception; |
9 | 11 | use Yiisoft\Db\Exception\InvalidConfigException; |
10 | 12 | use Yiisoft\Db\Exception\NotSupportedException; |
11 | 13 | use Yiisoft\Db\Expression\JsonExpression; |
| 14 | +use Yiisoft\Db\Pgsql\Command; |
12 | 15 | use Yiisoft\Db\Pgsql\Connection; |
13 | | -use Yiisoft\Db\Pgsql\Dsn; |
14 | 16 | use Yiisoft\Db\Pgsql\Driver; |
| 17 | +use Yiisoft\Db\Pgsql\Dsn; |
15 | 18 | use Yiisoft\Db\Pgsql\Tests\Support\TestTrait; |
16 | 19 | use Yiisoft\Db\Tests\Common\CommonCommandTest; |
17 | 20 | use Yiisoft\Db\Tests\Support\DbHelper; |
@@ -330,4 +333,78 @@ public function testShowDatabases(): void |
330 | 333 | $this->assertSame('pgsql:host=127.0.0.1;dbname=postgres;port=5432', $db->getDriver()->getDsn()); |
331 | 334 | $this->assertSame(['yiitest'], $command->showDatabases()); |
332 | 335 | } |
| 336 | + |
| 337 | + public function testRefreshMaterializesView(): void |
| 338 | + { |
| 339 | + $db = $this->getConnection(true); |
| 340 | + /** @var Command $command */ |
| 341 | + $command = $db->createCommand(); |
| 342 | + |
| 343 | + $command->refreshMaterializedView('mat_view_without_unique'); |
| 344 | + |
| 345 | + $this->expectException(LogicException::class); |
| 346 | + $this->expectExceptionMessage('CONCURRENTLY refresh is not allowed without unique index.'); |
| 347 | + $command->refreshMaterializedView('mat_view_without_unique', true); |
| 348 | + } |
| 349 | + |
| 350 | + public static function materializedViewExceptionsDataProvider(): array |
| 351 | + { |
| 352 | + return [ |
| 353 | + [ |
| 354 | + 'mat_view_without_unique', |
| 355 | + true, |
| 356 | + null, |
| 357 | + LogicException::class, |
| 358 | + 'CONCURRENTLY refresh is not allowed without unique index.' |
| 359 | + ], |
| 360 | + |
| 361 | + [ |
| 362 | + 'mat_view_with_unique', |
| 363 | + true, |
| 364 | + false, |
| 365 | + LogicException::class, |
| 366 | + 'CONCURRENTLY and WITH NO DATA may not be specified together.' |
| 367 | + ], |
| 368 | + |
| 369 | + [ |
| 370 | + 'mat_view_with_unique', |
| 371 | + null, |
| 372 | + false, |
| 373 | + LogicException::class, |
| 374 | + 'CONCURRENTLY and WITH NO DATA may not be specified together.' |
| 375 | + ], |
| 376 | + |
| 377 | + [ |
| 378 | + 'not_exists_mat_view', |
| 379 | + null, |
| 380 | + null, |
| 381 | + InvalidArgumentException::class, |
| 382 | + '"not_exists_mat_view" not found in DB' |
| 383 | + ] |
| 384 | + ]; |
| 385 | + } |
| 386 | + |
| 387 | + /** |
| 388 | + * @dataProvider materializedViewExceptionsDataProvider |
| 389 | + * @param string $viewName |
| 390 | + * @param bool|null $concurrently |
| 391 | + * @param bool|null $withData |
| 392 | + * @param string $exception |
| 393 | + * @param string $message |
| 394 | + * @return void |
| 395 | + * @throws Exception |
| 396 | + * @throws InvalidConfigException |
| 397 | + */ |
| 398 | + public function testRefreshMaterializesViewExceptions(string $viewName, ?bool $concurrently, ?bool $withData, string $exception, string $message): void |
| 399 | + { |
| 400 | + $db = $this->getConnection(true); |
| 401 | + |
| 402 | + /** @var Command $command */ |
| 403 | + $command = $db->createCommand(); |
| 404 | + |
| 405 | + $this->expectException($exception); |
| 406 | + $this->expectExceptionMessage($message); |
| 407 | + |
| 408 | + $command->refreshMaterializedView($viewName, $concurrently, $withData); |
| 409 | + } |
333 | 410 | } |
0 commit comments