From 98f135760878681096df925c307a3fdd5122a66a Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Fri, 1 Nov 2024 21:56:19 +0500 Subject: [PATCH 1/7] Ease local testing --- composer.json | 4 ++- tests/.env | 6 +++++ tests/Support/TestTrait.php | 51 +++++++++++++++++++++++++++++++++---- tests/bootstrap.php | 8 ++++++ 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 tests/.env create mode 100644 tests/bootstrap.php diff --git a/composer.json b/composer.json index a9b12247..9fd143d1 100644 --- a/composer.json +++ b/composer.json @@ -41,6 +41,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/cache-file": "^3.1", "yiisoft/var-dumper": "^1.5" @@ -54,7 +55,8 @@ "psr-4": { "Yiisoft\\Db\\Oracle\\Tests\\": "tests", "Yiisoft\\Db\\Tests\\": "vendor/yiisoft/db/tests" - } + }, + "files": ["tests/bootstrap.php"] }, "config": { "sort-packages": true, diff --git a/tests/.env b/tests/.env new file mode 100644 index 00000000..a355b624 --- /dev/null +++ b/tests/.env @@ -0,0 +1,6 @@ +ENVIRONMENT=local +YII_ORACLE_DATABASE= +YII_ORACLE_HOST=oracle +YII_ORACLE_PORT= +YII_ORACLE_USER=system +YII_ORACLE_PASSWORD=root diff --git a/tests/Support/TestTrait.php b/tests/Support/TestTrait.php index 8d5c73d3..702ab79b 100644 --- a/tests/Support/TestTrait.php +++ b/tests/Support/TestTrait.php @@ -5,6 +5,7 @@ namespace Yiisoft\Db\Oracle\Tests\Support; use Yiisoft\Db\Driver\Pdo\PdoConnectionInterface; +use Yiisoft\Db\Driver\Pdo\PdoDriverInterface; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Oracle\Connection; @@ -14,7 +15,7 @@ trait TestTrait { - private string $dsn = 'oci:dbname=localhost/XE;'; + private string $dsn = ''; /** * @throws InvalidConfigException @@ -22,7 +23,7 @@ trait TestTrait */ protected function getConnection(bool $fixture = false): PdoConnectionInterface { - $db = new Connection(new Driver($this->getDsn(), 'system', 'root'), DbHelper::getSchemaCache()); + $db = new Connection($this->getDriver(), DbHelper::getSchemaCache()); if ($fixture) { DbHelper::loadFixture($db, __DIR__ . '/Fixture/oci.sql'); @@ -33,15 +34,25 @@ protected function getConnection(bool $fixture = false): PdoConnectionInterface protected static function getDb(): PdoConnectionInterface { - $dsn = (new Dsn(databaseName: 'XE', options: ['charset' => 'AL32UTF8']))->asString(); + $dsn = (new Dsn( + host: self::getHost(), + databaseName: self::getDatabaseName(), + port: self::getPort(), + options: ['charset' => 'AL32UTF8'], + ))->asString(); - return new Connection(new Driver($dsn, 'system', 'root'), DbHelper::getSchemaCache()); + return new Connection(new Driver($dsn, self::getUsername(), self::getPassword()), DbHelper::getSchemaCache()); } protected function getDsn(): string { if ($this->dsn === '') { - $this->dsn = (new Dsn(databaseName: 'XE', options: ['charset' => 'AL32UTF8']))->asString(); + $this->dsn = (new Dsn( + host: self::getHost(), + databaseName: self::getDatabaseName(), + port: self::getPort(), + options: ['charset' => 'AL32UTF8'], + ))->asString(); } return $this->dsn; @@ -56,4 +67,34 @@ protected function setDsn(string $dsn): void { $this->dsn = $dsn; } + + private function getDriver(): PdoDriverInterface + { + return new Driver($this->getDsn(), self::getUsername(), self::getPassword()); + } + + private static function getDatabaseName(): string + { + return getenv('YII_ORACLE_DATABASE') ?: 'XE'; + } + + private static function getHost(): string + { + return getenv('YII_ORACLE_HOST'); + } + + private static function getPort(): string + { + return getenv('YII_ORACLE_PORT') ?: '1521'; + } + + private static function getUsername(): string + { + return getenv('YII_ORACLE_USER'); + } + + private static function getPassword(): string + { + return getenv('YII_ORACLE_PASSWORD'); + } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..0b8567eb --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,8 @@ +load(); +} From 026bcf5080930aec4fc7516df2f684eb76c1ed1e Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Mon, 18 Nov 2024 21:14:28 +0500 Subject: [PATCH 2/7] WIP --- .github/workflows/build.yml | 6 ++++++ .github/workflows/mutation.yml | 5 +++++ tests/.env | 4 ++-- tests/Support/TestTrait.php | 10 +++++----- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59ae210a..6b86ba97 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -95,6 +95,12 @@ jobs: - name: Run tests with phpunit with code coverage. run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always + env: + YII_ORACLE_SID: XE + YII_ORACLE_HOST: localhost + YII_ORACLE_PORT: 1521 + YII_ORACLE_USER: system + YII_ORACLE_PASSWORD: root - name: Upload coverage to Codecov. uses: codecov/codecov-action@v3 diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 40741f4d..01c8e0f6 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -84,3 +84,8 @@ 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 }} + YII_ORACLE_SID: XE + YII_ORACLE_HOST: localhost + YII_ORACLE_PORT: 1521 + YII_ORACLE_USER: system + YII_ORACLE_PASSWORD: root diff --git a/tests/.env b/tests/.env index a355b624..183ab6e2 100644 --- a/tests/.env +++ b/tests/.env @@ -1,6 +1,6 @@ ENVIRONMENT=local -YII_ORACLE_DATABASE= +YII_ORACLE_SID=XE YII_ORACLE_HOST=oracle -YII_ORACLE_PORT= +YII_ORACLE_PORT=1521 YII_ORACLE_USER=system YII_ORACLE_PASSWORD=root diff --git a/tests/Support/TestTrait.php b/tests/Support/TestTrait.php index 702ab79b..0f67cca1 100644 --- a/tests/Support/TestTrait.php +++ b/tests/Support/TestTrait.php @@ -36,7 +36,7 @@ protected static function getDb(): PdoConnectionInterface { $dsn = (new Dsn( host: self::getHost(), - databaseName: self::getDatabaseName(), + databaseName: self::getSid(), port: self::getPort(), options: ['charset' => 'AL32UTF8'], ))->asString(); @@ -49,7 +49,7 @@ protected function getDsn(): string if ($this->dsn === '') { $this->dsn = (new Dsn( host: self::getHost(), - databaseName: self::getDatabaseName(), + databaseName: self::getSid(), port: self::getPort(), options: ['charset' => 'AL32UTF8'], ))->asString(); @@ -73,9 +73,9 @@ private function getDriver(): PdoDriverInterface return new Driver($this->getDsn(), self::getUsername(), self::getPassword()); } - private static function getDatabaseName(): string + private static function getSid(): string { - return getenv('YII_ORACLE_DATABASE') ?: 'XE'; + return getenv('YII_ORACLE_SID'); } private static function getHost(): string @@ -85,7 +85,7 @@ private static function getHost(): string private static function getPort(): string { - return getenv('YII_ORACLE_PORT') ?: '1521'; + return getenv('YII_ORACLE_PORT'); } private static function getUsername(): string From a63ce24bde167e9ecbf86a469e0b8a77579300d4 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Mon, 2 Dec 2024 22:15:29 +0500 Subject: [PATCH 3/7] WIP --- .github/workflows/build.yml | 3 ++- .github/workflows/mutation.yml | 3 ++- tests/CommandTest.php | 12 +----------- tests/Support/TestTrait.php | 15 ++++++++++----- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6b86ba97..e371226f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,7 +53,7 @@ jobs: ports: - 1521:1521 env: - ORACLE_DATABASE : yiitest + ORACLE_DATABASE: FREEPDB1 ORACLE_PASSWORD : root options: >- --name=oci @@ -97,6 +97,7 @@ jobs: run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always env: YII_ORACLE_SID: XE + YII_ORACLE_DATABASE: FREEPDB1 YII_ORACLE_HOST: localhost YII_ORACLE_PORT: 1521 YII_ORACLE_USER: system diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 01c8e0f6..7c203a32 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -42,7 +42,7 @@ jobs: ports: - 1521:1521 env: - ORACLE_DATABASE : yiitest + ORACLE_DATABASE: FREEPDB1 ORACLE_PASSWORD : root options: >- --name=oci @@ -85,6 +85,7 @@ jobs: env: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} YII_ORACLE_SID: XE + YII_ORACLE_DATABASE: FREEPDB1 YII_ORACLE_HOST: localhost YII_ORACLE_PORT: 1521 YII_ORACLE_USER: system diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 89a1374d..53668679 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -13,14 +13,10 @@ use Yiisoft\Db\Exception\InvalidCallException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Oracle\Connection; -use Yiisoft\Db\Oracle\Dsn; -use Yiisoft\Db\Oracle\Driver; use Yiisoft\Db\Oracle\Tests\Support\TestTrait; use Yiisoft\Db\Query\Query; use Yiisoft\Db\Tests\Common\CommonCommandTest; use Yiisoft\Db\Tests\Support\Assert; -use Yiisoft\Db\Tests\Support\DbHelper; use Yiisoft\Db\Transaction\TransactionInterface; use function is_resource; @@ -628,12 +624,6 @@ public function testProfilerData(string $sql = null): void public function testShowDatabases(): void { - $dsn = new Dsn('oci', 'localhost'); - $db = new Connection(new Driver($dsn->asString(), 'SYSTEM', 'root'), DbHelper::getSchemaCache()); - - $command = $db->createCommand(); - - $this->assertSame('oci:dbname=localhost:1521', $db->getDriver()->getDsn()); - $this->assertSame(['YIITEST'], $command->showDatabases()); + $this->assertSame([self::getDatabaseName()], self::getDb()->createCommand()->showDatabases()); } } diff --git a/tests/Support/TestTrait.php b/tests/Support/TestTrait.php index 0f67cca1..139ea5b1 100644 --- a/tests/Support/TestTrait.php +++ b/tests/Support/TestTrait.php @@ -75,26 +75,31 @@ private function getDriver(): PdoDriverInterface private static function getSid(): string { - return getenv('YII_ORACLE_SID'); + return getenv('YII_ORACLE_SID') ?? ''; + } + + private static function getDatabaseName(): string + { + return getenv('YII_ORACLE_DATABASE') ?? ''; } private static function getHost(): string { - return getenv('YII_ORACLE_HOST'); + return getenv('YII_ORACLE_HOST') ?? ''; } private static function getPort(): string { - return getenv('YII_ORACLE_PORT'); + return getenv('YII_ORACLE_PORT') ?? ''; } private static function getUsername(): string { - return getenv('YII_ORACLE_USER'); + return getenv('YII_ORACLE_USER') ?? ''; } private static function getPassword(): string { - return getenv('YII_ORACLE_PASSWORD'); + return getenv('YII_ORACLE_PASSWORD') ?? ''; } } From 09d368dc3a049ac06ec0ccc4b86f1db65adac8ae Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Mon, 2 Dec 2024 22:25:27 +0500 Subject: [PATCH 4/7] WIP --- .github/workflows/build.yml | 1 - .github/workflows/mutation.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e371226f..aa43add1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,7 +53,6 @@ jobs: ports: - 1521:1521 env: - ORACLE_DATABASE: FREEPDB1 ORACLE_PASSWORD : root options: >- --name=oci diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 7c203a32..c5aa27b9 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -42,7 +42,6 @@ jobs: ports: - 1521:1521 env: - ORACLE_DATABASE: FREEPDB1 ORACLE_PASSWORD : root options: >- --name=oci From 2092818cd0125fda410715e16f9bb2156805722f Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Tue, 3 Dec 2024 20:07:45 +0500 Subject: [PATCH 5/7] WIP --- .github/workflows/build.yml | 3 ++- .github/workflows/mutation.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aa43add1..b230747c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,6 +53,7 @@ jobs: ports: - 1521:1521 env: + ORACLE_DATABASE: yiitest ORACLE_PASSWORD : root options: >- --name=oci @@ -96,7 +97,7 @@ jobs: run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always env: YII_ORACLE_SID: XE - YII_ORACLE_DATABASE: FREEPDB1 + YII_ORACLE_DATABASE: yiitest YII_ORACLE_HOST: localhost YII_ORACLE_PORT: 1521 YII_ORACLE_USER: system diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index c5aa27b9..4d5b0501 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -42,6 +42,7 @@ jobs: ports: - 1521:1521 env: + ORACLE_DATABASE: yiitest ORACLE_PASSWORD : root options: >- --name=oci @@ -84,7 +85,7 @@ jobs: env: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} YII_ORACLE_SID: XE - YII_ORACLE_DATABASE: FREEPDB1 + YII_ORACLE_DATABASE: yiitest YII_ORACLE_HOST: localhost YII_ORACLE_PORT: 1521 YII_ORACLE_USER: system From a2baa0672f609c07391d151467e20e095c398573 Mon Sep 17 00:00:00 2001 From: Alexey Rogachev Date: Tue, 3 Dec 2024 20:16:08 +0500 Subject: [PATCH 6/7] WIP --- .github/workflows/build.yml | 4 ++-- .github/workflows/mutation.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b230747c..af31f9c4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,7 +53,7 @@ jobs: ports: - 1521:1521 env: - ORACLE_DATABASE: yiitest + ORACLE_DATABASE: YIITEST ORACLE_PASSWORD : root options: >- --name=oci @@ -97,7 +97,7 @@ jobs: run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always env: YII_ORACLE_SID: XE - YII_ORACLE_DATABASE: yiitest + YII_ORACLE_DATABASE: YIITEST YII_ORACLE_HOST: localhost YII_ORACLE_PORT: 1521 YII_ORACLE_USER: system diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 4d5b0501..f2c0f35c 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -42,7 +42,7 @@ jobs: ports: - 1521:1521 env: - ORACLE_DATABASE: yiitest + ORACLE_DATABASE: YIITEST ORACLE_PASSWORD : root options: >- --name=oci @@ -85,7 +85,7 @@ jobs: env: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} YII_ORACLE_SID: XE - YII_ORACLE_DATABASE: yiitest + YII_ORACLE_DATABASE: YIITEST YII_ORACLE_HOST: localhost YII_ORACLE_PORT: 1521 YII_ORACLE_USER: system From b3683567c49cb6fffd2f7237e9fb595006ea3cab Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 14 Feb 2025 08:55:42 +0000 Subject: [PATCH 7/7] Apply fixes from StyleCI --- tests/CommandTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 95b434fe..d9178cd0 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -15,9 +15,6 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Oracle\Column\ColumnBuilder; -use Yiisoft\Db\Oracle\Connection; -use Yiisoft\Db\Oracle\Dsn; -use Yiisoft\Db\Oracle\Driver; use Yiisoft\Db\Oracle\IndexType; use Yiisoft\Db\Oracle\Tests\Provider\CommandProvider; use Yiisoft\Db\Oracle\Tests\Support\TestTrait;