From cc4d744b68d64d92e578cda89e110fbe1199eea3 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Thu, 31 Oct 2024 18:55:54 +0500 Subject: [PATCH 01/10] Ease local testing --- .github/workflows/build.yml | 7 +++++ composer.json | 4 ++- tests/CommandTest.php | 8 +----- tests/PDODriverTest.php | 8 ++---- tests/SchemaTest.php | 4 +-- tests/Support/TestTrait.php | 51 +++++++++++++++++++++++++++++++++---- tests/bootstrap.php | 8 ++++++ 7 files changed, 69 insertions(+), 21 deletions(-) create mode 100644 tests/bootstrap.php diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1e462f263..45bcedaf7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -86,6 +86,13 @@ jobs: - name: Run tests with phpunit with code coverage. run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations + env: + ENVIRONMENT: ci + YII_MYSQL_DATABASE: yiitest + YII_MYSQL_HOST: 127.0.0.1 + YII_MYSQL_PORT: 3306 + YII_MYSQL_USER: root + YII_MYSQL_PASSWORD: '' - name: Upload coverage to Codecov. uses: codecov/codecov-action@v3 diff --git a/composer.json b/composer.json index fde367f86..1b1760770 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,7 @@ "roave/infection-static-analysis-plugin": "^1.16", "spatie/phpunit-watcher": "^1.23", "vimeo/psalm": "^5.25", + "vlucas/phpdotenv": "^5.6", "yiisoft/aliases": "^2.0", "yiisoft/log-target-file": "^2.0", "yiisoft/cache-file": "^3.1", @@ -60,7 +61,8 @@ "psr-4": { "Yiisoft\\Db\\Mysql\\Tests\\": "tests", "Yiisoft\\Db\\Tests\\": "vendor/yiisoft/db/tests" - } + }, + "files": ["tests/bootstrap.php"] }, "config": { "sort-packages": true, diff --git a/tests/CommandTest.php b/tests/CommandTest.php index be24f0062..4a065e7b9 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -141,12 +141,6 @@ public function testUpsert(array $firstData, array $secondData): void public function testShowDatabases(): void { - $dsn = new Dsn('mysql', '127.0.0.1', ); - $db = new Connection(new Driver($dsn->asString(), 'root', ''), DbHelper::getSchemaCache()); - - $command = $db->createCommand(); - - $this->assertSame('mysql:host=127.0.0.1;port=3306', $db->getDriver()->getDsn()); - $this->assertSame(['yiitest'], $command->showDatabases()); + $this->assertSame([self::getDatabaseName()], static::getDb()->createCommand()->showDatabases()); } } diff --git a/tests/PDODriverTest.php b/tests/PDODriverTest.php index 647731564..d99a8af70 100644 --- a/tests/PDODriverTest.php +++ b/tests/PDODriverTest.php @@ -29,7 +29,7 @@ public function testConnectionCharset(): void $this->assertEqualsIgnoringCase('utf8mb4', array_values($charset)[1]); - $pdoDriver = new Driver('mysql:host=127.0.0.1;dbname=yiitest;port=3306', 'root', ''); + $pdoDriver = $this->getDriver(); $newCharset = 'latin1'; $pdoDriver->charset($newCharset); $pdo = $pdoDriver->createConnection(); @@ -40,11 +40,7 @@ public function testConnectionCharset(): void public function testCharsetDefault(): void { - $db = new Connection( - new Driver('mysql:host=127.0.0.1;dbname=yiitest;port=3306', 'root', ''), - DbHelper::getSchemaCache(), - ); - + $db = static::getDb(); $db->open(); $command = $db->createCommand(); diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 538460b3b..9f0144f3c 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -293,7 +293,7 @@ public function testGetSchemaNames(): void $schema = $db->getSchema(); - $this->assertSame(['yiitest'], $schema->getSchemaNames()); + $this->assertSame([self::getDatabaseName()], $schema->getSchemaNames()); } /** @@ -326,7 +326,7 @@ public function testGetTableNamesWithSchema(): void $db = $this->getConnection(true); $schema = $db->getSchema(); - $tablesNames = $schema->getTableNames('yiitest'); + $tablesNames = $schema->getTableNames(self::getDatabaseName()); $expectedTableNames = [ 'alpha', diff --git a/tests/Support/TestTrait.php b/tests/Support/TestTrait.php index 6bb30459a..0915fe6d4 100644 --- a/tests/Support/TestTrait.php +++ b/tests/Support/TestTrait.php @@ -5,6 +5,7 @@ namespace Yiisoft\Db\Mysql\Tests\Support; use Yiisoft\Db\Driver\Pdo\PdoConnectionInterface; +use Yiisoft\Db\Driver\Pdo\PdoDriverInterface; use Yiisoft\Db\Mysql\Connection; use Yiisoft\Db\Mysql\Driver; use Yiisoft\Db\Mysql\Dsn; @@ -16,7 +17,7 @@ trait TestTrait protected function getConnection(bool $fixture = false): PdoConnectionInterface { - $db = new Connection(new Driver($this->getDsn(), 'root', ''), DbHelper::getSchemaCache()); + $db = new Connection($this->getDriver(), DbHelper::getSchemaCache()); if ($fixture) { DbHelper::loadFixture($db, __DIR__ . '/Fixture/mysql.sql'); @@ -27,15 +28,25 @@ protected function getConnection(bool $fixture = false): PdoConnectionInterface protected static function getDb(): PdoConnectionInterface { - $dsn = (new Dsn(databaseName: 'yiitest', options: ['charset' => 'utf8mb4']))->asString(); - - return new Connection(new Driver($dsn, 'root', ''), DbHelper::getSchemaCache()); + $dsn = (new Dsn( + host: self::getHost(), + databaseName: self::getDatabaseName(), + port: self::getPort(), + options: ['charset' => 'utf8mb4'], + ))->asString(); + + return new Connection(new Driver($dsn, self::getUsername(), self::getPassword()), DbHelper::getSchemaCache()); } protected function getDsn(): string { if ($this->dsn === '') { - $this->dsn = (new Dsn(databaseName: 'yiitest', options: ['charset' => 'utf8mb4']))->asString(); + $this->dsn = (new Dsn( + host: self::getHost(), + databaseName: self::getDatabaseName(), + port: self::getPort(), + options: ['charset' => 'utf8mb4'], + ))->asString(); } return $this->dsn; @@ -59,4 +70,34 @@ public static function setUpBeforeClass(): void $db->close(); } + + private function getDriver(): PdoDriverInterface + { + return new Driver($this->getDsn(), self::getUsername(), self::getPassword()); + } + + private static function getDatabaseName(): string + { + return getenv('YII_MYSQL_DATABASE'); + } + + private static function getHost(): string + { + return getenv('YII_MYSQL_HOST'); + } + + private static function getPort(): string + { + return getenv('YII_MYSQL_PORT'); + } + + private static function getUsername(): string + { + return getenv('YII_MYSQL_USER'); + } + + private static function getPassword(): string + { + return getenv('YII_MYSQL_PASSWORD'); + } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 000000000..905b9ee55 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,8 @@ +load(); +} From 09c2dd72574566711094b25e9fbb476d37f6342f Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 31 Oct 2024 13:56:11 +0000 Subject: [PATCH 02/10] Apply fixes from StyleCI --- tests/CommandTest.php | 6 +----- tests/PDODriverTest.php | 5 +---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 4a065e7b9..4dbfa2b40 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -8,12 +8,8 @@ use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mysql\Connection; -use Yiisoft\Db\Mysql\Dsn; -use Yiisoft\Db\Mysql\Driver; use Yiisoft\Db\Mysql\Tests\Support\TestTrait; use Yiisoft\Db\Tests\Common\CommonCommandTest; -use Yiisoft\Db\Tests\Support\DbHelper; /** * @group mysql @@ -141,6 +137,6 @@ public function testUpsert(array $firstData, array $secondData): void public function testShowDatabases(): void { - $this->assertSame([self::getDatabaseName()], static::getDb()->createCommand()->showDatabases()); + $this->assertSame([self::getDatabaseName()], self::getDb()->createCommand()->showDatabases()); } } diff --git a/tests/PDODriverTest.php b/tests/PDODriverTest.php index d99a8af70..577a4ff1b 100644 --- a/tests/PDODriverTest.php +++ b/tests/PDODriverTest.php @@ -6,10 +6,7 @@ use PDO; use PHPUnit\Framework\TestCase; -use Yiisoft\Db\Mysql\Connection; -use Yiisoft\Db\Mysql\Driver; use Yiisoft\Db\Mysql\Tests\Support\TestTrait; -use Yiisoft\Db\Tests\Support\DbHelper; /** * @group mysql @@ -40,7 +37,7 @@ public function testConnectionCharset(): void public function testCharsetDefault(): void { - $db = static::getDb(); + $db = self::getDb(); $db->open(); $command = $db->createCommand(); From abb547d3f384710725751064a38190f8acd7ab70 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Thu, 31 Oct 2024 19:09:20 +0500 Subject: [PATCH 03/10] WIP --- .github/workflows/build-mariadb.yml | 7 +++++++ .github/workflows/composer-require-checker.yml | 2 ++ .github/workflows/mutation.yml | 1 + 3 files changed, 10 insertions(+) diff --git a/.github/workflows/build-mariadb.yml b/.github/workflows/build-mariadb.yml index fedfc19d8..05f7cfdf8 100644 --- a/.github/workflows/build-mariadb.yml +++ b/.github/workflows/build-mariadb.yml @@ -91,6 +91,13 @@ jobs: - name: Run tests with phpunit with code coverage. run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations + env: + ENVIRONMENT: ci + YII_MYSQL_DATABASE: yiitest + YII_MYSQL_HOST: 127.0.0.1 + YII_MYSQL_PORT: 3306 + YII_MYSQL_USER: root + YII_MYSQL_PASSWORD: '' - name: Upload coverage to Codecov. uses: codecov/codecov-action@v3 diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml index c2ca43f8b..7d3846bd5 100644 --- a/.github/workflows/composer-require-checker.yml +++ b/.github/workflows/composer-require-checker.yml @@ -64,3 +64,5 @@ jobs: - name: Check dependencies. run: vendor/bin/composer-require-checker + env: + ENVIRONMENT: ci diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index b6683a09c..5d6d7a63b 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -79,3 +79,4 @@ jobs: vendor/bin/roave-infection-static-analysis-plugin --threads=2 --ignore-msi-with-no-mutations --only-covered env: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} + ENVIRONMENT: ci From 57d0e2d7ba6a633cf7a94b70de6ff2ef61f81372 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Thu, 31 Oct 2024 19:09:56 +0500 Subject: [PATCH 04/10] WIP --- .github/workflows/ansi-mode.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ansi-mode.yml b/.github/workflows/ansi-mode.yml index a3d68beaf..1042807d5 100644 --- a/.github/workflows/ansi-mode.yml +++ b/.github/workflows/ansi-mode.yml @@ -85,6 +85,13 @@ jobs: - name: Run tests with phpunit with code coverage. run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations + env: + ENVIRONMENT: ci + YII_MYSQL_DATABASE: yiitest + YII_MYSQL_HOST: 127.0.0.1 + YII_MYSQL_PORT: 3306 + YII_MYSQL_USER: root + YII_MYSQL_PASSWORD: '' - name: Upload coverage to Codecov. uses: codecov/codecov-action@v3 From bdb8f4ddf9624b4133aab63cb0f7fedfbbd2e4dc Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Thu, 31 Oct 2024 19:24:32 +0500 Subject: [PATCH 05/10] WIP --- .github/workflows/mutation.yml | 5 +++++ .github/workflows/static.yml | 2 ++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 5d6d7a63b..f2b29fa6a 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -80,3 +80,8 @@ jobs: env: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} ENVIRONMENT: ci + YII_MYSQL_DATABASE: yiitest + YII_MYSQL_HOST: 127.0.0.1 + YII_MYSQL_PORT: 3306 + YII_MYSQL_USER: root + YII_MYSQL_PASSWORD: '' diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 95e5fd752..81bff4e2f 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -66,3 +66,5 @@ jobs: - name: Static analysis. run: vendor/bin/psalm --config=${{ inputs.psalm-config }} --shepherd --stats --output-format=github --php-version=${{ matrix.php }} + env: + ENVIRONMENT: ci From f7080edb675f57cf37c50ad541b2dbe83ac1481f Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Thu, 31 Oct 2024 19:28:59 +0500 Subject: [PATCH 06/10] WIP --- .github/workflows/rector.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index edce19b28..44fcc242c 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -16,3 +16,5 @@ jobs: ['ubuntu-latest'] php: >- ['8.3'] + env: + ENVIRONMENT: ci From 4673c2118b5bb8d83ae5d0edc3dd86178a246d12 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Thu, 31 Oct 2024 19:32:30 +0500 Subject: [PATCH 07/10] WIP --- .github/workflows/ansi-mode.yml | 1 - .github/workflows/build-mariadb.yml | 1 - .github/workflows/build.yml | 1 - .github/workflows/composer-require-checker.yml | 2 -- .github/workflows/mutation.yml | 1 - .github/workflows/rector.yml | 2 -- .github/workflows/static.yml | 2 -- tests/bootstrap.php | 2 +- 8 files changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/ansi-mode.yml b/.github/workflows/ansi-mode.yml index 1042807d5..cdbccc24b 100644 --- a/.github/workflows/ansi-mode.yml +++ b/.github/workflows/ansi-mode.yml @@ -86,7 +86,6 @@ jobs: - name: Run tests with phpunit with code coverage. run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations env: - ENVIRONMENT: ci YII_MYSQL_DATABASE: yiitest YII_MYSQL_HOST: 127.0.0.1 YII_MYSQL_PORT: 3306 diff --git a/.github/workflows/build-mariadb.yml b/.github/workflows/build-mariadb.yml index 05f7cfdf8..4f941defb 100644 --- a/.github/workflows/build-mariadb.yml +++ b/.github/workflows/build-mariadb.yml @@ -92,7 +92,6 @@ jobs: - name: Run tests with phpunit with code coverage. run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations env: - ENVIRONMENT: ci YII_MYSQL_DATABASE: yiitest YII_MYSQL_HOST: 127.0.0.1 YII_MYSQL_PORT: 3306 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 45bcedaf7..3bc5ef7a7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -87,7 +87,6 @@ jobs: - name: Run tests with phpunit with code coverage. run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always --display-warnings --display-deprecations env: - ENVIRONMENT: ci YII_MYSQL_DATABASE: yiitest YII_MYSQL_HOST: 127.0.0.1 YII_MYSQL_PORT: 3306 diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml index 7d3846bd5..c2ca43f8b 100644 --- a/.github/workflows/composer-require-checker.yml +++ b/.github/workflows/composer-require-checker.yml @@ -64,5 +64,3 @@ jobs: - name: Check dependencies. run: vendor/bin/composer-require-checker - env: - ENVIRONMENT: ci diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index f2b29fa6a..2a286da7c 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -79,7 +79,6 @@ jobs: vendor/bin/roave-infection-static-analysis-plugin --threads=2 --ignore-msi-with-no-mutations --only-covered env: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} - ENVIRONMENT: ci YII_MYSQL_DATABASE: yiitest YII_MYSQL_HOST: 127.0.0.1 YII_MYSQL_PORT: 3306 diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index 44fcc242c..edce19b28 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -16,5 +16,3 @@ jobs: ['ubuntu-latest'] php: >- ['8.3'] - env: - ENVIRONMENT: ci diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 81bff4e2f..95e5fd752 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -66,5 +66,3 @@ jobs: - name: Static analysis. run: vendor/bin/psalm --config=${{ inputs.psalm-config }} --shepherd --stats --output-format=github --php-version=${{ matrix.php }} - env: - ENVIRONMENT: ci diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 905b9ee55..0b8567eb8 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,7 +2,7 @@ declare(strict_types=1); -if (getenv('ENVIRONMENT', local_only: true) !== 'ci') { +if (getenv('ENVIRONMENT', local_only: true) === 'local') { $dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__); $dotenv->load(); } From 31f50e94e91b08c3de1f16e3e69bcc5abb3e6dda Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Thu, 31 Oct 2024 19:39:13 +0500 Subject: [PATCH 08/10] WIP --- .gitignore | 4 ---- tests/.env | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 tests/.env diff --git a/.gitignore b/.gitignore index 61ac953dd..2ea2501ec 100644 --- a/.gitignore +++ b/.gitignore @@ -40,7 +40,3 @@ phpunit.phar /apps /extensions /packages - -# NPM packages -/node_modules -.env diff --git a/tests/.env b/tests/.env new file mode 100644 index 000000000..a554a517a --- /dev/null +++ b/tests/.env @@ -0,0 +1,25 @@ +ENVIRONMENT=local + +YII_MYSQL_DATABASE=yii +YII_MYSQL_HOST=mysql +YII_MYSQL_PORT=3306 +YII_MYSQL_USER=root +YII_MYSQL_PASSWORD=root + +YII_PGSQL_DATABASE=yii +YII_PGSQL_HOST=postgres +YII_PGSQL_PORT=5432 +YII_PGSQL_USER=postgres +YII_PGSQL_PASSWORD=postgres + +YII_MSSQL_DATABASE=tempdb +YII_MSSQL_HOST=mssql +YII_MSSQL_PORT=1433 +YII_MSSQL_USER=SA +YII_MSSQL_PASSWORD=YourStrong!Passw0rd + +YII_ORACLE_DATABASE= +YII_ORACLE_HOST=oracle +YII_ORACLE_PORT= +YII_ORACLE_USER=system +YII_ORACLE_PASSWORD=root From 2d1a81f34c8f202b7ab192dc762293621da32598 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Thu, 31 Oct 2024 19:45:05 +0500 Subject: [PATCH 09/10] WIP [skip ci] --- tests/.env | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/tests/.env b/tests/.env index a554a517a..3dc0f6c8e 100644 --- a/tests/.env +++ b/tests/.env @@ -1,25 +1,6 @@ ENVIRONMENT=local - YII_MYSQL_DATABASE=yii YII_MYSQL_HOST=mysql YII_MYSQL_PORT=3306 YII_MYSQL_USER=root YII_MYSQL_PASSWORD=root - -YII_PGSQL_DATABASE=yii -YII_PGSQL_HOST=postgres -YII_PGSQL_PORT=5432 -YII_PGSQL_USER=postgres -YII_PGSQL_PASSWORD=postgres - -YII_MSSQL_DATABASE=tempdb -YII_MSSQL_HOST=mssql -YII_MSSQL_PORT=1433 -YII_MSSQL_USER=SA -YII_MSSQL_PASSWORD=YourStrong!Passw0rd - -YII_ORACLE_DATABASE= -YII_ORACLE_HOST=oracle -YII_ORACLE_PORT= -YII_ORACLE_USER=system -YII_ORACLE_PASSWORD=root From b87162d4f1a945fcde384bc9cfc5869e5a39b063 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Wed, 20 Nov 2024 00:31:13 +0500 Subject: [PATCH 10/10] WIP --- tests/Support/TestTrait.php | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/tests/Support/TestTrait.php b/tests/Support/TestTrait.php index 0915fe6d4..ab576d1ce 100644 --- a/tests/Support/TestTrait.php +++ b/tests/Support/TestTrait.php @@ -78,26 +78,51 @@ private function getDriver(): PdoDriverInterface private static function getDatabaseName(): string { - return getenv('YII_MYSQL_DATABASE'); + if (self::isMariadb()) { + return getenv('YII_MARIADB_DATABASE') ?: ''; + } + + return getenv('YII_MYSQL_DATABASE') ?: ''; } private static function getHost(): string { - return getenv('YII_MYSQL_HOST'); + if (self::isMariadb()) { + return getenv('YII_MARIADB_HOST') ?: ''; + } + + return getenv('YII_MYSQL_HOST') ?: ''; } private static function getPort(): string { - return getenv('YII_MYSQL_PORT'); + if (self::isMariadb()) { + return getenv('YII_MARIADB_PORT') ?: ''; + } + + return getenv('YII_MYSQL_PORT') ?: ''; } private static function getUsername(): string { - return getenv('YII_MYSQL_USER'); + if (self::isMariadb()) { + return getenv('YII_MARIADB_USER') ?: ''; + } + + return getenv('YII_MYSQL_USER') ?: ''; } private static function getPassword(): string { - return getenv('YII_MYSQL_PASSWORD'); + if (self::isMariadb()) { + return getenv('YII_MARIADB_PASSWORD') ?: ''; + } + + return getenv('YII_MYSQL_PASSWORD') ?: ''; + } + + private static function isMariadb(): bool + { + return getenv('YII_MYSQL_TYPE') === 'mariadb'; } }