Skip to content

Commit d78460e

Browse files
gr8manmichalsn
andcommitted
Update tests/system/HTTP/ResponseTest.php
Co-authored-by: Michal Sniatala <michal@sniatala.pl>
1 parent c563c13 commit d78460e

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

‎tests/system/HTTP/ResponseTest.php‎

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -498,33 +498,37 @@ public function testGetDownloadResponseByExtremeFilePath(): void
498498
{
499499
$response = new Response(new App());
500500

501+
$tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'ci4_test_dir';
502+
@mkdir($tempDir);
501503
$tempDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'ci4_test_dir_' . bin2hex(random_bytes(8));
502-
503504
$this->assertTrue(mkdir($tempDir));
504505
$extremeName = 'my_extreme_file_!@#$%.txt';
505506
$extremePath = $tempDir . DIRECTORY_SEPARATOR . $extremeName;
506-
file_put_contents($extremePath, 'extreme data');
507507

508-
$actual = $response->download($extremePath, null);
508+
try {
509+
file_put_contents($extremePath, 'extreme data');
509510

510-
$this->assertInstanceOf(DownloadResponse::class, $actual);
511-
$actual->buildHeaders();
511+
$actual = $response->download($extremePath, null);
512512

513-
$expectedBasename = basename($extremePath);
514-
$this->assertSame(
515-
'attachment; filename="' . addslashes($expectedBasename) . '"; filename*=UTF-8\'\'' . rawurlencode($expectedBasename),
516-
$actual->getHeaderLine('Content-Disposition'),
517-
);
513+
$this->assertInstanceOf(DownloadResponse::class, $actual);
514+
$actual->buildHeaders();
518515

519-
ob_start();
520-
$actual->sendBody();
521-
$actualOutput = ob_get_contents();
522-
ob_end_clean();
516+
$expectedFilename = $extremeName;
517+
$this->assertSame(
518+
'attachment; filename="' . addslashes($expectedFilename) . '"; filename*=UTF-8\'\'' . rawurlencode($expectedFilename),
519+
$actual->getHeaderLine('Content-Disposition'),
520+
);
523521

524-
$this->assertSame('extreme data', $actualOutput);
522+
ob_start();
523+
$actual->sendBody();
524+
$actualOutput = ob_get_contents();
525+
ob_end_clean();
525526

526-
unlink($extremePath);
527-
rmdir($tempDir);
527+
$this->assertSame('extreme data', $actualOutput);
528+
} finally {
529+
@unlink($extremePath);
530+
@rmdir($tempDir);
531+
}
528532
}
529533

530534
public function testVagueDownload(): void

0 commit comments

Comments
 (0)