Repository navigation
Expand file tree
/
Copy pathGetIndexDataTest.php
More file actions
99 lines (81 loc) · 3.52 KB
/
Copy pathGetIndexDataTest.php
File metadata and controls
99 lines (81 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Database\Live\SQLite3;
use CodeIgniter\Database\SQLite3\Forge;
use CodeIgniter\Test\CIUnitTestCase;
use Config\Database;
use PHPUnit\Framework\Attributes\Group;
use stdClass;
/**
* @internal
*/
#[Group('DatabaseLive')]
final class GetIndexDataTest extends CIUnitTestCase
{
private Forge $forge;
protected function setUp(): void
{
parent::setUp();
$this->db = Database::connect($this->DBGroup);
if ($this->db->DBDriver !== 'SQLite3') {
$this->markTestSkipped('This test is only for SQLite3.');
}
$config = [
'DBDriver' => 'SQLite3',
'database' => 'database.db',
'DBDebug' => true,
];
$this->db = db_connect($config, false);
$this->forge = Database::forge($config);
}
public function testGetIndexData(): void
{
// INTEGER PRIMARY KEY AUTO_INCREMENT doesn't get an index by default
$this->forge->addField([
'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true],
'userid' => ['type' => 'INTEGER', 'constraint' => 3],
'name' => ['type' => 'VARCHAR', 'constraint' => 80],
'email' => ['type' => 'VARCHAR', 'constraint' => 100],
'country' => ['type' => 'VARCHAR', 'constraint' => 40],
'created_at' => ['type' => 'DATETIME', 'null' => true],
'updated_at' => ['type' => 'DATETIME', 'null' => true],
'deleted_at' => ['type' => 'DATETIME', 'null' => true],
])
->addKey(['id'], true)
->addUniqueKey('email')
->addKey('country')
->createTable('testuser', true);
$expectedIndexes = [];
$row = new stdClass();
$row->name = 'PRIMARY';
$row->fields = ['id'];
$row->type = 'PRIMARY';
$expectedIndexes['PRIMARY'] = $row;
$row = new stdClass();
$row->name = 'testuser_email';
$row->fields = ['email'];
$row->type = 'UNIQUE';
$expectedIndexes['testuser_email'] = $row;
$row = new stdClass();
$row->name = 'testuser_country';
$row->fields = ['country'];
$row->type = 'INDEX';
$expectedIndexes['testuser_country'] = $row;
$indexes = $this->db->getIndexData('testuser');
$this->assertSame($expectedIndexes['PRIMARY']->fields, $indexes['PRIMARY']->fields);
$this->assertSame($expectedIndexes['PRIMARY']->type, $indexes['PRIMARY']->type);
$this->assertSame($expectedIndexes['testuser_email']->fields, $indexes['testuser_email']->fields);
$this->assertSame($expectedIndexes['testuser_email']->type, $indexes['testuser_email']->type);
$this->assertSame($expectedIndexes['testuser_country']->fields, $indexes['testuser_country']->fields);
$this->assertSame($expectedIndexes['testuser_country']->type, $indexes['testuser_country']->type);
$this->forge->dropTable('testuser', true);
}
}