Skip to content

Commit

Permalink
Fixed port for MigrationControllerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhirtz committed Jan 24, 2024
1 parent 3d4d754 commit c751aab
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions tests/unit/console/MigrationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ class MigrationControllerMock extends MigrateController
private ?string $dbUsername = null;
private ?string $dbPassword = null;
private ?string $dbName = null;
private ?string $dbPort = null;

public function resetDbCredentials(): void
{
$this->dbUsername = Yii::$app->getDb()->username;
$this->dbPassword = Yii::$app->getDb()->password;

$dbname = preg_replace('/^.*dbname=([^;]+).*$/i', '$1', (string) Yii::$app->getDb()->dsn);
$this->dbName = $dbname;
$this->dbName = preg_replace('/^.*dbname=([^;]+).*$/i', '$1', (string) Yii::$app->getDb()->dsn);
$this->dbPort = preg_replace('/^.*port=([^;]+).*$/i', '$1', (string) Yii::$app->getDb()->dsn);

Yii::$app->getDb()->dsn = '';
}
Expand All @@ -121,13 +122,9 @@ public function confirm($message, $default = false): bool

public function prompt($text, $options = []): string
{
// grab dbname= from dsn
$dbname = preg_replace('/^.*dbname=([^;]+).*$/i', '$1', (string) Yii::$app->getDb()->dsn);
codecept_debug("dbname: $dbname");

return match ($text) {
'Enter database host:' => 'localhost',
'Enter port or leave empty:' => '',
'Enter port or leave empty:' => $this->dbPort,
'Enter database name:' => $this->dbName,
'Enter username:' => $this->dbUsername,
default => parent::prompt($text, $options),
Expand Down

0 comments on commit c751aab

Please sign in to comment.