-
-
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.
Use regex lazy quantifier to match first occurrence in combined valid…
…ation rules (#4049) * use regex lazy quantifier to match first occurrence in combined validation rules * added test for lazy quantifier fix in RowValidator
- Loading branch information
Showing
2 changed files
with
51 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -294,6 +294,56 @@ public function rules(): array | |
$this->assertInstanceOf(ValidationException::class, $e ?? null); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function can_validate_rows_with_combined_rules_with_colons() | ||
{ | ||
$import = new class implements ToModel, WithValidation | ||
{ | ||
use Importable; | ||
|
||
/** | ||
* @param array $row | ||
* @return Model|null | ||
*/ | ||
public function model(array $row) | ||
{ | ||
return new User([ | ||
'name' => $row[0], | ||
'email' => $row[1], | ||
'password' => 'secret', | ||
]); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'1' => 'required_with:0|unique:users,email', | ||
]; | ||
} | ||
}; | ||
|
||
$import->import('import-users.xlsx'); | ||
|
||
$this->assertDatabaseHas('users', [ | ||
'email' => '[email protected]', | ||
]); | ||
|
||
try { | ||
$import->import('import-users.xlsx'); | ||
} catch (ValidationException $e) { | ||
$this->validateFailure($e, 1, '1', [ | ||
'The 1 has already been taken.', | ||
]); | ||
} | ||
|
||
$this->assertInstanceOf(ValidationException::class, $e ?? null); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
|