summaryrefslogtreecommitdiff
path: root/tests/LargeFileTest.php
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2018-09-02 18:58:32 -0400
committerPaul Duncan <pabs@pablotron.org>2018-09-03 09:54:47 -0400
commite4850cba6fd67a6d4d9d8c969281e57447c17fd9 (patch)
tree29fb04954bdabde80a2208d6fa88c575cc7ed802 /tests/LargeFileTest.php
parentd70e1b519d27e5b0090412c566bee79d57f7838e (diff)
downloadzipstream-php-e4850cba6fd67a6d4d9d8c969281e57447c17fd9.tar.bz2
zipstream-php-e4850cba6fd67a6d4d9d8c969281e57447c17fd9.zip
add tests/ and composer test script
Diffstat (limited to 'tests/LargeFileTest.php')
-rw-r--r--tests/LargeFileTest.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/LargeFileTest.php b/tests/LargeFileTest.php
new file mode 100644
index 0000000..c271b47
--- /dev/null
+++ b/tests/LargeFileTest.php
@@ -0,0 +1,35 @@
+<?php
+declare(strict_types = 1);
+
+namespace Pablotron\ZipStream\Tests;
+
+use \PHPUnit\Framework\TestCase;
+use \Pablotron\ZipStream\ZipStream;
+
+final class LargeFileTest extends BaseTestCase {
+ public function testCreateLargeFile() : void {
+ # build 4M string
+ $chunk_size = (1 << 22);
+ $num_chunks = 1025;
+
+ # calculate expected size
+ $expected_size = $chunk_size * $num_chunks;
+
+ $this->with_temp_zip(function(ZipStream &$zip) use ($chunk_size, $num_chunks) {
+ $zip->add('hello.txt', function($e) use ($chunk_size, $num_chunks) {
+ # build chunk
+ $data = str_repeat('x', $chunk_size);
+
+ # repeatedly write chunk
+ foreach (range(0, $num_chunks - 1) as $i) {
+ $e->write($data);
+ }
+ });
+ }, function($zip_path) use ($expected_size) {
+ $zip = $this->open_archive($zip_path);
+ $st = $zip->statName('hello.txt');
+
+ $this->assertEquals($expected_size, $st['size']);
+ });
+ }
+};