-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8913 from kenjis/fix-postgre-error-msg
fix: [Postgres] show missing error message
- Loading branch information
Showing
3 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of CodeIgniter 4 framework. | ||
* | ||
* (c) CodeIgniter Foundation <[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CodeIgniter\Database\Live\Postgre; | ||
|
||
use CodeIgniter\Database\Exceptions\DatabaseException; | ||
use CodeIgniter\Test\CIUnitTestCase; | ||
use Config\Database; | ||
use PHPUnit\Framework\Attributes\Group; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[Group('DatabaseLive')] | ||
final class ConnectTest extends CIUnitTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->db = Database::connect($this->DBGroup); | ||
|
||
if ($this->db->DBDriver !== 'Postgre') { | ||
$this->markTestSkipped('This test is only for Postgre.'); | ||
} | ||
} | ||
|
||
public function testShowErrorMessageWhenSettingInvalidCharset(): void | ||
{ | ||
$this->expectException(DatabaseException::class); | ||
$this->expectExceptionMessage( | ||
'Unable to connect to the database. | ||
Main connection [Postgre]: ERROR: invalid value for parameter "client_encoding": "utf8mb4"' | ||
); | ||
|
||
$config = config('Database'); | ||
$group = $config->tests; | ||
// Sets invalid charset. | ||
$group['charset'] = 'utf8mb4'; | ||
$db = Database::connect($group); | ||
|
||
// Actually connect to DB. | ||
$db->initialize(); | ||
} | ||
} |