Skip to content

Commit 180eebf

Browse files
committed
Add a test case for InvalidArgumentException and remove the duplicate comment.
1 parent 3cd4397 commit 180eebf

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

system/Validation/StrictRules/Rules.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ public function is_unique($str, string $field, array $data): bool
218218
// Grab any data for exclusion of a single row.
219219
[$field, $ignoreField, $ignoreValue] = array_pad(explode(',', $field), 3, null);
220220

221-
// Break the dbGroup, table and field apart from the field string
222221
// Break the dbGroup, table and field apart from the field string
223222
$parts = explode('.', $field, 3);
224223
$numParts = count($parts);

tests/system/Validation/StrictRules/DatabaseRelatedRulesTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ public function testIsUniqueWithDBConnectionAsParameter(): void
108108
$this->assertTrue($result);
109109
}
110110

111+
public function testIsUniqueWrongParametersThrowInvalidArgumentException(): void
112+
{
113+
$this->validation->setRules(['email' => 'is_unique[invalid_parameters]']);
114+
115+
$data = ['email' => '[email protected]'];
116+
117+
$this->expectException(\InvalidArgumentException::class);
118+
$this->expectExceptionMessage('The field must be in the format "table.field" or "dbGroup.table.field".');
119+
120+
$this->validation->run($data);
121+
}
122+
111123
public function testIsUniqueWithInvalidDBGroup(): void
112124
{
113125
$this->expectException(InvalidArgumentException::class);
@@ -322,4 +334,16 @@ public function testIsNotUniqueWithDBConnectionAsParameter(): void
322334
$this->validation->setRules(['email' => 'is_not_unique[tests.user.email]']);
323335
$this->assertTrue($this->validation->run($data));
324336
}
337+
338+
public function testIsNotUniqueWrongParametersThrowInvalidArgumentException(): void
339+
{
340+
$this->validation->setRules(['email' => 'is_not_unique[invalid_parameters]']);
341+
342+
$data = ['email' => '[email protected]'];
343+
344+
$this->expectException(\InvalidArgumentException::class);
345+
$this->expectExceptionMessage('The field must be in the format "table.field" or "dbGroup.table.field".');
346+
347+
$this->validation->run($data);
348+
}
325349
}

0 commit comments

Comments
 (0)