diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59ae210..af31f9c 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 @@ -95,6 +95,13 @@ 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_DATABASE: YIITEST + 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 40741f4..f2c0f35 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 @@ -84,3 +84,9 @@ 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_DATABASE: YIITEST + YII_ORACLE_HOST: localhost + YII_ORACLE_PORT: 1521 + YII_ORACLE_USER: system + YII_ORACLE_PASSWORD: root diff --git a/composer.json b/composer.json index a9b1224..9fd143d 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 0000000..183ab6e --- /dev/null +++ b/tests/.env @@ -0,0 +1,6 @@ +ENVIRONMENT=local +YII_ORACLE_SID=XE +YII_ORACLE_HOST=oracle +YII_ORACLE_PORT=1521 +YII_ORACLE_USER=system +YII_ORACLE_PASSWORD=root diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 89a1374..5366867 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 8d5c73d..139ea5b 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::getSid(), + 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::getSid(), + port: self::getPort(), + options: ['charset' => 'AL32UTF8'], + ))->asString(); } return $this->dsn; @@ -56,4 +67,39 @@ 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 getSid(): string + { + 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') ?? ''; + } + + private static function getPort(): string + { + return getenv('YII_ORACLE_PORT') ?? ''; + } + + 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 0000000..0b8567e --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,8 @@ +load(); +}