|
| 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\OCI8; |
| 15 | + |
| 16 | +use CodeIgniter\Test\CIUnitTestCase; |
| 17 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 18 | +use PHPUnit\Framework\Attributes\Group; |
| 19 | + |
| 20 | +/** |
| 21 | + * @internal |
| 22 | + */ |
| 23 | +#[Group('Others')] |
| 24 | +final class ConnectionTest extends CIUnitTestCase |
| 25 | +{ |
| 26 | + private array $options = [ |
| 27 | + 'DSN' => 'localhost:1521/XEPDB1', |
| 28 | + 'hostname' => '', |
| 29 | + 'username' => 'ORACLE', |
| 30 | + 'password' => 'ORACLE', |
| 31 | + 'database' => '', |
| 32 | + 'DBDriver' => 'OCI8', |
| 33 | + 'DBPrefix' => 'db_', |
| 34 | + 'pConnect' => false, |
| 35 | + 'DBDebug' => true, |
| 36 | + 'charset' => 'AL32UTF8', |
| 37 | + 'DBCollat' => '', |
| 38 | + 'swapPre' => '', |
| 39 | + 'encrypt' => false, |
| 40 | + 'compress' => false, |
| 41 | + 'strictOn' => false, |
| 42 | + 'failover' => [], |
| 43 | + ]; |
| 44 | + |
| 45 | + #[DataProvider('provideIsValidDSN')] |
| 46 | + public function testIsValidDSN(string $dsn): void |
| 47 | + { |
| 48 | + $this->options['DSN'] = $dsn; |
| 49 | + $db = new Connection($this->options); |
| 50 | + |
| 51 | + $isValidDSN = $this->getPrivateMethodInvoker($db, 'isValidDSN'); |
| 52 | + |
| 53 | + $this->assertTrue($isValidDSN()); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @return list<string> |
| 58 | + */ |
| 59 | + public static function provideIsValidDSN(): iterable |
| 60 | + { |
| 61 | + yield from [ |
| 62 | + // Easy Connect string |
| 63 | + // See https://docs.oracle.com/en/database/oracle/oracle-database/23/netag/configuring-naming-methods.html#GUID-36F3A17D-843C-490A-8A23-FB0FE005F8E8 |
| 64 | + 'HostOnly' => ['sales-server'], |
| 65 | + 'Host:Port' => ['sales-server:3456'], |
| 66 | + 'Host/ServiceName' => ['sales-server/sales'], |
| 67 | + 'IPv6Address:Port/ServiceName' => ['[2001:0db8:0:0::200C:417A]:80/sales'], |
| 68 | + 'Host:Port/ServiceName' => ['sales-server:80/sales'], |
| 69 | + 'Host/ServiceName:ServerType/InstanceName' => ['sales-server/sales:dedicated/inst1'], |
| 70 | + 'Host:InstanceName' => ['sales-server//inst1'], |
| 71 | + 'Host/ServiceNameWithDots' => ['myhost/my.service.name'], |
| 72 | + 'Host:Port/ServiceNameWithDots' => ['myhost:1521/my.service.name'], |
| 73 | + ]; |
| 74 | + } |
| 75 | +} |
0 commit comments