Skip to content

Commit

Permalink
Merge pull request #8449 from kenjis/test-sqlsrv-getFieldData
Browse files Browse the repository at this point in the history
test: add test for SQLSRV getFieldData()
  • Loading branch information
kenjis authored Jan 25, 2024
2 parents 47f71fa + 22d8e74 commit 94b3701
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions tests/system/Database/Live/SQLSRV/GetFieldDataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace CodeIgniter\Database\Live\SQLSRV;

use CodeIgniter\Database\Live\AbstractGetFieldDataTest;
use Config\Database;

/**
* @group DatabaseLive
*
* @internal
*/
final class GetFieldDataTest extends AbstractGetFieldDataTest
{
protected function createForge(): void
{
if ($this->db->DBDriver !== 'SQLSRV') {
$this->markTestSkipped('This test is only for SQLSRV.');
}

$this->forge = Database::forge($this->db);
}

public function testGetFieldData(): void
{
$fields = $this->db->getFieldData('test1');

$this->assertJsonStringEqualsJsonString(
json_encode([
(object) [
'name' => 'id',
'type' => 'int',
'max_length' => 10,
'default' => null, // The default value is not defined.
// 'primary_key' => 1,
'nullable' => false,
],
(object) [
'name' => 'text_not_null',
'type' => 'varchar',
'max_length' => 64,
'default' => null, // The default value is not defined.
// 'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_null',
'type' => 'varchar',
'max_length' => 64,
'default' => null, // The default value is not defined.
// 'primary_key' => 0,
'nullable' => true,
],
(object) [
'name' => 'int_default_0',
'type' => 'int',
'max_length' => 10,
'default' => '((0))', // int 0
// 'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_default_null',
'type' => 'varchar',
'max_length' => 64,
'default' => '(NULL)', // NULL value
// 'primary_key' => 0,
'nullable' => true,
],
(object) [
'name' => 'text_default_text_null',
'type' => 'varchar',
'max_length' => 64,
'default' => "('null')", // string "null"
// 'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_default_abc',
'type' => 'varchar',
'max_length' => 64,
'default' => "('abc')", // string "abc"
// 'primary_key' => 0,
'nullable' => false,
],
]),
json_encode($fields)
);
}
}

0 comments on commit 94b3701

Please sign in to comment.