Skip to content

Commit ebf8fab

Browse files
committed
test: extract AbstractGetFieldDataTest class
1 parent 74f2b81 commit ebf8fab

File tree

2 files changed

+8
-111
lines changed

2 files changed

+8
-111
lines changed

tests/system/Database/Live/MySQLi/GetFieldDataTest.php

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* This file is part of CodeIgniter 4 framework.
57
*
@@ -11,34 +13,18 @@
1113

1214
namespace CodeIgniter\Database\Live\MySQLi;
1315

14-
use CodeIgniter\Database\MySQLi\Connection;
15-
use CodeIgniter\Database\MySQLi\Forge;
16-
use CodeIgniter\Test\CIUnitTestCase;
17-
use CodeIgniter\Test\DatabaseTestTrait;
16+
use CodeIgniter\Database\Live\AbstractGetFieldDataTest;
1817
use Config\Database;
1918

2019
/**
2120
* @group DatabaseLive
2221
*
2322
* @internal
2423
*/
25-
final class GetFieldDataTest extends CIUnitTestCase
24+
final class GetFieldDataTest extends AbstractGetFieldDataTest
2625
{
27-
use DatabaseTestTrait;
28-
29-
protected $migrate = false;
30-
31-
/**
32-
* @var Connection
33-
*/
34-
protected $db;
35-
36-
private Forge $forge;
37-
38-
protected function setUp(): void
26+
protected function createForge(): void
3927
{
40-
parent::setUp();
41-
4228
if ($this->db->DBDriver !== 'MySQLi') {
4329
$this->markTestSkipped('This test is only for MySQLi.');
4430
}
@@ -48,45 +34,6 @@ protected function setUp(): void
4834

4935
public function testGetFieldData(): void
5036
{
51-
$this->forge->dropTable('test1', true);
52-
53-
$this->forge->addField([
54-
'id' => [
55-
'type' => 'INT',
56-
'auto_increment' => true,
57-
],
58-
'text_not_null' => [
59-
'type' => 'VARCHAR',
60-
'constraint' => 64,
61-
],
62-
'text_null' => [
63-
'type' => 'VARCHAR',
64-
'constraint' => 64,
65-
'null' => true,
66-
],
67-
'int_default_0' => [
68-
'type' => 'INT',
69-
'default' => 0,
70-
],
71-
'text_default_null' => [
72-
'type' => 'VARCHAR',
73-
'constraint' => 64,
74-
'default' => null,
75-
],
76-
'text_default_text_null' => [
77-
'type' => 'VARCHAR',
78-
'constraint' => 64,
79-
'default' => 'null',
80-
],
81-
'text_default_abc' => [
82-
'type' => 'VARCHAR',
83-
'constraint' => 64,
84-
'default' => 'abc',
85-
],
86-
]);
87-
$this->forge->addKey('id', true);
88-
$this->forge->createTable('test1');
89-
9037
$fields = $this->db->getFieldData('test1');
9138

9239
$this->assertJsonStringEqualsJsonString(
@@ -150,7 +97,5 @@ public function testGetFieldData(): void
15097
]),
15198
json_encode($fields)
15299
);
153-
154-
$this->forge->dropTable('test1', true);
155100
}
156101
}

tests/system/Database/Live/SQLite3/GetFieldDataTest.php

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,18 @@
1111

1212
namespace CodeIgniter\Database\Live\SQLite3;
1313

14-
use CodeIgniter\Database\SQLite3\Connection;
15-
use CodeIgniter\Database\SQLite3\Forge;
16-
use CodeIgniter\Test\CIUnitTestCase;
14+
use CodeIgniter\Database\Live\AbstractGetFieldDataTest;
1715
use Config\Database;
1816

1917
/**
2018
* @group DatabaseLive
2119
*
2220
* @internal
2321
*/
24-
final class GetFieldDataTest extends CIUnitTestCase
22+
final class GetFieldDataTest extends AbstractGetFieldDataTest
2523
{
26-
/**
27-
* @var Connection
28-
*/
29-
protected $db;
30-
31-
private Forge $forge;
32-
33-
protected function setUp(): void
24+
protected function createForge(): void
3425
{
35-
parent::setUp();
36-
37-
$this->db = Database::connect($this->DBGroup);
3826
if ($this->db->DBDriver !== 'SQLite3') {
3927
$this->markTestSkipped('This test is only for SQLite3.');
4028
}
@@ -50,40 +38,6 @@ protected function setUp(): void
5038

5139
public function testGetFieldData(): void
5240
{
53-
$this->forge->dropTable('test1', true);
54-
55-
$this->forge->addField([
56-
'id' => [
57-
'type' => 'INT',
58-
'auto_increment' => true,
59-
],
60-
'text_not_null' => [
61-
'type' => 'VARCHAR',
62-
],
63-
'text_null' => [
64-
'type' => 'VARCHAR',
65-
'null' => true,
66-
],
67-
'int_default_0' => [
68-
'type' => 'INT',
69-
'default' => 0,
70-
],
71-
'text_default_null' => [
72-
'type' => 'VARCHAR',
73-
'default' => null,
74-
],
75-
'text_default_text_null' => [
76-
'type' => 'VARCHAR',
77-
'default' => 'null',
78-
],
79-
'text_default_abc' => [
80-
'type' => 'VARCHAR',
81-
'default' => 'abc',
82-
],
83-
]);
84-
$this->forge->addKey('id', true);
85-
$this->forge->createTable('test1');
86-
8741
$fields = $this->db->getFieldData('test1');
8842

8943
$this->assertJsonStringEqualsJsonString(
@@ -147,7 +101,5 @@ public function testGetFieldData(): void
147101
]),
148102
json_encode($fields)
149103
);
150-
151-
$this->forge->dropTable('test1', true);
152104
}
153105
}

0 commit comments

Comments
 (0)