Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Remove automatic detection of numeric attributes for the newly added comparison rules. #24135

Merged
merged 1 commit into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/Illuminate/Validation/Concerns/ReplacesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,62 @@ protected function replaceDigitsBetween($message, $attribute, $rule, $parameters
return $this->replaceBetween($message, $attribute, $rule, $parameters);
}

/**
* Replace all place-holders for the gt rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected function replaceGt($message, $attribute, $rule, $parameters)
{
return str_replace(':value', $this->getSize($parameters[0], $this->getValue($parameters[0])), $message);
}

/**
* Replace all place-holders for the lt rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected function replaceLt($message, $attribute, $rule, $parameters)
{
return str_replace(':value', $this->getSize($parameters[0], $this->getValue($parameters[0])), $message);
}

/**
* Replace all place-holders for the gte rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected function replaceGte($message, $attribute, $rule, $parameters)
{
return str_replace(':value', $this->getSize($parameters[0], $this->getValue($parameters[0])), $message);
}

/**
* Replace all place-holders for the lte rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected function replaceLte($message, $attribute, $rule, $parameters)
{
return str_replace(':value', $this->getSize($parameters[0], $this->getValue($parameters[0])), $message);
}

/**
* Replace all place-holders for the min rule.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class Validator implements ValidatorContract
*
* @var array
*/
protected $numericRules = ['Numeric', 'Integer', 'Gt', 'Lt', 'Gte', 'Lte'];
protected $numericRules = ['Numeric', 'Integer'];

/**
* Create a new Validator instance.
Expand Down
16 changes: 8 additions & 8 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ public function testValidateDifferent()
public function testGreaterThan()
{
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['lhs' => 15, 'rhs' => 10], ['lhs' => 'gt:rhs']);
$v = new Validator($trans, ['lhs' => 15, 'rhs' => 10], ['lhs' => 'numeric|gt:rhs']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['lhs' => 'longer string', 'rhs' => 'string'], ['lhs' => 'gt:rhs']);
Expand All @@ -1079,14 +1079,14 @@ public function testGreaterThan()
$v = new Validator($trans, ['lhs' => $fileOne, 'rhs' => $fileTwo], ['lhs' => 'gt:rhs']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['lhs' => 15], ['lhs' => 'gt:10']);
$v = new Validator($trans, ['lhs' => 15], ['lhs' => 'numeric|gt:10']);
$this->assertTrue($v->passes());
}

public function testLessThan()
{
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['lhs' => 15, 'rhs' => 10], ['lhs' => 'lt:rhs']);
$v = new Validator($trans, ['lhs' => 15, 'rhs' => 10], ['lhs' => 'numeric|lt:rhs']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['lhs' => 'longer string', 'rhs' => 'string'], ['lhs' => 'lt:rhs']);
Expand All @@ -1102,14 +1102,14 @@ public function testLessThan()
$v = new Validator($trans, ['lhs' => $fileOne, 'rhs' => $fileTwo], ['lhs' => 'lt:rhs']);
$this->assertTrue($v->fails());

$v = new Validator($trans, ['lhs' => 15], ['lhs' => 'lt:10']);
$v = new Validator($trans, ['lhs' => 15], ['lhs' => 'numeric|lt:10']);
$this->assertTrue($v->fails());
}

public function testGreaterThanOrEqual()
{
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['lhs' => 15, 'rhs' => 15], ['lhs' => 'gte:rhs']);
$v = new Validator($trans, ['lhs' => 15, 'rhs' => 15], ['lhs' => 'numeric|gte:rhs']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['lhs' => 'longer string', 'rhs' => 'string'], ['lhs' => 'gte:rhs']);
Expand All @@ -1125,14 +1125,14 @@ public function testGreaterThanOrEqual()
$v = new Validator($trans, ['lhs' => $fileOne, 'rhs' => $fileTwo], ['lhs' => 'gte:rhs']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['lhs' => 15], ['lhs' => 'gte:15']);
$v = new Validator($trans, ['lhs' => 15], ['lhs' => 'numeric|gte:15']);
$this->assertTrue($v->passes());
}

public function testLessThanOrEqual()
{
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, ['lhs' => 15, 'rhs' => 15], ['lhs' => 'lte:rhs']);
$v = new Validator($trans, ['lhs' => 15, 'rhs' => 15], ['lhs' => 'numeric|lte:rhs']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['lhs' => 'longer string', 'rhs' => 'string'], ['lhs' => 'lte:rhs']);
Expand All @@ -1148,7 +1148,7 @@ public function testLessThanOrEqual()
$v = new Validator($trans, ['lhs' => $fileOne, 'rhs' => $fileTwo], ['lhs' => 'lte:rhs']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['lhs' => 15], ['lhs' => 'lte:10']);
$v = new Validator($trans, ['lhs' => 15], ['lhs' => 'numeric|lte:10']);
$this->assertTrue($v->fails());
}

Expand Down