Skip to content

Commit a0ec0d7

Browse files
author
Alex Schmitz
committed
Add tests for model insert empty checks.
1 parent b768a0e commit a0ec0d7

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

tests/system/Models/InsertModelTest.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function testInsertBatchNewEntityWithDateTime(): void
178178
$this->assertSame(2, $this->model->insertBatch([$entity, $entity]));
179179
}
180180

181-
public function testInsertArrayWithDataException(): void
181+
public function testInsertArrayWithNoDataException(): void
182182
{
183183
$this->expectException(DataException::class);
184184
$this->expectExceptionMessage('There is no data to insert.');
@@ -193,6 +193,45 @@ public function testInsertObjectWithNoDataException(): void
193193
$this->createModel(UserModel::class)->insert($data);
194194
}
195195

196+
public function testInsertArrayWithNoDataExceptionNoAllowedData(): void
197+
{
198+
$this->expectException(DataException::class);
199+
$this->expectExceptionMessage('There is no data to insert.');
200+
$this->createModel(UserModel::class)->insert(['thisKeyIsNotAllowed' => 'Bar']);
201+
}
202+
203+
public function testInsertEntityWithNoDataExceptionNoAllowedData(): void
204+
{
205+
$this->createModel(UserModel::class);
206+
207+
$entity = new class extends Entity
208+
{
209+
protected $id;
210+
protected $name;
211+
protected $email;
212+
protected $country;
213+
protected $deleted;
214+
protected $created_at;
215+
protected $updated_at;
216+
217+
protected $_options = [
218+
'datamap' => [],
219+
'dates' => [
220+
'created_at',
221+
'updated_at',
222+
'deleted_at',
223+
],
224+
'casts' => [],
225+
];
226+
};
227+
228+
$entity->fill(['thisKeyIsNotAllowed' => 'Bar']);
229+
230+
$this->expectException(DataException::class);
231+
$this->expectExceptionMessage('There is no data to insert.');
232+
$this->model->insert($entity);
233+
}
234+
196235
public function testUseAutoIncrementSetToFalseInsertException(): void
197236
{
198237
$this->expectException(DataException::class);

0 commit comments

Comments
 (0)