|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of CodeIgniter 4 framework. |
| 7 | + * |
| 8 | + * (c) CodeIgniter Foundation <[email protected]> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view |
| 11 | + * the LICENSE file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace CodeIgniter\Database\Live\OCI8; |
| 15 | + |
| 16 | +use CodeIgniter\Database\OCI8\Connection; |
| 17 | +use CodeIgniter\Test\CIUnitTestCase; |
| 18 | +use Config\Database as DbConfig; |
| 19 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 20 | +use PHPUnit\Framework\Attributes\Group; |
| 21 | + |
| 22 | +/** |
| 23 | + * @internal |
| 24 | + */ |
| 25 | +#[Group('DatabaseLive')] |
| 26 | +final class ConnectionTest extends CIUnitTestCase |
| 27 | +{ |
| 28 | + /** |
| 29 | + * @var array<string, mixed> Database connection settings |
| 30 | + */ |
| 31 | + private array $settings = []; |
| 32 | + |
| 33 | + protected function setUp(): void |
| 34 | + { |
| 35 | + $dbConfig = config(DbConfig::class); |
| 36 | + $this->settings = $dbConfig->{$this->DBGroup}; |
| 37 | + |
| 38 | + if ($this->settings['DBDriver'] !== 'OCI8') { |
| 39 | + $this->markTestSkipped('This test is only for OCI8.'); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + #[DataProvider('provideIsValidDSN')] |
| 44 | + public function testIsValidDSN(string $dsn): void |
| 45 | + { |
| 46 | + $this->settings['DSN'] = $dsn; |
| 47 | + |
| 48 | + $db = new Connection($this->settings); |
| 49 | + |
| 50 | + $isValidDSN = $this->getPrivateMethodInvoker($db, 'isValidDSN'); |
| 51 | + |
| 52 | + $this->assertTrue($isValidDSN()); |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * @return array<string, list<string>> |
| 57 | + */ |
| 58 | + public static function provideIsValidDSN(): iterable |
| 59 | + { |
| 60 | + yield from [ |
| 61 | + // Easy Connect string |
| 62 | + // See https://docs.oracle.com/en/database/oracle/oracle-database/23/netag/configuring-naming-methods.html#GUID-36F3A17D-843C-490A-8A23-FB0FE005F8E8 |
| 63 | + 'HostOnly' => ['sales-server'], |
| 64 | + 'Host:Port' => ['sales-server:3456'], |
| 65 | + 'Host/ServiceName' => ['sales-server/sales'], |
| 66 | + 'IPv6Address:Port/ServiceName' => ['[2001:0db8:0:0::200C:417A]:80/sales'], |
| 67 | + 'Host:Port/ServiceName' => ['sales-server:80/sales'], |
| 68 | + 'Host/ServiceName:ServerType/InstanceName' => ['sales-server/sales:dedicated/inst1'], |
| 69 | + 'Host:InstanceName' => ['sales-server//inst1'], |
| 70 | + 'Host/ServiceNameWithDots' => ['myhost/my.service.name'], |
| 71 | + 'Host:Port/ServiceNameWithDots' => ['myhost:1521/my.service.name'], |
| 72 | + ]; |
| 73 | + } |
| 74 | +} |
0 commit comments