Skip to content

Commit

Permalink
fix replace missing_unless
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 27, 2023
1 parent 5f30445 commit 89ac58a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/Illuminate/Validation/Concerns/ReplacesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ protected function replaceMissingIf($message, $attribute, $rule, $parameters)
*/
protected function replaceMissingUnless($message, $attribute, $rule, $parameters)
{
return $this->replaceMissingIf($message, $attribute, $rule, $parameters);
return str_replace([':other', ':value'], [
$this->getDisplayableAttribute($parameters[0]),
$this->getDisplayableValue($parameters[0], $parameters[1]),
], $message);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2324,23 +2324,23 @@ public function testValidateMissingUnless()

$v = new Validator($trans, ['foo' => 'yes', 'bar' => '2'], ['foo' => 'missing_unless:bar,1']);
$this->assertFalse($v->passes());
$this->assertSame('The foo field must be missing unless bar is 2.', $v->errors()->first('foo'));
$this->assertSame('The foo field must be missing unless bar is 1.', $v->errors()->first('foo'));

$v = new Validator($trans, ['foo' => '', 'bar' => '2'], ['foo' => 'missing_unless:bar,1']);
$this->assertFalse($v->passes());
$this->assertSame('The foo field must be missing unless bar is 2.', $v->errors()->first('foo'));
$this->assertSame('The foo field must be missing unless bar is 1.', $v->errors()->first('foo'));

$v = new Validator($trans, ['foo' => ' ', 'bar' => '2'], ['foo' => 'missing_unless:bar,1']);
$this->assertFalse($v->passes());
$this->assertSame('The foo field must be missing unless bar is 2.', $v->errors()->first('foo'));
$this->assertSame('The foo field must be missing unless bar is 1.', $v->errors()->first('foo'));

$v = new Validator($trans, ['foo' => null, 'bar' => '2'], ['foo' => 'missing_unless:bar,1']);
$this->assertFalse($v->passes());
$this->assertSame('The foo field must be missing unless bar is 2.', $v->errors()->first('foo'));
$this->assertSame('The foo field must be missing unless bar is 1.', $v->errors()->first('foo'));

$v = new Validator($trans, ['foo' => [], 'bar' => '2'], ['foo' => 'missing_unless:bar,1']);
$this->assertFalse($v->passes());
$this->assertSame('The foo field must be missing unless bar is 2.', $v->errors()->first('foo'));
$this->assertSame('The foo field must be missing unless bar is 1.', $v->errors()->first('foo'));

$v = new Validator($trans, ['foo' => new class implements Countable
{
Expand All @@ -2350,7 +2350,7 @@ public function count(): int
}
}, 'bar' => '2', ], ['foo' => 'missing_unless:bar,1']);
$this->assertFalse($v->passes());
$this->assertSame('The foo field must be missing unless bar is 2.', $v->errors()->first('foo'));
$this->assertSame('The foo field must be missing unless bar is 1.', $v->errors()->first('foo'));

$v = new Validator($trans, ['foo' => 'foo', 'bar' => '1'], ['foo' => 'missing_unless:bar,1']);
$this->assertTrue($v->passes());
Expand Down

0 comments on commit 89ac58a

Please sign in to comment.