Skip to content

Commit 22d8e74

Browse files
committed
test: add test for getFieldData() for SQLSRV
1 parent 3d8b04b commit 22d8e74

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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\SQLSRV;
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 !== 'SQLSRV') {
29+
$this->markTestSkipped('This test is only for SQLSRV.');
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+
$this->assertJsonStringEqualsJsonString(
40+
json_encode([
41+
(object) [
42+
'name' => 'id',
43+
'type' => 'int',
44+
'max_length' => 10,
45+
'default' => null, // The default value is not defined.
46+
// 'primary_key' => 1,
47+
'nullable' => false,
48+
],
49+
(object) [
50+
'name' => 'text_not_null',
51+
'type' => 'varchar',
52+
'max_length' => 64,
53+
'default' => null, // The default value is not defined.
54+
// 'primary_key' => 0,
55+
'nullable' => false,
56+
],
57+
(object) [
58+
'name' => 'text_null',
59+
'type' => 'varchar',
60+
'max_length' => 64,
61+
'default' => null, // The default value is not defined.
62+
// 'primary_key' => 0,
63+
'nullable' => true,
64+
],
65+
(object) [
66+
'name' => 'int_default_0',
67+
'type' => 'int',
68+
'max_length' => 10,
69+
'default' => '((0))', // int 0
70+
// 'primary_key' => 0,
71+
'nullable' => false,
72+
],
73+
(object) [
74+
'name' => 'text_default_null',
75+
'type' => 'varchar',
76+
'max_length' => 64,
77+
'default' => '(NULL)', // NULL value
78+
// 'primary_key' => 0,
79+
'nullable' => true,
80+
],
81+
(object) [
82+
'name' => 'text_default_text_null',
83+
'type' => 'varchar',
84+
'max_length' => 64,
85+
'default' => "('null')", // string "null"
86+
// 'primary_key' => 0,
87+
'nullable' => false,
88+
],
89+
(object) [
90+
'name' => 'text_default_abc',
91+
'type' => 'varchar',
92+
'max_length' => 64,
93+
'default' => "('abc')", // string "abc"
94+
// 'primary_key' => 0,
95+
'nullable' => false,
96+
],
97+
]),
98+
json_encode($fields)
99+
);
100+
}
101+
}

0 commit comments

Comments
 (0)