Skip to content

Commit ee4f784

Browse files
committed
minor symfony#57763 [HttpFoundation] Remove always false condition in BinaryFileResponse (alexandre-daubois)
This PR was merged into the 7.2 branch. Discussion ---------- [HttpFoundation] Remove always false condition in `BinaryFileResponse` | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT The condition is always false because the parameter is int typed. Passing `PHP_INT_MAX + 1` will result on a cast to float, making PHP complain about the parameter type. Also, the exception raised should better be an `InvalidArgmuentException` to me, instead of a logic one. I moved in this PR the test covering `setChunkSize` originally proposed in symfony#57714. Commits ------- 13fca6a [HttpFoundation] Remove always false condition in `BinaryFileResponse`
2 parents a5a1186 + 13fca6a commit ee4f784

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ public function getFile(): File
110110
*/
111111
public function setChunkSize(int $chunkSize): static
112112
{
113-
if ($chunkSize < 1 || $chunkSize > \PHP_INT_MAX) {
114-
throw new \LogicException('The chunk size of a BinaryFileResponse cannot be less than 1 or greater than PHP_INT_MAX.');
113+
if ($chunkSize < 1) {
114+
throw new \InvalidArgumentException('The chunk size of a BinaryFileResponse cannot be less than 1.');
115115
}
116116

117117
$this->chunkSize = $chunkSize;

src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,4 +455,14 @@ public function testCreateFromTemporaryFile()
455455
$string = ob_get_clean();
456456
$this->assertSame('foo,bar', $string);
457457
}
458+
459+
public function testSetChunkSizeTooSmall()
460+
{
461+
$response = new BinaryFileResponse(__DIR__.'/File/Fixtures/test.gif');
462+
463+
$this->expectException(\InvalidArgumentException::class);
464+
$this->expectExceptionMessage('The chunk size of a BinaryFileResponse cannot be less than 1.');
465+
466+
$response->setChunkSize(0);
467+
}
458468
}

0 commit comments

Comments
 (0)