|
9 | 9 |
|
10 | 10 | date_default_timezone_set('UTC'); |
11 | 11 |
|
12 | | -test('Scenario #1', catchMessage( |
| 12 | +test('Standard date/time template validation', catchAll( |
13 | 13 | fn() => v::dateTime()->assert('FooBarBazz'), |
14 | | - fn(string $message) => expect($message)->toBe('"FooBarBazz" must be a valid date/time'), |
| 14 | + fn(string $message, string $fullMessage, array $messages) => expect() |
| 15 | + ->and($message)->toBe('"FooBarBazz" must be a valid date/time') |
| 16 | + ->and($fullMessage)->toBe('- "FooBarBazz" must be a valid date/time') |
| 17 | + ->and($messages)->toBe(['dateTime' => '"FooBarBazz" must be a valid date/time']), |
15 | 18 | )); |
16 | 19 |
|
17 | | -test('Scenario #2', catchMessage( |
18 | | - fn() => v::dateTime('c')->assert('06-12-1995'), |
19 | | - fn(string $message) => expect($message)->toBe('"06-12-1995" must be a valid date/time in the format "2005-12-30T01:02:03+00:00"'), |
20 | | -)); |
21 | | - |
22 | | -test('Scenario #3', catchFullMessage( |
23 | | - fn() => v::dateTime()->assert('QuxQuuxx'), |
24 | | - fn(string $fullMessage) => expect($fullMessage)->toBe('- "QuxQuuxx" must be a valid date/time'), |
25 | | -)); |
26 | | - |
27 | | -test('Scenario #4', catchFullMessage( |
28 | | - fn() => v::dateTime('r')->assert(2018013030), |
29 | | - fn(string $fullMessage) => expect($fullMessage)->toBe('- 2018013030 must be a valid date/time in the format "Fri, 30 Dec 2005 01:02:03 +0000"'), |
| 20 | +test('Standard date/time template validation (inverted)', catchAll( |
| 21 | + fn() => v::not(v::dateTime())->assert('1988-09-09'), |
| 22 | + fn(string $message, string $fullMessage, array $messages) => expect() |
| 23 | + ->and($message)->toBe('"1988-09-09" must not be a valid date/time') |
| 24 | + ->and($fullMessage)->toBe('- "1988-09-09" must not be a valid date/time') |
| 25 | + ->and($messages)->toBe(['notDateTime' => '"1988-09-09" must not be a valid date/time']), |
30 | 26 | )); |
31 | 27 |
|
32 | | -test('Scenario #5', catchMessage( |
33 | | - fn() => v::not(v::dateTime())->assert('4 days ago'), |
34 | | - fn(string $message) => expect($message)->toBe('"4 days ago" must not be a valid date/time'), |
| 28 | +test('Format date/time template validation', catchAll( |
| 29 | + fn() => v::dateTime('c')->assert('06-12-1995'), |
| 30 | + fn(string $message, string $fullMessage, array $messages) => expect() |
| 31 | + ->and($message)->toBe('"06-12-1995" must be a valid date/time in the format "2005-12-30T01:02:03+00:00"') |
| 32 | + ->and($fullMessage)->toBe('- "06-12-1995" must be a valid date/time in the format "2005-12-30T01:02:03+00:00"') |
| 33 | + ->and($messages)->toBe(['dateTime' => '"06-12-1995" must be a valid date/time in the format "2005-12-30T01:02:03+00:00"']), |
35 | 34 | )); |
36 | 35 |
|
37 | | -test('Scenario #6', catchMessage( |
| 36 | +test('Format date/time template validation (inverted)', catchAll( |
38 | 37 | fn() => v::not(v::dateTime('Y-m-d'))->assert('1988-09-09'), |
39 | | - fn(string $message) => expect($message)->toBe('"1988-09-09" must not be a valid date/time in the format "2005-12-30"'), |
40 | | -)); |
41 | | - |
42 | | -test('Scenario #7', catchFullMessage( |
43 | | - fn() => v::not(v::dateTime())->assert('+3 weeks'), |
44 | | - fn(string $fullMessage) => expect($fullMessage)->toBe('- "+3 weeks" must not be a valid date/time'), |
45 | | -)); |
46 | | - |
47 | | -test('Scenario #8', catchFullMessage( |
48 | | - fn() => v::not(v::dateTime('d/m/y'))->assert('23/07/99'), |
49 | | - fn(string $fullMessage) => expect($fullMessage)->toBe('- "23/07/99" must not be a valid date/time in the format "30/12/05"'), |
| 38 | + fn(string $message, string $fullMessage, array $messages) => expect() |
| 39 | + ->and($message)->toBe('"1988-09-09" must not be a valid date/time in the format "2005-12-30"') |
| 40 | + ->and($fullMessage)->toBe('- "1988-09-09" must not be a valid date/time in the format "2005-12-30"') |
| 41 | + ->and($messages)->toBe(['notDateTime' => '"1988-09-09" must not be a valid date/time in the format "2005-12-30"']), |
50 | 42 | )); |
0 commit comments