|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of CodeIgniter 4 framework. |
| 7 | + * |
| 8 | + * (c) CodeIgniter Foundation <admin@codeigniter.com> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view |
| 11 | + * the LICENSE file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace CodeIgniter\Database\Live\Postgre; |
| 15 | + |
| 16 | +use CodeIgniter\Database\Exceptions\DatabaseException; |
| 17 | +use CodeIgniter\Test\CIUnitTestCase; |
| 18 | +use Config\Database; |
| 19 | +use PHPUnit\Framework\Attributes\Group; |
| 20 | + |
| 21 | +/** |
| 22 | + * @internal |
| 23 | + */ |
| 24 | +#[Group('DatabaseLive')] |
| 25 | +final class ConnectTest extends CIUnitTestCase |
| 26 | +{ |
| 27 | + protected function setUp(): void |
| 28 | + { |
| 29 | + parent::setUp(); |
| 30 | + |
| 31 | + $this->db = Database::connect($this->DBGroup); |
| 32 | + |
| 33 | + if ($this->db->DBDriver !== 'Postgre') { |
| 34 | + $this->markTestSkipped('This test is only for Postgre.'); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + public function testShowErrorMessageWhenSettingInvalidCharset(): void |
| 39 | + { |
| 40 | + $this->expectException(DatabaseException::class); |
| 41 | + $this->expectExceptionMessage( |
| 42 | + 'Unable to connect to the database. |
| 43 | +Main connection [Postgre]: ERROR: invalid value for parameter "client_encoding": "utf8mb4"' |
| 44 | + ); |
| 45 | + |
| 46 | + $config = config('Database'); |
| 47 | + $group = $config->tests; |
| 48 | + // Sets invalid charset. |
| 49 | + $group['charset'] = 'utf8mb4'; |
| 50 | + $db = Database::connect($group); |
| 51 | + |
| 52 | + // Actually connect to DB. |
| 53 | + $db->initialize(); |
| 54 | + } |
| 55 | +} |
0 commit comments