Skip to content

Commit 57af5c3

Browse files
[11.x] Provide an error message for PostTooLargeException (#53301)
* [11.x] Provide an error message for PostTooLargeException * Improve test This test was producing a false positive where ->server('CONTENT_LENGTH') was returning an array. There is no need to mock Request here. I've also added a pass to ensure it works * Assert Message
1 parent 24fde3b commit 57af5c3

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/Illuminate/Http/Middleware/ValidatePostSize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function handle($request, Closure $next)
2121
$max = $this->getPostMaxSize();
2222

2323
if ($max > 0 && $request->server('CONTENT_LENGTH') > $max) {
24-
throw new PostTooLargeException;
24+
throw new PostTooLargeException('The POST data is too large.');
2525
}
2626

2727
return $next($request);

tests/Integration/Http/ResourceTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
use Illuminate\Tests\Integration\Http\Fixtures\SerializablePostResource;
4747
use Illuminate\Tests\Integration\Http\Fixtures\Subscription;
4848
use LogicException;
49-
use Mockery as m;
5049
use Orchestra\Testbench\TestCase;
5150

5251
class ResourceTest extends TestCase
@@ -1503,12 +1502,16 @@ public function work()
15031502

15041503
public function testPostTooLargeException()
15051504
{
1505+
$request = new Request(server: ['CONTENT_LENGTH' => '4']);
1506+
$post = new ValidatePostSize;
1507+
$post->handle($request, fn () => null);
1508+
15061509
$this->expectException(PostTooLargeException::class);
1510+
$this->expectExceptionMessage('The POST data is too large.');
15071511

1508-
$request = m::mock(Request::class, ['server' => ['CONTENT_LENGTH' => '2147483640']]);
1512+
$request = new Request(server: ['CONTENT_LENGTH' => '2147483640']);
15091513
$post = new ValidatePostSize;
1510-
$post->handle($request, function () {
1511-
});
1514+
$post->handle($request, fn () => null);
15121515
}
15131516

15141517
public function testLeadingMergeKeyedValueIsMergedCorrectlyWhenFirstValueIsMissing()

0 commit comments

Comments
 (0)