-
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.
feat: Add optional dbGroup support in validation rules for multiple d…
…atabase connections cs fixer docs format fix rules add test testIsNotUniqueWithDBConnectionAsParameter docs: update v4.5.6.rst docs: fix tabs docs update for v4.6.0 Update validation.rst Update user_guide_src/source/changelogs/v4.6.0.rst Co-authored-by: Michal Sniatala <[email protected]> Add a test case for `InvalidArgumentException` and remove the duplicate comment. refactor: code for is_unique and is_not_unique methods; extracted common code into prepareUniqueQuery method rector and phpstan fix
- Loading branch information
1 parent
9fba8c7
commit 86278d9
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