Skip to content

Commit 6b63561

Browse files
committed
Add additional download tests with partial file having same or larger file size as source
1 parent d8808da commit 6b63561

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,24 @@ public function testDownloadRange()
692692
$filesize - 3,
693693
$filesize - 2,
694694
$filesize - 1,
695+
696+
// A partial temporary file having the exact same file size as the complete source file should only
697+
// occur under certain circumstances (almost never). When the download successfully completed, the
698+
// temporary file should have been moved to the download destination save path. However, it is possible
699+
// that a larger file download was interrupted after which the source file was updated and now has the
700+
// exact same file size as the partial temporary. When resuming the download, the range is now
701+
// unsatisfiable as the first byte position exceeds the available range. The entire file should be
702+
// downloaded again.
703+
$filesize - 0,
704+
705+
// A partial temporary file having a larger file size than the complete source file should only occur
706+
// under certain circumstances. This is possible when a download was interrupted after which the source
707+
// file was updated with a smaller file. When resuming the download, the range is now unsatisfiable as
708+
// the first byte position exceeds the the available range. The entire file should be downloaded again.
709+
$filesize + 1,
710+
$filesize + 2,
711+
$filesize + 3,
712+
695713
) as $length) {
696714

697715
$source = Test::TEST_URL;
@@ -749,10 +767,12 @@ public function testDownloadRange()
749767
$this->assertEquals($expected_bytes_downloaded, $bytes_downloaded);
750768
}
751769
$this->assertEquals($expected_http_status_code, $curl->httpStatusCode);
752-
$this->assertEquals($filesize, filesize($destination));
753770

754-
unlink($destination);
755-
$this->assertFalse(file_exists($destination));
771+
if (!$curl->error) {
772+
$this->assertEquals($filesize, filesize($destination));
773+
unlink($destination);
774+
$this->assertFalse(file_exists($destination));
775+
}
756776
}
757777

758778
// Remove server file.

0 commit comments

Comments
 (0)