Skip to content

Commit 9e5c3f6

Browse files
committed
fix: Use Illuminate\Http\UploadedFile to avoid conversion and ignore test property
1 parent 47fa95d commit 9e5c3f6

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

src/Drivers/LaravelHttpServer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace Pest\Browser\Drivers;
66

7-
use const UPLOAD_ERR_OK;
8-
97
use Amp\ByteStream\ReadableResourceStream;
108
use Amp\Http\Cookie\RequestCookie;
119
use Amp\Http\Server\DefaultErrorHandler;
@@ -21,6 +19,7 @@
2119
use Illuminate\Contracts\Http\Kernel as HttpKernel;
2220
use Illuminate\Foundation\Testing\Concerns\WithoutExceptionHandlingHandler;
2321
use Illuminate\Http\Request;
22+
use Illuminate\Http\UploadedFile;
2423
use Illuminate\Routing\UrlGenerator;
2524
use Illuminate\Support\Uri;
2625
use Pest\Browser\Contracts\HttpServer;
@@ -29,7 +28,6 @@
2928
use Pest\Browser\GlobalState;
3029
use Pest\Browser\Playwright\Playwright;
3130
use Psr\Log\NullLogger;
32-
use Symfony\Component\HttpFoundation\File\UploadedFile;
3331
use Symfony\Component\Mime\MimeTypes;
3432
use Throwable;
3533

tests/Unit/Drivers/Laravel/LaravelHttpServerTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,58 @@
120120
$page->assertSee('Empty file: ');
121121
});
122122

123+
it('validates multipart pdf upload metadata', function (): void {
124+
Route::get('favicon.ico', static fn (): string => '');
125+
Route::get('/', static fn (): string => "
126+
<html>
127+
<head></head>
128+
<body>
129+
<form method='post' enctype='multipart/form-data' action='/form'>
130+
<label for='pdf-file'>PDF file</label>
131+
<input id='pdf-file' type='file' name='pdf_file'>
132+
133+
<button type='submit'>Send</button>
134+
</form>
135+
</body>
136+
</html>
137+
");
138+
139+
$expectedPdfSize = filesize(fixture('example.pdf'));
140+
assert($expectedPdfSize !== false);
141+
142+
Route::post('/form', static function (Request $request) use ($expectedPdfSize): string {
143+
$pdf = $request->file('pdf_file');
144+
$name = $pdf?->getClientOriginalName() ?? '';
145+
$extension = $pdf?->getClientOriginalExtension() ?? '';
146+
$valid = $pdf?->isValid() ? 'yes' : 'no';
147+
$size = (string) ($pdf?->getSize() ?? '');
148+
149+
return "
150+
<html>
151+
<head></head>
152+
<body>
153+
<p>Name: $name</p>
154+
<p>Extension: $extension</p>
155+
<p>Valid: $valid</p>
156+
<p>Size: $size</p>
157+
<p>Expected size: $expectedPdfSize</p>
158+
</body>
159+
</html>
160+
";
161+
});
162+
163+
$page = visit('/');
164+
165+
$page->attach('PDF file', fixture('example.pdf'));
166+
$page->submit();
167+
168+
$page->assertSee('Name: example.pdf')
169+
->assertSee('Extension: pdf')
170+
->assertSee('Valid: yes')
171+
->assertSee('Expected size: '.$expectedPdfSize)
172+
->assertSee('Size: '.$expectedPdfSize);
173+
});
174+
123175
it('parse a multipart body with nested fields', function (): void {
124176
Route::get('/', static fn (): string => "
125177
<html>

0 commit comments

Comments
 (0)