mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
update tests
This commit is contained in:
parent
1625eaf160
commit
f67babcec0
@ -47,15 +47,14 @@ class Migration_Create_test_tables extends Migration
|
||||
'value' => ['type' => 'VARCHAR', 'constraint' => 400, 'null' => true],
|
||||
])->addKey('id', true)->createTable('misc', true);
|
||||
|
||||
// Team members Table (composite key)
|
||||
$this->forge->addField([
|
||||
'id' => ['type' => 'INTEGER', 'constraint' => 3, 'auto_increment' => true],
|
||||
'city' => ['type' => 'VARCHAR', 'constraint' => 40],
|
||||
'country' => ['type' => 'VARCHAR', 'constraint' => 40],
|
||||
'population' => ['type' => 'INTEGER', 'constraint' => 3, 'unsigned' => true, 'null' => true],
|
||||
'team_id' => ['type' => 'INTEGER', 'constraint' => 3],
|
||||
'person_id' => ['type' => 'INTEGER', 'constraint' => 3],
|
||||
'role' => ['type' => 'VARCHAR', 'constraint' => 40],
|
||||
'status' => ['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(['city', 'country'])->createTable('cities', true);
|
||||
])->addUniqueKey(['team_id', 'person_id'])->createTable('team_members', true);
|
||||
|
||||
// Database Type test table
|
||||
// missing types:
|
||||
|
@ -107,16 +107,18 @@ class CITestSeeder extends Seeder
|
||||
'value' => 'ടൈപ്പ്',
|
||||
],
|
||||
],
|
||||
'cities' => [
|
||||
'team_members' => [
|
||||
[
|
||||
'city' => 'Tokyo',
|
||||
'country' => 'Japan',
|
||||
'population' => 37_115_035,
|
||||
'team_id' => 1,
|
||||
'person_id' => 22,
|
||||
'role' => 'member',
|
||||
'status' => 'active',
|
||||
],
|
||||
[
|
||||
'city' => 'Delhi',
|
||||
'country' => 'India',
|
||||
'population' => 33_807_403,
|
||||
'team_id' => 1,
|
||||
'person_id' => 33,
|
||||
'role' => 'mentor',
|
||||
'status' => 'active',
|
||||
],
|
||||
],
|
||||
'type_test' => [
|
||||
|
@ -44,10 +44,10 @@ final class MetadataTest extends CIUnitTestCase
|
||||
|
||||
$tables = [
|
||||
$prefix . 'migrations',
|
||||
$prefix . 'cities',
|
||||
$prefix . 'user',
|
||||
$prefix . 'job',
|
||||
$prefix . 'misc',
|
||||
$prefix . 'team_members',
|
||||
$prefix . 'type_test',
|
||||
$prefix . 'empty',
|
||||
$prefix . 'secondary',
|
||||
|
@ -614,24 +614,27 @@ final class UpsertTest extends CIUnitTestCase
|
||||
{
|
||||
$data = [
|
||||
[
|
||||
'id' => 1,
|
||||
'city' => 'Tokyo',
|
||||
'country' => 'Japan',
|
||||
'population' => 222,
|
||||
'team_id' => 1,
|
||||
'person_id' => 22,
|
||||
'role' => 'leader',
|
||||
'status' => 'active',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'city' => 'Delhi',
|
||||
'country' => 'India',
|
||||
'population' => 111,
|
||||
'team_id' => 1,
|
||||
'person_id' => 33,
|
||||
'role' => 'member',
|
||||
'status' => 'active',
|
||||
],
|
||||
];
|
||||
|
||||
// uses city_country (city,country) - composite unique index
|
||||
$this->db->table('cities')->upsertBatch($data);
|
||||
// uses (team_id, person_id) - composite unique index
|
||||
$this->db->table('team_members')->upsertBatch($data);
|
||||
|
||||
$this->seeInDatabase('cities', ['id' => 1, 'population' => 222]);
|
||||
$this->seeInDatabase('cities', ['id' => 2, 'population' => 111]);
|
||||
$this->seeInDatabase('team_members', ['team_id' => 1, 'person_id' => 22, 'role' => 'leader']);
|
||||
$this->dontSeeInDatabase('team_members', ['team_id' => 1, 'person_id' => 22, 'role' => 'member']);
|
||||
|
||||
$this->seeInDatabase('team_members', ['team_id' => 1, 'person_id' => 33, 'role' => 'member']);
|
||||
$this->dontSeeInDatabase('team_members', ['team_id' => 1, 'person_id' => 33, 'role' => 'mentor']);
|
||||
}
|
||||
|
||||
public function testSetBatchOneRow(): void
|
||||
|
Loading…
x
Reference in New Issue
Block a user