Compare commits

...

2 Commits

Author SHA1 Message Date
Michal Sniatala
1ed71795f6
Merge f67babcec0480b778aba5065366f5ee29002c508 into a348792bf28207ce29acfb88f6dd0e48bc01a447 2025-02-19 07:32:11 +00:00
michalsn
f67babcec0
update tests 2025-02-19 08:32:03 +01:00
4 changed files with 31 additions and 27 deletions

View File

@ -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:

View File

@ -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' => [

View File

@ -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',

View File

@ -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