Skip to content

Commit

Permalink
Add passing test for situation in #4077
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbrouwers committed Feb 19, 2024
1 parent 4719218 commit c35a38e
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/Concerns/WithValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,56 @@ public function customValidationAttributes()
$this->assertInstanceOf(ValidationException::class, $e ?? null);
}

public function test_can_validate_with_custom_attributes_pointing_to_another_attribute()
{
$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'],
'2' => ['required_with:*.1'],
];
}

/**
* @return array
*/
public function customValidationAttributes()
{
return ['1' => 'email', '2' => 'password'];
}
};

try {
$import->import('import-users.xlsx');
} catch (ValidationException $e) {
$this->validateFailure($e, 1, 'password', [
'The password field is required when email is present.',
]);
}

$this->assertInstanceOf(ValidationException::class, $e ?? null);
}

public function test_can_validate_with_custom_message()
{
$import = new class implements ToModel, WithValidation
Expand Down

0 comments on commit c35a38e

Please sign in to comment.