Skip to content

Commit 6b659e8

Browse files
committed
Changed assertion to seeInDatabase function in testUpdateBatchWithCasts
1 parent efde523 commit 6b659e8

File tree

1 file changed

+13
-56
lines changed

1 file changed

+13
-56
lines changed

tests/system/Models/UpdateModelTest.php

Lines changed: 13 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -608,81 +608,38 @@ public function testUpdateBatchWithCasts(): void
608608
{
609609
$this->createModel(UserCastsTimestampModel::class);
610610

611-
// Step 1: Insert initial users
612-
$initialData = [
613-
[
614-
'name' => 'Smriti',
615-
'email' => [
616-
'personal' => '[email protected]',
617-
'work' => '[email protected]',
618-
],
619-
'country' => 'India',
620-
],
621-
[
622-
'name' => 'Rahul',
623-
'email' => [
624-
'personal' => '[email protected]',
625-
'work' => '[email protected]',
626-
],
627-
'country' => 'India',
628-
],
629-
];
630-
631-
$this->model->insertBatch($initialData);
632-
633-
$rows = $this->model->where('country', 'India')->findAll();
611+
$rows = $this->db->table('user')->limit(2)->orderBy('id', 'asc')->get()->getResultArray();
634612

635613
$this->assertNotEmpty($rows);
636614
$this->assertCount(2, $rows);
637615

638-
$smriti = $rows[0];
639-
$rahul = $rows[1];
616+
$row1 = $rows[0];
617+
$row2 = $rows[1];
640618

641-
$this->assertNotNull($smriti);
642-
$this->assertNotNull($rahul);
619+
$this->assertNotNull($row1);
620+
$this->assertNotNull($row2);
643621

644-
// Step 3: Prepare update data (must include 'id' key)
645622
$updateData = [
646623
[
647-
'id' => $smriti['id'],
648-
'name' => 'Smriti Updated',
624+
'id' => $row1['id'],
649625
'email' => [
650-
'personal' => 'smriti.new@india.com',
651-
'work' => 'smriti[email protected]',
626+
'personal' => 'email1.new@country.com',
627+
'work' => 'email1[email protected]',
652628
],
653629
],
654630
[
655-
'id' => $rahul['id'],
656-
'name' => 'Rahul Updated',
631+
'id' => $row2['id'],
657632
'email' => [
658-
'personal' => 'rahul.new@india.com',
659-
'work' => 'rahul[email protected]',
633+
'personal' => 'email2.new@country.com',
634+
'work' => 'email2[email protected]',
660635
],
661636
],
662637
];
663638

664-
// Step 4: Perform batch update
665639
$numRows = $this->model->updateBatch($updateData, 'id');
666640
$this->assertSame(2, $numRows);
667641

668-
$rows = $this->model->where('country', 'India')->findAll();
669-
670-
$this->assertNotEmpty($rows);
671-
$this->assertCount(2, $rows);
672-
673-
$smritiUpdated = $rows[0];
674-
$rahulUpdated = $rows[1];
675-
676-
// Smriti assertions
677-
$this->assertSame('Smriti Updated', $smritiUpdated['name']);
678-
$this->assertIsArray($smritiUpdated['email']);
679-
$this->assertSame('[email protected]', $smritiUpdated['email']['personal']);
680-
$this->assertSame('[email protected]', $smritiUpdated['email']['work']);
681-
682-
// Rahul assertions
683-
$this->assertSame('Rahul Updated', $rahulUpdated['name']);
684-
$this->assertIsArray($rahulUpdated['email']);
685-
$this->assertSame('[email protected]', $rahulUpdated['email']['personal']);
686-
$this->assertSame('[email protected]', $rahulUpdated['email']['work']);
642+
$this->seeInDatabase('user', ['email' => json_encode($updateData[0]['email'])]);
643+
$this->seeInDatabase('user', ['email' => json_encode($updateData[1]['email'])]);
687644
}
688645
}

0 commit comments

Comments
 (0)