|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of CodeIgniter 4 framework. |
| 7 | + * |
| 8 | + * (c) CodeIgniter Foundation <admin@codeigniter.com> |
| 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\Live\AbstractGetFieldDataTest; |
| 17 | +use Config\Database; |
| 18 | + |
| 19 | +/** |
| 20 | + * @group DatabaseLive |
| 21 | + * |
| 22 | + * @internal |
| 23 | + */ |
| 24 | +final class GetFieldDataTest extends AbstractGetFieldDataTest |
| 25 | +{ |
| 26 | + protected function createForge(): void |
| 27 | + { |
| 28 | + if ($this->db->DBDriver !== 'OCI8') { |
| 29 | + $this->markTestSkipped('This test is only for OCI8.'); |
| 30 | + } |
| 31 | + |
| 32 | + $this->forge = Database::forge($this->db); |
| 33 | + } |
| 34 | + |
| 35 | + public function testGetFieldData(): void |
| 36 | + { |
| 37 | + $fields = $this->db->getFieldData('test1'); |
| 38 | + |
| 39 | + $data = []; |
| 40 | + |
| 41 | + foreach ($fields as $obj) { |
| 42 | + $data[$obj->name] = $obj; |
| 43 | + } |
| 44 | + |
| 45 | + $idDefault = $data['id']->default; |
| 46 | + $this->assertMatchesRegularExpression('/"ORACLE"."ISEQ\$\$_[0-9]+".nextval/', $idDefault); |
| 47 | + |
| 48 | + $expected = json_decode(json_encode([ |
| 49 | + (object) [ |
| 50 | + 'name' => 'id', |
| 51 | + 'type' => 'NUMBER', |
| 52 | + 'max_length' => '11', |
| 53 | + 'default' => $idDefault, // The default value is not defined. |
| 54 | + // 'primary_key' => 1, |
| 55 | + 'nullable' => false, |
| 56 | + ], |
| 57 | + (object) [ |
| 58 | + 'name' => 'text_not_null', |
| 59 | + 'type' => 'VARCHAR2', |
| 60 | + 'max_length' => '64', |
| 61 | + 'default' => null, // The default value is not defined. |
| 62 | + // 'primary_key' => 0, |
| 63 | + 'nullable' => false, |
| 64 | + ], |
| 65 | + (object) [ |
| 66 | + 'name' => 'text_null', |
| 67 | + 'type' => 'VARCHAR2', |
| 68 | + 'max_length' => '64', |
| 69 | + 'default' => null, // The default value is not defined. |
| 70 | + // 'primary_key' => 0, |
| 71 | + 'nullable' => true, |
| 72 | + ], |
| 73 | + (object) [ |
| 74 | + 'name' => 'int_default_0', |
| 75 | + 'type' => 'NUMBER', |
| 76 | + 'max_length' => '11', |
| 77 | + 'default' => '0 ', // int 0 |
| 78 | + // 'primary_key' => 0, |
| 79 | + 'nullable' => false, |
| 80 | + ], |
| 81 | + (object) [ |
| 82 | + 'name' => 'text_default_null', |
| 83 | + 'type' => 'VARCHAR2', |
| 84 | + 'max_length' => '64', |
| 85 | + 'default' => 'NULL ', // NULL value |
| 86 | + // 'primary_key' => 0, |
| 87 | + 'nullable' => true, |
| 88 | + ], |
| 89 | + (object) [ |
| 90 | + 'name' => 'text_default_text_null', |
| 91 | + 'type' => 'VARCHAR2', |
| 92 | + 'max_length' => '64', |
| 93 | + 'default' => "'null' ", // string "null" |
| 94 | + // 'primary_key' => 0, |
| 95 | + 'nullable' => false, |
| 96 | + ], |
| 97 | + (object) [ |
| 98 | + 'name' => 'text_default_abc', |
| 99 | + 'type' => 'VARCHAR2', |
| 100 | + 'max_length' => '64', |
| 101 | + 'default' => "'abc' ", // string "abc" |
| 102 | + // 'primary_key' => 0, |
| 103 | + 'nullable' => false, |
| 104 | + ], |
| 105 | + ]), true); |
| 106 | + $names = array_column($expected, 'name'); |
| 107 | + array_multisort($names, SORT_ASC, $expected); |
| 108 | + |
| 109 | + $fields = json_decode(json_encode($fields), true); |
| 110 | + $names = array_column($fields, 'name'); |
| 111 | + array_multisort($names, SORT_ASC, $fields); |
| 112 | + |
| 113 | + $this->assertSame($expected, $fields); |
| 114 | + } |
| 115 | +} |
0 commit comments