-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9216 from maniaba/dev.9215
feat: [Validation] add support for `$dbGroup` as parameter in `is_unique` and `is_not_unique`
- Loading branch information
Showing
5 changed files
with
113 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,29 @@ public function testIsUniqueWithDBConnection(): void | |
$this->assertTrue($result); | ||
} | ||
|
||
public function testIsUniqueWithDBConnectionAsParameter(): void | ||
{ | ||
$this->validation->setRules(['email' => 'is_unique[tests.user.email]']); | ||
|
||
$data = ['email' => '[email protected]']; | ||
|
||
$result = $this->validation->run($data); | ||
|
||
$this->assertTrue($result); | ||
} | ||
|
||
public function testIsUniqueWrongParametersThrowInvalidArgumentException(): void | ||
{ | ||
$this->validation->setRules(['email' => 'is_unique[invalid_parameters]']); | ||
|
||
$data = ['email' => '[email protected]']; | ||
|
||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage('The field must be in the format "table.field" or "dbGroup.table.field".'); | ||
|
||
$this->validation->run($data); | ||
} | ||
|
||
public function testIsUniqueWithInvalidDBGroup(): void | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
|
@@ -295,4 +318,31 @@ public function testIsNotUniqueByManualRun(): void | |
|
||
$this->assertTrue($this->createRules()->is_not_unique('[email protected]', 'user.email,id,{id}', [])); | ||
} | ||
|
||
public function testIsNotUniqueWithDBConnectionAsParameter(): void | ||
{ | ||
Database::connect() | ||
->table('user') | ||
->insert([ | ||
'name' => 'Derek Travis', | ||
'email' => '[email protected]', | ||
'country' => 'Elbonia', | ||
]); | ||
|
||
$data = ['email' => '[email protected]']; | ||
$this->validation->setRules(['email' => 'is_not_unique[tests.user.email]']); | ||
$this->assertTrue($this->validation->run($data)); | ||
} | ||
|
||
public function testIsNotUniqueWrongParametersThrowInvalidArgumentException(): void | ||
{ | ||
$this->validation->setRules(['email' => 'is_not_unique[invalid_parameters]']); | ||
|
||
$data = ['email' => '[email protected]']; | ||
|
||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage('The field must be in the format "table.field" or "dbGroup.table.field".'); | ||
|
||
$this->validation->run($data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters