Skip to content

Commit 715fbb6

Browse files
committed
Migrate 21 additional validator tests to catchAll() logic
This commit transitions 21 more files to the `catchAll()` function. This shift ensures that every message template is verified in both default and inverted templates, replacing ambiguous "Scenarios" with a predictable, template-aware testing name. With this update, 47% of the library (68 files) is now standardized.
1 parent 70e14e2 commit 715fbb6

21 files changed

Lines changed: 387 additions & 468 deletions

tests/feature/Validators/ArrayTypeTest.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,18 @@
77

88
declare(strict_types=1);
99

10-
test('Scenario #1', catchMessage(
10+
test('Standard arrayType template validation', catchAll(
1111
fn() => v::arrayType()->assert('teste'),
12-
fn(string $message) => expect($message)->toBe('"teste" must be an array'),
12+
fn(string $message, string $fullMessage, array $messages) => expect()
13+
->and($message)->toBe('"teste" must be an array')
14+
->and($fullMessage)->toBe('- "teste" must be an array')
15+
->and($messages)->toBe(['arrayType' => '"teste" must be an array']),
1316
));
1417

15-
test('Scenario #2', catchMessage(
18+
test('Standard arrayType template validation (inverted)', catchAll(
1619
fn() => v::not(v::arrayType())->assert([]),
17-
fn(string $message) => expect($message)->toBe('`[]` must not be an array'),
18-
));
19-
20-
test('Scenario #3', catchFullMessage(
21-
fn() => v::arrayType()->assert(new ArrayObject()),
22-
fn(string $fullMessage) => expect($fullMessage)->toBe('- `ArrayObject { getArrayCopy() => [] }` must be an array'),
23-
));
24-
25-
test('Scenario #4', catchFullMessage(
26-
fn() => v::not(v::arrayType())->assert([1, 2, 3]),
27-
fn(string $fullMessage) => expect($fullMessage)->toBe('- `[1, 2, 3]` must not be an array'),
20+
fn(string $message, string $fullMessage, array $messages) => expect()
21+
->and($message)->toBe('`[]` must not be an array')
22+
->and($fullMessage)->toBe('- `[]` must not be an array')
23+
->and($messages)->toBe(['notArrayType' => '`[]` must not be an array']),
2824
));

tests/feature/Validators/ContainsCountTest.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,34 @@
77

88
declare(strict_types=1);
99

10-
test('Scenario #1', catchMessage(
10+
test('Contains count times template validation', catchAll(
1111
fn() => v::containsCount('foo', 2)->assert('bar'),
12-
fn(string $message) => expect($message)->toBe('"bar" must contain "foo" 2 time(s)'),
12+
fn(string $message, string $fullMessage, array $messages) => expect()
13+
->and($message)->toBe('"bar" must contain "foo" 2 time(s)')
14+
->and($fullMessage)->toBe('- "bar" must contain "foo" 2 time(s)')
15+
->and($messages)->toBe(['containsCount' => '"bar" must contain "foo" 2 time(s)']),
1316
));
1417

15-
test('Scenario #2', catchMessage(
16-
fn() => v::not(v::containsCount('foo', 2))->assert('foo bar foo'),
17-
fn(string $message) => expect($message)->toBe('"foo bar foo" must not contain "foo" 2 time(s)'),
18+
test('Contains count times template validation (inverted)', catchAll(
19+
fn() => v::not(v::containsCount('bar', 2))->assert('bar baz bar'),
20+
fn(string $message, string $fullMessage, array $messages) => expect()
21+
->and($message)->toBe('"bar baz bar" must not contain "bar" 2 time(s)')
22+
->and($fullMessage)->toBe('- "bar baz bar" must not contain "bar" 2 time(s)')
23+
->and($messages)->toBe(['notContainsCount' => '"bar baz bar" must not contain "bar" 2 time(s)']),
1824
));
1925

20-
test('Scenario #3', catchFullMessage(
21-
fn() => v::containsCount('foo', 2)->assert(['foo']),
22-
fn(string $fullMessage) => expect($fullMessage)->toBe('- `["foo"]` must contain "foo" 2 time(s)'),
26+
test('Contains count once template validation', catchAll(
27+
fn() => v::containsCount('foo', 1, true)->assert(['foo', 'foo']),
28+
fn(string $message, string $fullMessage, array $messages) => expect()
29+
->and($message)->toBe('`["foo", "foo"]` must contain "foo" only once')
30+
->and($fullMessage)->toBe('- `["foo", "foo"]` must contain "foo" only once')
31+
->and($messages)->toBe(['containsCount' => '`["foo", "foo"]` must contain "foo" only once']),
2332
));
2433

25-
test('Scenario #4', catchFullMessage(
34+
test('Contains count once template validation (inverted)', catchAll(
2635
fn() => v::not(v::containsCount('foo', 1, true))->assert(['foo', 'bar']),
27-
fn(string $fullMessage) => expect($fullMessage)->toBe('- `["foo", "bar"]` must not contain "foo" only once'),
28-
));
29-
30-
test('Scenario #5', catchFullMessage(
31-
fn() => v::containsCount('foo', 1, true)->assert(['foo', 'foo']),
32-
fn(string $fullMessage) => expect($fullMessage)->toBe('- `["foo", "foo"]` must contain "foo" only once'),
36+
fn(string $message, string $fullMessage, array $messages) => expect()
37+
->and($message)->toBe('`["foo", "bar"]` must not contain "foo" only once')
38+
->and($fullMessage)->toBe('- `["foo", "bar"]` must not contain "foo" only once')
39+
->and($messages)->toBe(['notContainsCount' => '`["foo", "bar"]` must not contain "foo" only once']),
3340
));

tests/feature/Validators/CreditCardTest.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,34 @@
77

88
declare(strict_types=1);
99

10-
test('Scenario #1', catchMessage(
11-
fn() => v::creditCard('Discover')->assert(3566002020360505),
12-
fn(string $message) => expect($message)->toBe('3566002020360505 must be a valid Discover credit card number'),
10+
test('Standard credit card template validation', catchAll(
11+
fn() => v::creditCard()->assert(1234567890123456),
12+
fn(string $message, string $fullMessage, array $messages) => expect()
13+
->and($message)->toBe('1234567890123456 must be a valid credit card number')
14+
->and($fullMessage)->toBe('- 1234567890123456 must be a valid credit card number')
15+
->and($messages)->toBe(['creditCard' => '1234567890123456 must be a valid credit card number']),
1316
));
1417

15-
test('Scenario #2', catchMessage(
16-
fn() => v::not(v::creditCard('Visa'))->assert(4024007153361885),
17-
fn(string $message) => expect($message)->toBe('4024007153361885 must not be a valid Visa credit card number'),
18+
test('Standard credit card template validation (inverted)', catchAll(
19+
fn() => v::not(v::creditCard())->assert(5555444433331111),
20+
fn(string $message, string $fullMessage, array $messages) => expect()
21+
->and($message)->toBe('5555444433331111 must not be a valid credit card number')
22+
->and($fullMessage)->toBe('- 5555444433331111 must not be a valid credit card number')
23+
->and($messages)->toBe(['notCreditCard' => '5555444433331111 must not be a valid credit card number']),
1824
));
1925

20-
test('Scenario #3', catchFullMessage(
21-
fn() => v::creditCard('MasterCard')->assert(3566002020360505),
22-
fn(string $fullMessage) => expect($fullMessage)->toBe('- 3566002020360505 must be a valid MasterCard credit card number'),
26+
test('Branched credit card template validation', catchAll(
27+
fn() => v::creditCard('Visa')->assert(3566002020360505),
28+
fn(string $message, string $fullMessage, array $messages) => expect()
29+
->and($message)->toBe('3566002020360505 must be a valid Visa credit card number')
30+
->and($fullMessage)->toBe('- 3566002020360505 must be a valid Visa credit card number')
31+
->and($messages)->toBe(['creditCard' => '3566002020360505 must be a valid Visa credit card number']),
2332
));
2433

25-
test('Scenario #4', catchFullMessage(
26-
fn() => v::not(v::creditCard())->assert(5555444433331111),
27-
fn(string $fullMessage) => expect($fullMessage)->toBe('- 5555444433331111 must not be a valid credit card number'),
34+
test('Branched credit card template validation (inverted)', catchAll(
35+
fn() => v::not(v::creditCard('MasterCard'))->assert(5555555555554444),
36+
fn(string $message, string $fullMessage, array $messages) => expect()
37+
->and($message)->toBe('5555555555554444 must not be a valid MasterCard credit card number')
38+
->and($fullMessage)->toBe('- 5555555555554444 must not be a valid MasterCard credit card number')
39+
->and($messages)->toBe(['notCreditCard' => '5555555555554444 must not be a valid MasterCard credit card number']),
2840
));

tests/feature/Validators/DateTimeTest.php

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,34 @@
99

1010
date_default_timezone_set('UTC');
1111

12-
test('Scenario #1', catchMessage(
12+
test('Standard date/time template validation', catchAll(
1313
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']),
1518
));
1619

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']),
3026
));
3127

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"']),
3534
));
3635

37-
test('Scenario #6', catchMessage(
36+
test('Format date/time template validation (inverted)', catchAll(
3837
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"']),
5042
));

tests/feature/Validators/DirectoryTest.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,18 @@
77

88
declare(strict_types=1);
99

10-
test('Scenario #1', catchMessage(
10+
test('Standard directory template validation', catchAll(
1111
fn() => v::directory()->assert('batman'),
12-
fn(string $message) => expect($message)->toBe('"batman" must be a directory'),
12+
fn(string $message, string $fullMessage, array $messages) => expect()
13+
->and($message)->toBe('"batman" must be a directory')
14+
->and($fullMessage)->toBe('- "batman" must be a directory')
15+
->and($messages)->toBe(['directory' => '"batman" must be a directory']),
1316
));
1417

15-
test('Scenario #2', catchMessage(
18+
test('Standard directory template validation (inverted)', catchAll(
1619
fn() => v::not(v::directory())->assert(dirname('/etc/')),
17-
fn(string $message) => expect($message)->toBe('"/" must not be a directory'),
18-
));
19-
20-
test('Scenario #3', catchFullMessage(
21-
fn() => v::directory()->assert('ppz'),
22-
fn(string $fullMessage) => expect($fullMessage)->toBe('- "ppz" must be a directory'),
23-
));
24-
25-
test('Scenario #4', catchFullMessage(
26-
fn() => v::not(v::directory())->assert(dirname('/etc/')),
27-
fn(string $fullMessage) => expect($fullMessage)->toBe('- "/" must not be a directory'),
20+
fn(string $message, string $fullMessage, array $messages) => expect()
21+
->and($message)->toBe('"/" must not be a directory')
22+
->and($fullMessage)->toBe('- "/" must not be a directory')
23+
->and($messages)->toBe(['notDirectory' => '"/" must not be a directory']),
2824
));

tests/feature/Validators/DomainTest.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,18 @@
77

88
declare(strict_types=1);
99

10-
test('Scenario #1', catchMessage(
10+
test('Standard domain template validation', catchAll(
1111
fn() => v::domain()->assert('batman'),
12-
fn(string $message) => expect($message)->toBe('"batman" must be a valid domain'),
12+
fn(string $message, string $fullMessage, array $messages) => expect()
13+
->and($message)->toBe('"batman" must be a valid domain')
14+
->and($fullMessage)->toBe('- "batman" must be a valid domain')
15+
->and($messages)->toBe(['domain' => '"batman" must be a valid domain']),
1316
));
1417

15-
test('Scenario #2', catchMessage(
18+
test('Standard domain template validation (inverted)', catchAll(
1619
fn() => v::not(v::domain())->assert('r--w.com'),
17-
fn(string $message) => expect($message)->toBe('"r--w.com" must not be a valid domain'),
18-
));
19-
20-
test('Scenario #3', catchFullMessage(
21-
fn() => v::domain()->assert('p-éz-.kk'),
22-
fn(string $fullMessage) => expect($fullMessage)->toBe('- "p-éz-.kk" must be a valid domain'),
23-
));
24-
25-
test('Scenario #4', catchFullMessage(
26-
fn() => v::not(v::domain())->assert('github.com'),
27-
fn(string $fullMessage) => expect($fullMessage)->toBe('- "github.com" must not be a valid domain'),
20+
fn(string $message, string $fullMessage, array $messages) => expect()
21+
->and($message)->toBe('"r--w.com" must not be a valid domain')
22+
->and($fullMessage)->toBe('- "r--w.com" must not be a valid domain')
23+
->and($messages)->toBe(['notDomain' => '"r--w.com" must not be a valid domain']),
2824
));

tests/feature/Validators/EmailTest.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,18 @@
77

88
declare(strict_types=1);
99

10-
test('Scenario #1', catchMessage(
10+
test('Standard email template validation', catchAll(
1111
fn() => v::email()->assert('batman'),
12-
fn(string $message) => expect($message)->toBe('"batman" must be a valid email address'),
12+
fn(string $message, string $fullMessage, array $messages) => expect()
13+
->and($message)->toBe('"batman" must be a valid email address')
14+
->and($fullMessage)->toBe('- "batman" must be a valid email address')
15+
->and($messages)->toBe(['email' => '"batman" must be a valid email address']),
1316
));
1417

15-
test('Scenario #2', catchMessage(
18+
test('Standard email template validation (inverted)', catchAll(
1619
fn() => v::not(v::email())->assert('bruce.wayne@gothancity.com'),
17-
fn(string $message) => expect($message)->toBe('"bruce.wayne@gothancity.com" must not be an email address'),
18-
));
19-
20-
test('Scenario #3', catchFullMessage(
21-
fn() => v::email()->assert('bruce wayne'),
22-
fn(string $fullMessage) => expect($fullMessage)->toBe('- "bruce wayne" must be a valid email address'),
23-
));
24-
25-
test('Scenario #4', catchFullMessage(
26-
fn() => v::not(v::email())->assert('iambatman@gothancity.com'),
27-
fn(string $fullMessage) => expect($fullMessage)->toBe('- "iambatman@gothancity.com" must not be an email address'),
20+
fn(string $message, string $fullMessage, array $messages) => expect()
21+
->and($message)->toBe('"bruce.wayne@gothancity.com" must not be an email address')
22+
->and($fullMessage)->toBe('- "bruce.wayne@gothancity.com" must not be an email address')
23+
->and($messages)->toBe(['notEmail' => '"bruce.wayne@gothancity.com" must not be an email address']),
2824
));

tests/feature/Validators/EvenTest.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,18 @@
77

88
declare(strict_types=1);
99

10-
test('Scenario #1', catchMessage(
10+
test('Standard even template validation', catchAll(
1111
fn() => v::even()->assert(-1),
12-
fn(string $message) => expect($message)->toBe('-1 must be an even number'),
12+
fn(string $message, string $fullMessage, array $messages) => expect()
13+
->and($message)->toBe('-1 must be an even number')
14+
->and($fullMessage)->toBe('- -1 must be an even number')
15+
->and($messages)->toBe(['even' => '-1 must be an even number']),
1316
));
1417

15-
test('Scenario #2', catchFullMessage(
16-
fn() => v::even()->assert(5),
17-
fn(string $fullMessage) => expect($fullMessage)->toBe('- 5 must be an even number'),
18-
));
19-
20-
test('Scenario #3', catchMessage(
21-
fn() => v::not(v::even())->assert(6),
22-
fn(string $message) => expect($message)->toBe('6 must be an odd number'),
23-
));
24-
25-
test('Scenario #4', catchFullMessage(
26-
fn() => v::not(v::even())->assert(8),
27-
fn(string $fullMessage) => expect($fullMessage)->toBe('- 8 must be an odd number'),
18+
test('Standard even template validation (inverted)', catchAll(
19+
fn() => v::not(v::even())->assert(2),
20+
fn(string $message, string $fullMessage, array $messages) => expect()
21+
->and($message)->toBe('2 must be an odd number')
22+
->and($fullMessage)->toBe('- 2 must be an odd number')
23+
->and($messages)->toBe(['notEven' => '2 must be an odd number']),
2824
));

tests/feature/Validators/FileTest.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,18 @@
77

88
declare(strict_types=1);
99

10-
test('Scenario #1', catchMessage(
10+
test('Standard file template validation', catchAll(
1111
fn() => v::file()->assert('tests/fixtures/non-existent.sh'),
12-
fn(string $message) => expect($message)->toBe('"tests/fixtures/non-existent.sh" must be a valid file'),
12+
fn(string $message, string $fullMessage, array $messages) => expect()
13+
->and($message)->toBe('"tests/fixtures/non-existent.sh" must be a valid file')
14+
->and($fullMessage)->toBe('- "tests/fixtures/non-existent.sh" must be a valid file')
15+
->and($messages)->toBe(['file' => '"tests/fixtures/non-existent.sh" must be a valid file']),
1316
));
1417

15-
test('Scenario #2', catchMessage(
18+
test('Standard file template validation (inverted)', catchAll(
1619
fn() => v::not(v::file())->assert('tests/fixtures/valid-image.png'),
17-
fn(string $message) => expect($message)->toBe('"tests/fixtures/valid-image.png" must be an invalid file'),
18-
));
19-
20-
test('Scenario #3', catchFullMessage(
21-
fn() => v::file()->assert('tests/fixtures/non-existent.sh'),
22-
fn(string $fullMessage) => expect($fullMessage)->toBe('- "tests/fixtures/non-existent.sh" must be a valid file'),
23-
));
24-
25-
test('Scenario #4', catchFullMessage(
26-
fn() => v::not(v::file())->assert('tests/fixtures/valid-image.png'),
27-
fn(string $fullMessage) => expect($fullMessage)->toBe('- "tests/fixtures/valid-image.png" must be an invalid file'),
20+
fn(string $message, string $fullMessage, array $messages) => expect()
21+
->and($message)->toBe('"tests/fixtures/valid-image.png" must be an invalid file')
22+
->and($fullMessage)->toBe('- "tests/fixtures/valid-image.png" must be an invalid file')
23+
->and($messages)->toBe(['notFile' => '"tests/fixtures/valid-image.png" must be an invalid file']),
2824
));

0 commit comments

Comments
 (0)