forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSizeStringRuleTest.php
More file actions
57 lines (50 loc) · 1.12 KB
/
FileSizeStringRuleTest.php
File metadata and controls
57 lines (50 loc) · 1.12 KB
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
<?php
use App\Rules\FileSizeString;
use Illuminate\Support\Facades\Validator;
test('validates correct file size strings', function (string $size) {
$validator = Validator::make(
['size' => $size],
['size' => new FileSizeString]
);
expect($validator->passes())->toBeTrue();
})->with([
'100 B',
'100B',
'1 KB',
'1KB',
'100 MB',
'100MB',
'1 GB',
'1GB',
'2 TB',
'2TB',
'1.5 MB',
'2.5 GB',
'100 mb',
'1 gb',
]);
test('rejects invalid file size strings', function (string|int $size) {
$validator = Validator::make(
['size' => $size],
['size' => new FileSizeString]
);
expect($validator->fails())->toBeTrue();
})->with([
'invalid',
'100',
'MB',
'100 XB',
'100 ZB',
'abc MB',
'',
' ',
123,
]);
test('provides meaningful error message', function () {
$validator = Validator::make(
['file_size' => 'invalid'],
['file_size' => new FileSizeString]
);
expect($validator->fails())->toBeTrue();
expect($validator->errors()->first('file_size'))->toContain('valid file size');
});