Skip to content

Commit

Permalink
[11.x] Provide an error message for PostTooLargeException (#53301)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
patrickomeara authored Oct 29, 2024
1 parent 24fde3b commit 57af5c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Http/Middleware/ValidatePostSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function handle($request, Closure $next)
$max = $this->getPostMaxSize();

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

return $next($request);
Expand Down
11 changes: 7 additions & 4 deletions tests/Integration/Http/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
use Illuminate\Tests\Integration\Http\Fixtures\SerializablePostResource;
use Illuminate\Tests\Integration\Http\Fixtures\Subscription;
use LogicException;
use Mockery as m;
use Orchestra\Testbench\TestCase;

class ResourceTest extends TestCase
Expand Down Expand Up @@ -1503,12 +1502,16 @@ public function work()

public function testPostTooLargeException()
{
$request = new Request(server: ['CONTENT_LENGTH' => '4']);
$post = new ValidatePostSize;
$post->handle($request, fn () => null);

$this->expectException(PostTooLargeException::class);
$this->expectExceptionMessage('The POST data is too large.');

$request = m::mock(Request::class, ['server' => ['CONTENT_LENGTH' => '2147483640']]);
$request = new Request(server: ['CONTENT_LENGTH' => '2147483640']);
$post = new ValidatePostSize;
$post->handle($request, function () {
});
$post->handle($request, fn () => null);
}

public function testLeadingMergeKeyedValueIsMergedCorrectlyWhenFirstValueIsMissing()
Expand Down

0 comments on commit 57af5c3

Please sign in to comment.