-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
1 parent
7658187
commit 2f12b6c
Showing
18 changed files
with
121 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (c) Alexandre Gomes Gaigalas <[email protected]> | ||
* 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'], | ||
]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.