Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional empty checks after field protection for update/insert. #4195

Merged
merged 4 commits into from
Jan 31, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for model insert empty checks.
  • Loading branch information
Alex Schmitz committed Jan 31, 2021
commit a0ec0d7b7d866e9651e2aabcfc41569ec15820ff
41 changes: 40 additions & 1 deletion tests/system/Models/InsertModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function testInsertBatchNewEntityWithDateTime(): void
$this->assertSame(2, $this->model->insertBatch([$entity, $entity]));
}

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

public function testInsertArrayWithNoDataExceptionNoAllowedData(): void
{
$this->expectException(DataException::class);
$this->expectExceptionMessage('There is no data to insert.');
$this->createModel(UserModel::class)->insert(['thisKeyIsNotAllowed' => 'Bar']);
}

public function testInsertEntityWithNoDataExceptionNoAllowedData(): void
{
$this->createModel(UserModel::class);

$entity = new class extends Entity
{
protected $id;
protected $name;
protected $email;
protected $country;
protected $deleted;
protected $created_at;
protected $updated_at;

protected $_options = [
'datamap' => [],
'dates' => [
'created_at',
'updated_at',
'deleted_at',
],
'casts' => [],
];
};

$entity->fill(['thisKeyIsNotAllowed' => 'Bar']);

$this->expectException(DataException::class);
$this->expectExceptionMessage('There is no data to insert.');
$this->model->insert($entity);
}

public function testUseAutoIncrementSetToFalseInsertException(): void
{
$this->expectException(DataException::class);
Expand Down