-
Notifications
You must be signed in to change notification settings - Fork 773
/
sorted.phpt
71 lines (60 loc) · 1.84 KB
/
sorted.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
--CREDITS--
Danilo Correa <danilosilva87@gmail.com>
Henrique Moody <henriquemoody@gmail.com>
--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Exceptions\NestedValidationException;
use Respect\Validation\Exceptions\SortedException;
use Respect\Validation\Validator as v;
try {
v::sorted('ASC')->check([1, 3, 2]);
} catch (SortedException $exception) {
echo $exception->getMessage().PHP_EOL;
}
try {
v::sorted('DESC')->check([1, 2, 3]);
} catch (SortedException $exception) {
echo $exception->getMessage().PHP_EOL;
}
try {
v::not(v::sorted('ASC'))->check([1, 2, 3]);
} catch (SortedException $exception) {
echo $exception->getMessage().PHP_EOL;
}
try {
v::not(v::sorted('DESC'))->check([3, 2, 1]);
} catch (SortedException $exception) {
echo $exception->getMessage().PHP_EOL;
}
try {
v::sorted('ASC')->assert([3, 2, 1]);
} catch (NestedValidationException $exception) {
echo $exception->getFullMessage().PHP_EOL;
}
try {
v::sorted('DESC')->assert([1, 2, 3]);
} catch (NestedValidationException $exception) {
echo $exception->getFullMessage().PHP_EOL;
}
try {
v::not(v::sorted('ASC'))->assert([1, 2, 3]);
} catch (NestedValidationException $exception) {
echo $exception->getFullMessage().PHP_EOL;
}
try {
v::not(v::sorted('DESC'))->assert([3, 2, 1]);
} catch (NestedValidationException $exception) {
echo $exception->getFullMessage().PHP_EOL;
}
?>
--EXPECT--
`{ 1, 3, 2 }` must be sorted in ascending order
`{ 1, 2, 3 }` must be sorted in descending order
`{ 1, 2, 3 }` must not be sorted in ascending order
`{ 3, 2, 1 }` must not be sorted in descending order
- `{ 3, 2, 1 }` must be sorted in ascending order
- `{ 1, 2, 3 }` must be sorted in descending order
- `{ 1, 2, 3 }` must not be sorted in ascending order
- `{ 3, 2, 1 }` must not be sorted in descending order