Skip to content

Commit f9cc163

Browse files
committed
test: add and update tests
1 parent 46a1e5e commit f9cc163

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/system/Models/UpdateModelTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,27 @@ public function testUpdateBatchSuccess(): void
147147
]);
148148
}
149149

150+
public function testUpdateBatchInvalidIndex(): void
151+
{
152+
$this->expectException(InvalidArgumentException::class);
153+
$this->expectExceptionMessage(
154+
'The index ("not_exist") for updateBatch() is missing in the data: {"name":"Derek Jones","country":"Greece"}'
155+
);
156+
157+
$data = [
158+
[
159+
'name' => 'Derek Jones',
160+
'country' => 'Greece',
161+
],
162+
[
163+
'name' => 'Ahmadinejad',
164+
'country' => 'Greece',
165+
],
166+
];
167+
168+
$this->createModel(UserModel::class)->updateBatch($data, 'not_exist');
169+
}
170+
150171
public function testUpdateBatchValidationFail(): void
151172
{
152173
$data = [
@@ -208,11 +229,16 @@ public function testUpdateBatchWithEntity(): void
208229
$entity1->name = 'Jones Martin';
209230
$entity1->country = 'India';
210231
$entity1->deleted = 0;
232+
$entity1->syncOriginal();
233+
// Update the entity.
234+
$entity1->country = 'China';
211235

236+
// This entity is not updated.
212237
$entity2->id = 4;
213238
$entity2->name = 'Jones Martin';
214239
$entity2->country = 'India';
215240
$entity2->deleted = 0;
241+
$entity2->syncOriginal();
216242

217243
$this->assertSame(2, $this->createModel(UserModel::class)->updateBatch([$entity1, $entity2], 'id'));
218244
}

0 commit comments

Comments
 (0)