Rename "Min" to "GreaterThanOrEqual"

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:
Henrique Moody 2024-02-23 11:05:03 +01:00
parent d184d9d95b
commit 7658187720
No known key found for this signature in database
GPG key ID: 221E9281655813A6
19 changed files with 147 additions and 146 deletions

View file

@ -16,7 +16,7 @@ that can be parsed by PHP
Below you can see some examples:
```php
v::min(100)->validate($collection); // true if it has at least 100 items
v::greaterThanOrEqual(100)->validate($collection); // true if it has at least 100 items
v::dateTime()
->between(new DateTime('yesterday'), new DateTime('tomorrow'))
@ -27,4 +27,4 @@ v::numericVal()->max(10)->validate(5); // true
v::stringVal()->between('a', 'f')->validate('d'); // true
v::dateTime()->between('yesterday', 'tomorrow')->validate('now'); // true
```
```

View file

@ -46,11 +46,11 @@
- [Equals](rules/Equals.md)
- [Equivalent](rules/Equivalent.md)
- [GreaterThan](rules/GreaterThan.md)
- [GreaterThanOrEqual](rules/GreaterThanOrEqual.md)
- [Identical](rules/Identical.md)
- [In](rules/In.md)
- [LessThan](rules/LessThan.md)
- [Max](rules/Max.md)
- [Min](rules/Min.md)
## Composite
@ -322,6 +322,7 @@
- [FloatVal](rules/FloatVal.md)
- [Graph](rules/Graph.md)
- [GreaterThan](rules/GreaterThan.md)
- [GreaterThanOrEqual](rules/GreaterThanOrEqual.md)
- [HexRgbColor](rules/HexRgbColor.md)
- [Iban](rules/Iban.md)
- [Identical](rules/Identical.md)
@ -351,7 +352,6 @@
- [Max](rules/Max.md)
- [MaxAge](rules/MaxAge.md)
- [Mimetype](rules/Mimetype.md)
- [Min](rules/Min.md)
- [MinAge](rules/MinAge.md)
- [Multiple](rules/Multiple.md)
- [Negative](rules/Negative.md)

View file

@ -32,7 +32,7 @@ See also:
- [DateTime](DateTime.md)
- [GreaterThan](GreaterThan.md)
- [GreaterThanOrEqual](GreaterThanOrEqual.md)
- [Length](Length.md)
- [LessThan](LessThan.md)
- [Max](Max.md)
- [Min](Min.md)

View file

@ -28,5 +28,5 @@ Version | Description
See also:
- [Between](Between.md)
- [GreaterThanOrEqual](GreaterThanOrEqual.md)
- [Max](Max.md)
- [Min](Min.md)

View file

@ -0,0 +1,40 @@
# GreaterThanOrEqual
- `GreaterThanOrEqual(mixed $compareTo)`
Validates whether the input is greater than or equal to a value.
```php
v::intVal()->greaterThanOrEqual(10)->validate(9); // false
v::intVal()->greaterThanOrEqual(10)->validate(10); // true
v::intVal()->greaterThanOrEqual(10)->validate(11); // true
```
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 "Min" to "GreaterThanOrEqual" |
| 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)
- [Length](Length.md)
- [LessThan](LessThan.md)
- [Max](Max.md)
- [MaxAge](MaxAge.md)
- [MinAge](MinAge.md)

View file

@ -50,4 +50,4 @@ Version | Description
See also:
- [Between](Between.md)
- [Min](Min.md)
- [GreaterThanOrEqual](GreaterThanOrEqual.md)

View file

@ -28,5 +28,5 @@ Version | Description
See also:
- [Between](Between.md)
- [GreaterThanOrEqual](GreaterThanOrEqual.md)
- [Max](Max.md)
- [Min](Min.md)

View file

@ -32,7 +32,7 @@ See also:
- [Between](Between.md)
- [GreaterThan](GreaterThan.md)
- [GreaterThanOrEqual](GreaterThanOrEqual.md)
- [LessThan](LessThan.md)
- [MaxAge](MaxAge.md)
- [Min](Min.md)
- [MinAge](MinAge.md)

View file

@ -32,8 +32,8 @@ Version | Description
See also:
- [Date](Date.md)
- [GreaterThanOrEqual](GreaterThanOrEqual.md)
- [Max](Max.md)
- [Min](Min.md)
- [MinAge](MinAge.md)
[date()]: http://php.net/date

View file

@ -1,39 +0,0 @@
# Min
- `Min(mixed $compareTo)`
Validates whether the input is greater than or equal to a value.
```php
v::intVal()->min(10)->validate(9); // false
v::intVal()->min(10)->validate(10); // true
v::intVal()->min(10)->validate(11); // true
```
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)
- [Length](Length.md)
- [LessThan](LessThan.md)
- [Max](Max.md)
- [MaxAge](MaxAge.md)
- [MinAge](MinAge.md)

View file

@ -33,9 +33,9 @@ See also:
- [Date](Date.md)
- [DateTime](DateTime.md)
- [GreaterThanOrEqual](GreaterThanOrEqual.md)
- [Max](Max.md)
- [MaxAge](MaxAge.md)
- [Min](Min.md)
[date()]: http://php.net/date
[DateTimeInterface]: http://php.net/DateTimeInterface

View file

@ -200,7 +200,7 @@ interface ChainedValidator extends Validatable
public function mimetype(string $mimetype): ChainedValidator;
public function min(mixed $compareTo): ChainedValidator;
public function greaterThanOrEqual(mixed $compareTo): ChainedValidator;
public function minAge(int $age, ?string $format = null): ChainedValidator;

View file

@ -29,7 +29,7 @@ final class Between extends Envelope
parent::__construct(
new AllOf(
new Min($minValue),
new GreaterThanOrEqual($minValue),
new Max($maxValue)
),
[

View file

@ -15,7 +15,7 @@ use Respect\Validation\Message\Template;
'{{name}} must be greater than or equal to {{compareTo}}',
'{{name}} must not be greater than or equal to {{compareTo}}',
)]
final class Min extends Comparison
final class GreaterThanOrEqual extends Comparison
{
protected function compare(mixed $left, mixed $right): bool
{

View file

@ -202,7 +202,7 @@ interface StaticValidator
public static function mimetype(string $mimetype): ChainedValidator;
public static function min(mixed $compareTo): ChainedValidator;
public static function greaterThanOrEqual(mixed $compareTo): ChainedValidator;
public static function minAge(int $age, ?string $format = null): ChainedValidator;

View 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::greaterThanOrEqual(INF)->check(10));
exceptionMessage(static fn() => v::not(v::greaterThanOrEqual(5))->check(INF));
exceptionFullMessage(static fn() => v::greaterThanOrEqual('today')->assert('yesterday'));
exceptionFullMessage(static fn() => v::not(v::greaterThanOrEqual('a'))->assert('z'));
?>
--EXPECT--
10 must be greater than or equal to `INF`
`INF` must not be greater than or equal to 5
- "yesterday" must be greater than or equal to "today"
- "z" must not be greater than or equal to "a"

View file

@ -1,19 +0,0 @@
--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
exceptionMessage(static fn() => v::min(INF)->check(10));
exceptionMessage(static fn() => v::not(v::min(5))->check(INF));
exceptionFullMessage(static fn() => v::min('today')->assert('yesterday'));
exceptionFullMessage(static fn() => v::not(v::min('a'))->assert('z'));
?>
--EXPECT--
10 must be greater than or equal to `INF`
`INF` must not be greater than or equal to 5
- "yesterday" must be greater than or equal to "today"
- "z" must not be greater than or equal to "a"

View file

@ -0,0 +1,73 @@
<?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(GreaterThanOrEqual::class)]
final class GreaterThanOrEqualTest extends RuleTestCase
{
/** @return iterable<array{GreaterThanOrEqual, mixed}> */
public static function providerForValidInput(): iterable
{
return [
// From documentation
[new GreaterThanOrEqual(10), 10],
[new GreaterThanOrEqual(10), 11],
[new GreaterThanOrEqual('2010-01-01'), '2010-01-01'],
[new GreaterThanOrEqual(new DateTime('yesterday')), new DateTimeImmutable('tomorrow')],
[new GreaterThanOrEqual('1988-09-09'), '18 years ago'],
[new GreaterThanOrEqual('a'), 'b'],
[new GreaterThanOrEqual(100), 165.0],
[new GreaterThanOrEqual(-100), 200],
[new GreaterThanOrEqual(200), 200],
[new GreaterThanOrEqual(200), 300],
[new GreaterThanOrEqual('a'), 'a'],
[new GreaterThanOrEqual('a'), 'c'],
[new GreaterThanOrEqual('yesterday'), 'now'],
// Samples from issue #178
[new GreaterThanOrEqual('13-05-2014 03:16'), '20-05-2014 03:16'],
[new GreaterThanOrEqual(new DateTime('13-05-2014 03:16')), new DateTime('20-05-2014 03:16')],
[new GreaterThanOrEqual('13-05-2014 03:16'), new DateTime('20-05-2014 03:16')],
[new GreaterThanOrEqual(new DateTime('13-05-2014 03:16')), '20-05-2014 03:16'],
[new GreaterThanOrEqual(50), 50],
[new GreaterThanOrEqual(new CountableStub(10)), 10],
];
}
/** @return iterable<array{GreaterThanOrEqual, mixed}> */
public static function providerForInvalidInput(): iterable
{
return [
// From documentation
[new GreaterThanOrEqual(10), 9],
[new GreaterThanOrEqual('2011-01-01'), '2009-01-01'],
[new GreaterThanOrEqual(new DateTimeImmutable('+1 month')), new DateTime('today')],
[new GreaterThanOrEqual('+1 minute'), new DateTime('now')],
[new GreaterThanOrEqual('C'), 'A'],
[new GreaterThanOrEqual(100), ''],
[new GreaterThanOrEqual(100), ''],
[new GreaterThanOrEqual(500), 300],
[new GreaterThanOrEqual(0), -250],
[new GreaterThanOrEqual(0), -50],
[new GreaterThanOrEqual(new CountableStub(1)), 0],
[new GreaterThanOrEqual(2040), '2018-01-25'],
[new GreaterThanOrEqual(10.5), '2018-01-25'],
];
}
}

View file

@ -1,73 +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(Min::class)]
final class MinTest extends RuleTestCase
{
/** @return iterable<array{Min, mixed}> */
public static function providerForValidInput(): iterable
{
return [
// From documentation
[new Min(10), 10],
[new Min(10), 11],
[new Min('2010-01-01'), '2010-01-01'],
[new Min(new DateTime('yesterday')), new DateTimeImmutable('tomorrow')],
[new Min('1988-09-09'), '18 years ago'],
[new Min('a'), 'b'],
[new Min(100), 165.0],
[new Min(-100), 200],
[new Min(200), 200],
[new Min(200), 300],
[new Min('a'), 'a'],
[new Min('a'), 'c'],
[new Min('yesterday'), 'now'],
// Samples from issue #178
[new Min('13-05-2014 03:16'), '20-05-2014 03:16'],
[new Min(new DateTime('13-05-2014 03:16')), new DateTime('20-05-2014 03:16')],
[new Min('13-05-2014 03:16'), new DateTime('20-05-2014 03:16')],
[new Min(new DateTime('13-05-2014 03:16')), '20-05-2014 03:16'],
[new Min(50), 50],
[new Min(new CountableStub(10)), 10],
];
}
/** @return iterable<array{Min, mixed}> */
public static function providerForInvalidInput(): iterable
{
return [
// From documentation
[new Min(10), 9],
[new Min('2011-01-01'), '2009-01-01'],
[new Min(new DateTimeImmutable('+1 month')), new DateTime('today')],
[new Min('+1 minute'), new DateTime('now')],
[new Min('C'), 'A'],
[new Min(100), ''],
[new Min(100), ''],
[new Min(500), 300],
[new Min(0), -250],
[new Min(0), -50],
[new Min(new CountableStub(1)), 0],
[new Min(2040), '2018-01-25'],
[new Min(10.5), '2018-01-25'],
];
}
}