Skip to content

Commit ebc3c27

Browse files
committed
test: add test for OCI8 getFieldData()
1 parent ffb2027 commit ebc3c27

1 file changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
$this->assertJsonStringEqualsJsonString(
49+
json_encode([
50+
(object) [
51+
'name' => 'id',
52+
'type' => 'NUMBER',
53+
'max_length' => '11',
54+
'default' => $idDefault, // The default value is not defined.
55+
// 'primary_key' => 1,
56+
'nullable' => false,
57+
],
58+
(object) [
59+
'name' => 'text_not_null',
60+
'type' => 'VARCHAR2',
61+
'max_length' => '64',
62+
'default' => null, // The default value is not defined.
63+
// 'primary_key' => 0,
64+
'nullable' => false,
65+
],
66+
(object) [
67+
'name' => 'text_null',
68+
'type' => 'VARCHAR2',
69+
'max_length' => '64',
70+
'default' => null, // The default value is not defined.
71+
// 'primary_key' => 0,
72+
'nullable' => true,
73+
],
74+
(object) [
75+
'name' => 'int_default_0',
76+
'type' => 'NUMBER',
77+
'max_length' => '11',
78+
'default' => '0 ', // int 0
79+
// 'primary_key' => 0,
80+
'nullable' => false,
81+
],
82+
(object) [
83+
'name' => 'text_default_null',
84+
'type' => 'VARCHAR2',
85+
'max_length' => '64',
86+
'default' => 'NULL ', // NULL value
87+
// 'primary_key' => 0,
88+
'nullable' => true,
89+
],
90+
(object) [
91+
'name' => 'text_default_text_null',
92+
'type' => 'VARCHAR2',
93+
'max_length' => '64',
94+
'default' => "'null' ", // string "null"
95+
// 'primary_key' => 0,
96+
'nullable' => false,
97+
],
98+
(object) [
99+
'name' => 'text_default_abc',
100+
'type' => 'VARCHAR2',
101+
'max_length' => '64',
102+
'default' => "'abc' ", // string "abc"
103+
// 'primary_key' => 0,
104+
'nullable' => false,
105+
],
106+
]),
107+
json_encode($fields)
108+
);
109+
}
110+
}

0 commit comments

Comments
 (0)