Skip to content

Commit 331818e

Browse files
authored
Merge pull request #6846 from kenjis/fix-DeleteModelTest
test: fix DeleteModelTest
2 parents c9bd7ce + 83b9f4a commit 331818e

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

system/Database/BaseBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,7 @@ protected function _update(string $table, array $values): string
21112111
/**
21122112
* This method is used by both update() and getCompiledUpdate() to
21132113
* validate that data is actually being set and that a table has been
2114-
* chosen to be update.
2114+
* chosen to be updated.
21152115
*
21162116
* @throws DatabaseException
21172117
*/

tests/system/Models/DeleteModelTest.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,13 @@ public function testOnlyDeleted(): void
148148
}
149149

150150
/**
151-
* If where condition is set, beyond the value was empty (0,'', NULL, etc.),
152-
* Exception should not be thrown because condition was explicity set
151+
* Given an explicit empty value in the WHERE condition
152+
* When executing a soft delete
153+
* Then an exception should not be thrown
153154
*
154155
* @dataProvider emptyPkValues
155156
*
156-
* @param mixed $emptyValue
157+
* @param int|string|null $emptyValue
157158
*/
158159
public function testDontThrowExceptionWhenSoftDeleteConditionIsSetWithEmptyValue($emptyValue): void
159160
{
@@ -167,30 +168,33 @@ public function testDontThrowExceptionWhenSoftDeleteConditionIsSetWithEmptyValue
167168
/**
168169
* @dataProvider emptyPkValues
169170
*
170-
* @param mixed $emptyValue
171+
* @param int|string|null $emptyValue
171172
*/
172173
public function testThrowExceptionWhenSoftDeleteParamIsEmptyValue($emptyValue): void
173174
{
174175
$this->expectException(DatabaseException::class);
175176
$this->expectExceptionMessage('Deletes are not allowed unless they contain a "where" or "like" clause.');
176177

177178
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL' => null]);
179+
178180
$this->createModel(UserModel::class)->delete($emptyValue);
179181
}
180182

181183
/**
182184
* @dataProvider emptyPkValues
183185
*
184-
* @param mixed $emptyValue
186+
* @param int|string|null $emptyValue
185187
*/
186188
public function testDontDeleteRowsWhenSoftDeleteParamIsEmpty($emptyValue): void
187189
{
188-
$this->expectException(DatabaseException::class);
189-
$this->expectExceptionMessage('Deletes are not allowed unless they contain a "where" or "like" clause.');
190-
191190
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL' => null]);
192191

193-
$this->createModel(UserModel::class)->delete($emptyValue);
192+
try {
193+
$this->createModel(UserModel::class)->delete($emptyValue);
194+
} catch (DatabaseException $e) {
195+
// Do nothing.
196+
}
197+
194198
$this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL' => null]);
195199
}
196200

0 commit comments

Comments
 (0)