-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9006 from kenjis/fix-oci8-easy-connect-string-val…
…idation fix: [OCI8] Easy Connect string validation
- Loading branch information
Showing
2 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of CodeIgniter 4 framework. | ||
* | ||
* (c) CodeIgniter Foundation <admin@codeigniter.com> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CodeIgniter\Database\Live\OCI8; | ||
|
||
use CodeIgniter\Database\OCI8\Connection; | ||
use CodeIgniter\Test\CIUnitTestCase; | ||
use Config\Database as DbConfig; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\Attributes\Group; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[Group('DatabaseLive')] | ||
final class ConnectionTest extends CIUnitTestCase | ||
{ | ||
/** | ||
* @var array<string, mixed> Database connection settings | ||
*/ | ||
private array $settings = []; | ||
|
||
protected function setUp(): void | ||
{ | ||
$dbConfig = config(DbConfig::class); | ||
$this->settings = $dbConfig->{$this->DBGroup}; | ||
|
||
if ($this->settings['DBDriver'] !== 'OCI8') { | ||
$this->markTestSkipped('This test is only for OCI8.'); | ||
} | ||
} | ||
|
||
#[DataProvider('provideIsValidDSN')] | ||
public function testIsValidDSN(string $dsn): void | ||
{ | ||
$this->settings['DSN'] = $dsn; | ||
|
||
$db = new Connection($this->settings); | ||
|
||
$isValidDSN = $this->getPrivateMethodInvoker($db, 'isValidDSN'); | ||
|
||
$this->assertTrue($isValidDSN()); | ||
} | ||
|
||
/** | ||
* @return array<string, list<string>> | ||
*/ | ||
public static function provideIsValidDSN(): iterable | ||
{ | ||
yield from [ | ||
// Easy Connect string | ||
// See https://docs.oracle.com/en/database/oracle/oracle-database/23/netag/configuring-naming-methods.html#GUID-36F3A17D-843C-490A-8A23-FB0FE005F8E8 | ||
'HostOnly' => ['sales-server'], | ||
'Host:Port' => ['sales-server:3456'], | ||
'Host/ServiceName' => ['sales-server/sales'], | ||
'IPv6Address:Port/ServiceName' => ['[2001:0db8:0:0::200C:417A]:80/sales'], | ||
'Host:Port/ServiceName' => ['sales-server:80/sales'], | ||
'Host/ServiceName:ServerType/InstanceName' => ['sales-server/sales:dedicated/inst1'], | ||
'Host:InstanceName' => ['sales-server//inst1'], | ||
'Host/ServiceNameWithDots' => ['myhost/my.service.name'], | ||
'Host:Port/ServiceNameWithDots' => ['myhost:1521/my.service.name'], | ||
]; | ||
} | ||
} |