Skip to content

Commit ab58bbe

Browse files
committed
test(FeatureTest): Add image upload tests with timezone and locale
- Add tests for image uploads including multiple formats - Introduce timezone and locale settings in the ApplicationCollector - Update snapshot to reflect the new request file structure - Ensure accurate testing of proactive report handling
1 parent 04eb873 commit ab58bbe

File tree

4 files changed

+96
-11
lines changed

4 files changed

+96
-11
lines changed

src/Collectors/ApplicationCollector.php

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function collect(): array
3737
'In Console' => $this->container->runningInConsole(),
3838
'Debug Mode' => $this->container->hasDebugModeEnabled(),
3939
'Maintenance Mode' => $this->container->isDownForMaintenance(),
40+
'Timezone' => config('app.timezone'),
41+
'Locale' => config('app.locale'),
4042
];
4143
}
4244
}

src/Collectors/RequestFileCollector.php

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ public function __construct(private Request $request) {}
2323

2424
/**
2525
* @noinspection CallableParameterUseCaseInTypeContextInspection
26+
*
27+
* ```json
28+
* {
29+
* "name": "images.jpeg",
30+
* "full_path": "images.jpeg",
31+
* "type": "image/jpeg",
32+
* "tmp_name": "/private/var/tmp/phpz7mx94",
33+
* "error": 0,
34+
* "size": 2075
35+
* }
36+
* ```
2637
*/
2738
public function collect(): array
2839
{

tests/FeatureTest.php

+42-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,51 @@
2121
use Illuminate\Http\UploadedFile;
2222

2323
it('can proactive report exception', function (): void {
24+
$jpgFile = UploadedFile::fake()->image('jpg.jpg');
25+
$pngFile = UploadedFile::fake()->image('png.png');
2426
$this
2527
->post('proactive-report-exception?foo=bar', [
2628
'bar' => 'baz',
2729
'password' => 'password',
28-
'file' => new UploadedFile(__FILE__, basename(__FILE__)),
30+
'image' => new UploadedFile(
31+
path: $jpgFile->path(),
32+
originalName: $jpgFile->getBasename(),
33+
mimeType: $jpgFile->getMimeType(),
34+
error: null,
35+
test: true
36+
),
37+
'images_list' => [
38+
new UploadedFile(
39+
path: $jpgFile->path(),
40+
originalName: $jpgFile->getBasename(),
41+
mimeType: $jpgFile->getMimeType(),
42+
error: \UPLOAD_ERR_INI_SIZE,
43+
test: true
44+
),
45+
new UploadedFile(
46+
path: $pngFile->path(),
47+
originalName: $pngFile->getBasename(),
48+
mimeType: $pngFile->getMimeType(),
49+
error: \UPLOAD_ERR_PARTIAL,
50+
test: true
51+
),
52+
],
53+
'images_map' => [
54+
'jpg' => new UploadedFile(
55+
path: $jpgFile->path(),
56+
originalName: $jpgFile->getBasename(),
57+
mimeType: $jpgFile->getMimeType(),
58+
error: \UPLOAD_ERR_CANT_WRITE,
59+
test: true
60+
),
61+
'png' => new UploadedFile(
62+
path: $pngFile->path(),
63+
originalName: $pngFile->getBasename(),
64+
mimeType: $pngFile->getMimeType(),
65+
error: \UPLOAD_ERR_EXTENSION,
66+
test: true
67+
),
68+
],
2969
])
3070
->assertOk();
3171
})->group(__DIR__, __FILE__);
@@ -35,7 +75,7 @@
3575
->post('automatic-report-exception?foo=bar', [
3676
'bar' => 'baz',
3777
'password' => 'password',
38-
'file' => new UploadedFile(__FILE__, basename(__FILE__)),
78+
// 'file' => new UploadedFile(__FILE__, basename(__FILE__)),
3979
])
4080
->assertServerError();
4181
})->group(__DIR__, __FILE__);

tests/__snapshots__/FeatureTest__it_can_proactive_report_exception__1.json

+41-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
22
"Application": {
3-
"Time": "2025-03-23 10:07:18",
3+
"Time": "2025-03-23 11:38:11",
44
"Name": "Laravel",
55
"Version": "9.52.20",
66
"PHP Version": "8.0.30",
77
"Environment": "testing",
88
"In Console": true,
99
"Debug Mode": false,
10-
"Maintenance Mode": false
10+
"Maintenance Mode": false,
11+
"Timezone": "UTC",
12+
"Locale": "en"
1113
},
1214
"Chore": {},
1315
"Exception Basic": {
@@ -30,7 +32,7 @@
3032
},
3133
"Exception Trace": {
3234
"1": "#1 \/Users\/yaozm\/Documents\/develop\/laravel-exception-notify\/tests\/TestCase.php(172): tap(Object(Illuminate\\Http\\Response), Object(Closure))",
33-
"29": "#29 \/Users\/yaozm\/Documents\/develop\/laravel-exception-notify\/tests\/FeatureTest.php(28): Orchestra\\Testbench\\TestCase->post('proactive-repor...', Array)",
35+
"29": "#29 \/Users\/yaozm\/Documents\/develop\/laravel-exception-notify\/tests\/FeatureTest.php(66): Orchestra\\Testbench\\TestCase->post('proactive-repor...', Array)",
3436
"30": "#30 [internal function]: P\\Tests\\FeatureTest->{closure}()",
3537
"32": "#32 [internal function]: P\\Tests\\FeatureTest->Pest\\Factories\\{closure}()",
3638
"49": "#49 {main}"
@@ -41,14 +43,42 @@
4143
"Method": "POST",
4244
"Controller Action": "Closure",
4345
"Memory": "52.50 MB",
44-
"Duration": "19.94 ms"
46+
"Duration": "17.2 ms"
4547
},
4648
"Request File": {
47-
"file": {
48-
"Name": "FeatureTest.php",
49-
"Type": "text\/x-php",
49+
"image": {
50+
"Name": "phpYPUAYe",
51+
"Type": "image\/jpeg",
5052
"Error": 0,
51-
"Size": "1.27 KB"
53+
"Size": "695 B"
54+
},
55+
"images_list": {
56+
"0": {
57+
"Name": "phpYPUAYe",
58+
"Type": "image\/jpeg",
59+
"Error": 1,
60+
"Size": "695 B"
61+
},
62+
"1": {
63+
"Name": "phpFLSHcG",
64+
"Type": "image\/png",
65+
"Error": 3,
66+
"Size": "91 B"
67+
}
68+
},
69+
"images_map": {
70+
"jpg": {
71+
"Name": "phpYPUAYe",
72+
"Type": "image\/jpeg",
73+
"Error": 7,
74+
"Size": "695 B"
75+
},
76+
"png": {
77+
"Name": "phpFLSHcG",
78+
"Type": "image\/png",
79+
"Error": 8,
80+
"Size": "91 B"
81+
}
5282
}
5383
},
5484
"Request Header": {
@@ -61,7 +91,9 @@
6191
},
6292
"Request Post": {
6393
"bar": "baz",
64-
"password": "******"
94+
"password": "******",
95+
"images_list": {},
96+
"images_map": {}
6597
},
6698
"Request Query": {
6799
"foo": "bar"

0 commit comments

Comments
 (0)