Skip to content

Commit 66395c5

Browse files
committed
test: add tests for Model::detete() with no WHERE clause
1 parent 14b045b commit 66395c5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/system/Models/DeleteModelTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,42 @@ public function testPurgeDeletedWithSoftDeleteFalse(): void
239239
$jobs = $this->model->findAll();
240240
$this->assertCount(4, $jobs);
241241
}
242+
243+
/**
244+
* @dataProvider emptyPkValues
245+
*
246+
* @param int|string|null $id
247+
*/
248+
public function testDeleteThrowDatabaseExceptionWithoutWhereClause($id): void
249+
{
250+
// BaseBuilder throws Exception.
251+
$this->expectException(DatabaseException::class);
252+
$this->expectExceptionMessage(
253+
'Deletes are not allowed unless they contain a "where" or "like" clause.'
254+
);
255+
256+
// $useSoftDeletes = false
257+
$this->createModel(JobModel::class);
258+
259+
$this->model->delete($id);
260+
}
261+
262+
/**
263+
* @dataProvider emptyPkValues
264+
*
265+
* @param int|string|null $id
266+
*/
267+
public function testDeleteWithSoftDeleteThrowDatabaseExceptionWithoutWhereClause($id): void
268+
{
269+
// Model throws Exception.
270+
$this->expectException(DatabaseException::class);
271+
$this->expectExceptionMessage(
272+
'Deletes are not allowed unless they contain a "where" or "like" clause.'
273+
);
274+
275+
// $useSoftDeletes = true
276+
$this->createModel(UserModel::class);
277+
278+
$this->model->delete($id);
279+
}
242280
}

0 commit comments

Comments
 (0)