diff --git a/src/Illuminate/Http/Middleware/ValidatePostSize.php b/src/Illuminate/Http/Middleware/ValidatePostSize.php index bfa620a85f46..8b3519c92842 100644 --- a/src/Illuminate/Http/Middleware/ValidatePostSize.php +++ b/src/Illuminate/Http/Middleware/ValidatePostSize.php @@ -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); diff --git a/tests/Integration/Http/ResourceTest.php b/tests/Integration/Http/ResourceTest.php index 56d2e5fd3aab..a0ec135b26b7 100644 --- a/tests/Integration/Http/ResourceTest.php +++ b/tests/Integration/Http/ResourceTest.php @@ -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 @@ -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()