mirror of
https://github.com/Respect/Validation.git
synced 2024-06-07 16:22:16 +02:00
Rename "Max" to "LessThanOrEqual"
Although the name is much longer, it's more explicit what it does. I confess that after a while without using Validation, even I get confused about that. Besides, I would like to create another rule with the same name, but that will behave differently. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
7658187720
commit
2f12b6c8d8
|
@ -22,7 +22,7 @@ v::dateTime()
|
|||
->between(new DateTime('yesterday'), new DateTime('tomorrow'))
|
||||
->validate(new DateTime('now')); // true
|
||||
|
||||
v::numericVal()->max(10)->validate(5); // true
|
||||
v::numericVal()->lessThanOrEqual(10)->validate(5); // true
|
||||
|
||||
v::stringVal()->between('a', 'f')->validate('d'); // true
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
- [Identical](rules/Identical.md)
|
||||
- [In](rules/In.md)
|
||||
- [LessThan](rules/LessThan.md)
|
||||
- [Max](rules/Max.md)
|
||||
- [LessThanOrEqual](rules/LessThanOrEqual.md)
|
||||
|
||||
## Composite
|
||||
|
||||
|
@ -346,10 +346,10 @@
|
|||
- [LeapYear](rules/LeapYear.md)
|
||||
- [Length](rules/Length.md)
|
||||
- [LessThan](rules/LessThan.md)
|
||||
- [LessThanOrEqual](rules/LessThanOrEqual.md)
|
||||
- [Lowercase](rules/Lowercase.md)
|
||||
- [Luhn](rules/Luhn.md)
|
||||
- [MacAddress](rules/MacAddress.md)
|
||||
- [Max](rules/Max.md)
|
||||
- [MaxAge](rules/MaxAge.md)
|
||||
- [Mimetype](rules/Mimetype.md)
|
||||
- [MinAge](rules/MinAge.md)
|
||||
|
|
|
@ -35,4 +35,4 @@ See also:
|
|||
- [GreaterThanOrEqual](GreaterThanOrEqual.md)
|
||||
- [Length](Length.md)
|
||||
- [LessThan](LessThan.md)
|
||||
- [Max](Max.md)
|
||||
- [LessThanOrEqual](LessThanOrEqual.md)
|
||||
|
|
|
@ -29,4 +29,4 @@ See also:
|
|||
|
||||
- [Between](Between.md)
|
||||
- [GreaterThanOrEqual](GreaterThanOrEqual.md)
|
||||
- [Max](Max.md)
|
||||
- [LessThanOrEqual](LessThanOrEqual.md)
|
||||
|
|
|
@ -35,6 +35,6 @@ See also:
|
|||
- [GreaterThan](GreaterThan.md)
|
||||
- [Length](Length.md)
|
||||
- [LessThan](LessThan.md)
|
||||
- [Max](Max.md)
|
||||
- [LessThanOrEqual](LessThanOrEqual.md)
|
||||
- [MaxAge](MaxAge.md)
|
||||
- [MinAge](MinAge.md)
|
||||
|
|
|
@ -29,4 +29,4 @@ See also:
|
|||
|
||||
- [Between](Between.md)
|
||||
- [GreaterThanOrEqual](GreaterThanOrEqual.md)
|
||||
- [Max](Max.md)
|
||||
- [LessThanOrEqual](LessThanOrEqual.md)
|
||||
|
|
39
docs/rules/LessThanOrEqual.md
Normal file
39
docs/rules/LessThanOrEqual.md
Normal file
|
@ -0,0 +1,39 @@
|
|||
# LessThanOrEqual
|
||||
|
||||
- `LessThanOrEqual(mixed $compareTo)`
|
||||
|
||||
Validates whether the input is less than or equal to a value.
|
||||
|
||||
```php
|
||||
v::lessThanOrEqual(10)->validate(9); // true
|
||||
v::lessThanOrEqual(10)->validate(10); // true
|
||||
v::lessThanOrEqual(10)->validate(11); // false
|
||||
```
|
||||
|
||||
Validation makes comparison easier, check out our supported
|
||||
[comparable values](../07-comparable-values.md).
|
||||
|
||||
Message template for this validator includes `{{compareTo}}`.
|
||||
|
||||
## Categorization
|
||||
|
||||
- Comparisons
|
||||
|
||||
## Changelog
|
||||
|
||||
| Version | Description |
|
||||
|--------:|-----------------------------------------|
|
||||
| 3.0.0 | Renamed from "Max" to "LessThanOrEqual" |
|
||||
| 2.0.0 | Became always inclusive |
|
||||
| 1.0.0 | Became inclusive by default |
|
||||
| 0.3.9 | Created |
|
||||
|
||||
***
|
||||
See also:
|
||||
|
||||
- [Between](Between.md)
|
||||
- [GreaterThan](GreaterThan.md)
|
||||
- [GreaterThanOrEqual](GreaterThanOrEqual.md)
|
||||
- [LessThan](LessThan.md)
|
||||
- [MaxAge](MaxAge.md)
|
||||
- [MinAge](MinAge.md)
|
|
@ -1,38 +0,0 @@
|
|||
# Max
|
||||
|
||||
- `Max(mixed $compareTo)`
|
||||
|
||||
Validates whether the input is less than or equal to a value.
|
||||
|
||||
```php
|
||||
v::max(10)->validate(9); // true
|
||||
v::max(10)->validate(10); // true
|
||||
v::max(10)->validate(11); // false
|
||||
```
|
||||
|
||||
Validation makes comparison easier, check out our supported
|
||||
[comparable values](../07-comparable-values.md).
|
||||
|
||||
Message template for this validator includes `{{compareTo}}`.
|
||||
|
||||
## Categorization
|
||||
|
||||
- Comparisons
|
||||
|
||||
## Changelog
|
||||
|
||||
Version | Description
|
||||
--------|-------------
|
||||
2.0.0 | Became always inclusive
|
||||
1.0.0 | Became inclusive by default
|
||||
0.3.9 | Created
|
||||
|
||||
***
|
||||
See also:
|
||||
|
||||
- [Between](Between.md)
|
||||
- [GreaterThan](GreaterThan.md)
|
||||
- [GreaterThanOrEqual](GreaterThanOrEqual.md)
|
||||
- [LessThan](LessThan.md)
|
||||
- [MaxAge](MaxAge.md)
|
||||
- [MinAge](MinAge.md)
|
|
@ -33,7 +33,7 @@ See also:
|
|||
|
||||
- [Date](Date.md)
|
||||
- [GreaterThanOrEqual](GreaterThanOrEqual.md)
|
||||
- [Max](Max.md)
|
||||
- [LessThanOrEqual](LessThanOrEqual.md)
|
||||
- [MinAge](MinAge.md)
|
||||
|
||||
[date()]: http://php.net/date
|
||||
|
|
|
@ -34,7 +34,7 @@ See also:
|
|||
- [Date](Date.md)
|
||||
- [DateTime](DateTime.md)
|
||||
- [GreaterThanOrEqual](GreaterThanOrEqual.md)
|
||||
- [Max](Max.md)
|
||||
- [LessThanOrEqual](LessThanOrEqual.md)
|
||||
- [MaxAge](MaxAge.md)
|
||||
|
||||
[date()]: http://php.net/date
|
||||
|
|
|
@ -194,7 +194,7 @@ interface ChainedValidator extends Validatable
|
|||
|
||||
public function macAddress(): ChainedValidator;
|
||||
|
||||
public function max(mixed $compareTo): ChainedValidator;
|
||||
public function lessThanOrEqual(mixed $compareTo): ChainedValidator;
|
||||
|
||||
public function maxAge(int $age, ?string $format = null): ChainedValidator;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ final class Between extends Envelope
|
|||
parent::__construct(
|
||||
new AllOf(
|
||||
new GreaterThanOrEqual($minValue),
|
||||
new Max($maxValue)
|
||||
new LessThanOrEqual($maxValue)
|
||||
),
|
||||
[
|
||||
'minValue' => $minValue,
|
||||
|
|
|
@ -15,7 +15,7 @@ use Respect\Validation\Message\Template;
|
|||
'{{name}} must be less than or equal to {{compareTo}}',
|
||||
'{{name}} must not be less than or equal to {{compareTo}}',
|
||||
)]
|
||||
final class Max extends Comparison
|
||||
final class LessThanOrEqual extends Comparison
|
||||
{
|
||||
protected function compare(mixed $left, mixed $right): bool
|
||||
{
|
|
@ -196,7 +196,7 @@ interface StaticValidator
|
|||
|
||||
public static function macAddress(): ChainedValidator;
|
||||
|
||||
public static function max(mixed $compareTo): ChainedValidator;
|
||||
public static function lessThanOrEqual(mixed $compareTo): ChainedValidator;
|
||||
|
||||
public static function maxAge(int $age, ?string $format = null): ChainedValidator;
|
||||
|
||||
|
|
19
tests/integration/rules/lessThanOrEqual.phpt
Normal file
19
tests/integration/rules/lessThanOrEqual.phpt
Normal file
|
@ -0,0 +1,19 @@
|
|||
--FILE--
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
exceptionMessage(static fn() => v::lessThanOrEqual(10)->check(11));
|
||||
exceptionMessage(static fn() => v::not(v::lessThanOrEqual(10))->check(5));
|
||||
exceptionFullMessage(static fn() => v::lessThanOrEqual('today')->assert('tomorrow'));
|
||||
exceptionFullMessage(static fn() => v::not(v::lessThanOrEqual('b'))->assert('a'));
|
||||
?>
|
||||
--EXPECT--
|
||||
11 must be less than or equal to 10
|
||||
5 must not be less than or equal to 10
|
||||
- "tomorrow" must be less than or equal to "today"
|
||||
- "a" must not be less than or equal to "b"
|
|
@ -1,19 +0,0 @@
|
|||
--FILE--
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
exceptionMessage(static fn() => v::max(10)->check(11));
|
||||
exceptionMessage(static fn() => v::not(v::max(10))->check(5));
|
||||
exceptionFullMessage(static fn() => v::max('today')->assert('tomorrow'));
|
||||
exceptionFullMessage(static fn() => v::not(v::max('b'))->assert('a'));
|
||||
?>
|
||||
--EXPECT--
|
||||
11 must be less than or equal to 10
|
||||
5 must not be less than or equal to 10
|
||||
- "tomorrow" must be less than or equal to "today"
|
||||
- "a" must not be less than or equal to "b"
|
50
tests/unit/Rules/LessThanOrEqualTest.php
Normal file
50
tests/unit/Rules/LessThanOrEqualTest.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use Respect\Validation\Test\RuleTestCase;
|
||||
use Respect\Validation\Test\Stubs\CountableStub;
|
||||
|
||||
#[Group('rule')]
|
||||
#[CoversClass(LessThanOrEqual::class)]
|
||||
final class LessThanOrEqualTest extends RuleTestCase
|
||||
{
|
||||
/** @return iterable<array{LessThanOrEqual, mixed}> */
|
||||
public static function providerForValidInput(): iterable
|
||||
{
|
||||
return [
|
||||
[new LessThanOrEqual(10), 9],
|
||||
[new LessThanOrEqual(10), 10],
|
||||
[new LessThanOrEqual('2010-01-01'), '2000-01-01'],
|
||||
[new LessThanOrEqual(new DateTime('today')), new DateTimeImmutable('yesterday')],
|
||||
[new LessThanOrEqual('18 years ago'), '1988-09-09'],
|
||||
[new LessThanOrEqual('z'), 'a'],
|
||||
[new LessThanOrEqual(new CountableStub(3)), 2],
|
||||
];
|
||||
}
|
||||
|
||||
/** @return iterable<array{LessThanOrEqual, mixed}> */
|
||||
public static function providerForInvalidInput(): iterable
|
||||
{
|
||||
return [
|
||||
[new LessThanOrEqual(10), 11],
|
||||
[new LessThanOrEqual(new DateTimeImmutable('today')), new DateTime('tomorrow')],
|
||||
[new LessThanOrEqual('now'), '+1 minute'],
|
||||
[new LessThanOrEqual('B'), 'C'],
|
||||
[new LessThanOrEqual(new CountableStub(3)), 4],
|
||||
[new LessThanOrEqual(1900), '2018-01-25'],
|
||||
[new LessThanOrEqual(10.5), '2018-01-25'],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use Respect\Validation\Test\RuleTestCase;
|
||||
use Respect\Validation\Test\Stubs\CountableStub;
|
||||
|
||||
#[Group('rule')]
|
||||
#[CoversClass(Max::class)]
|
||||
final class MaxTest extends RuleTestCase
|
||||
{
|
||||
/** @return iterable<array{Max, mixed}> */
|
||||
public static function providerForValidInput(): iterable
|
||||
{
|
||||
return [
|
||||
[new Max(10), 9],
|
||||
[new Max(10), 10],
|
||||
[new Max('2010-01-01'), '2000-01-01'],
|
||||
[new Max(new DateTime('today')), new DateTimeImmutable('yesterday')],
|
||||
[new Max('18 years ago'), '1988-09-09'],
|
||||
[new Max('z'), 'a'],
|
||||
[new Max(new CountableStub(3)), 2],
|
||||
];
|
||||
}
|
||||
|
||||
/** @return iterable<array{Max, mixed}> */
|
||||
public static function providerForInvalidInput(): iterable
|
||||
{
|
||||
return [
|
||||
[new Max(10), 11],
|
||||
[new Max(new DateTimeImmutable('today')), new DateTime('tomorrow')],
|
||||
[new Max('now'), '+1 minute'],
|
||||
[new Max('B'), 'C'],
|
||||
[new Max(new CountableStub(3)), 4],
|
||||
[new Max(1900), '2018-01-25'],
|
||||
[new Max(10.5), '2018-01-25'],
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue