Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ease local testing #287

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
ports:
- 1521:1521
env:
ORACLE_DATABASE : yiitest
ORACLE_DATABASE: YIITEST
ORACLE_PASSWORD : root
options: >-
--name=oci
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
ports:
- 1521:1521
env:
ORACLE_DATABASE : yiitest
ORACLE_DATABASE: YIITEST
ORACLE_PASSWORD : root
options: >-
--name=oci
Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions tests/.env
Original file line number Diff line number Diff line change
@@ -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
12 changes: 1 addition & 11 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
56 changes: 51 additions & 5 deletions tests/Support/TestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,15 +15,15 @@

trait TestTrait
{
private string $dsn = 'oci:dbname=localhost/XE;';
private string $dsn = '';

/**
* @throws InvalidConfigException
* @throws Exception
*/
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');
Expand All @@ -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;
Expand All @@ -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') ?? '';
}
}
8 changes: 8 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

if (getenv('ENVIRONMENT', local_only: true) === 'local') {
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__);
$dotenv->load();
}
Loading