Test Class for the Main ZipStream CLass.
More...
Test Class for the Main ZipStream CLass.
Definition at line 18 of file ZipStreamTest.php.
◆ addLargeFileFileFromPath()
ZipStreamTest\ZipStreamTest::addLargeFileFileFromPath |
( |
|
$method, |
|
|
|
$zeroHeader, |
|
|
|
$zip64 |
|
) |
| |
|
protected |
Definition at line 369 of file ZipStreamTest.php.
References $files, $i, PHPMailer\PHPMailer\$options, GuzzleHttp\Psr7\$stream, and $tmpDir.
375 $options->setLargeFileMethod($method);
377 $options->setZeroHeader($zeroHeader);
383 for (
$i = 0;
$i <= 10000;
$i++) {
384 fwrite($streamExample, sha1((
string)
$i));
385 if (
$i % 100 === 0) {
386 fwrite($streamExample,
"\n");
389 fclose($streamExample);
390 $shaExample = sha1_file($tmpExample);
391 $zip->addFileFromPath(
'sample.txt', $tmpExample);
400 $this->assertEquals(array(
'sample.txt'),
$files);
402 $this->assertEquals(sha1_file(
$tmpDir .
'/sample.txt'), $shaExample,
"SHA-1 Mismatch Method: {$method}");
validateAndExtractZip($tmp)
$stream
PHP stream implementation.
getRecursiveFileList(string $path)
◆ getRecursiveFileList()
ZipStreamTest\ZipStreamTest::getRecursiveFileList |
( |
string |
$path | ) |
|
|
protected |
- Parameters
-
- Returns
- string[]
Definition at line 134 of file ZipStreamTest.php.
References $data, and $files.
140 $pathLen = strlen(
$path);
141 foreach (
$files as $file) {
142 $filePath = $file->getRealPath();
143 if (!is_dir($filePath)) {
144 $data[] = substr($filePath, $pathLen + 1);
◆ getTmpDir()
ZipStreamTest\ZipStreamTest::getTmpDir |
( |
| ) |
|
|
protected |
Definition at line 121 of file ZipStreamTest.php.
123 $tmp = tempnam(sys_get_temp_dir(),
'zipstreamtest');
125 mkdir($tmp)
or $this->fail(
'Failed to make directory');
◆ getTmpFileStream()
ZipStreamTest\ZipStreamTest::getTmpFileStream |
( |
| ) |
|
|
protected |
◆ testAddFile()
ZipStreamTest\ZipStreamTest::testAddFile |
( |
| ) |
|
Definition at line 60 of file ZipStreamTest.php.
References $files, PHPMailer\PHPMailer\$options, GuzzleHttp\Psr7\$stream, and $tmpDir.
69 $zip->addFile(
'sample.txt',
'Sample String Data');
70 $zip->addFile(
'test/sample.txt',
'More Simple Sample Data');
78 $this->assertEquals([
'sample.txt',
'test/sample.txt'],
$files);
80 $this->assertStringEqualsFile(
$tmpDir .
'/sample.txt',
'Sample String Data');
81 $this->assertStringEqualsFile(
$tmpDir .
'/test/sample.txt',
'More Simple Sample Data');
validateAndExtractZip($tmp)
$stream
PHP stream implementation.
getRecursiveFileList(string $path)
◆ testAddFileFromPath()
ZipStreamTest\ZipStreamTest::testAddFileFromPath |
( |
| ) |
|
Definition at line 285 of file ZipStreamTest.php.
References $files, PHPMailer\PHPMailer\$options, GuzzleHttp\Psr7\$stream, and $tmpDir.
295 fwrite($streamExample,
'Sample String Data');
296 fclose($streamExample);
297 $zip->addFileFromPath(
'sample.txt', $tmpExample);
300 fwrite($streamExample,
'More Simple Sample Data');
301 fclose($streamExample);
302 $zip->addFileFromPath(
'test/sample.txt', $tmpExample);
310 $this->assertEquals(array(
'sample.txt',
'test/sample.txt'),
$files);
312 $this->assertStringEqualsFile(
$tmpDir .
'/sample.txt',
'Sample String Data');
313 $this->assertStringEqualsFile(
$tmpDir .
'/test/sample.txt',
'More Simple Sample Data');
validateAndExtractZip($tmp)
$stream
PHP stream implementation.
getRecursiveFileList(string $path)
◆ testAddFileFromPathWithStorageMethod()
ZipStreamTest\ZipStreamTest::testAddFileFromPathWithStorageMethod |
( |
| ) |
|
Definition at line 316 of file ZipStreamTest.php.
References PHPMailer\PHPMailer\$options, GuzzleHttp\Psr7\$stream, ZipStream\Option\Method\DEFLATE, and ZipStream\Option\Method\STORE.
325 $fileOptions =
new FileOptions();
329 fwrite($streamExample,
'Sample String Data');
330 fclose($streamExample);
331 $zip->addFileFromPath(
'sample.txt', $tmpExample, $fileOptions);
334 fwrite($streamExample,
'More Simple Sample Data');
335 fclose($streamExample);
336 $zip->addFileFromPath(
'test/sample.txt', $tmpExample);
341 $zipArch = new \ZipArchive();
342 $zipArch->open($tmp);
344 $sample1 = $zipArch->statName(
'sample.txt');
347 $sample2 = $zipArch->statName(
'test/sample.txt');
$stream
PHP stream implementation.
◆ testAddFileFromPsr7Stream()
ZipStreamTest\ZipStreamTest::testAddFileFromPsr7Stream |
( |
| ) |
|
Definition at line 481 of file ZipStreamTest.php.
References $files, PHPMailer\PHPMailer\$options, $response, GuzzleHttp\Psr7\$stream, $tmpDir, and ZipStream\Option\Method\STORE.
490 $body =
'Sample String Data';
491 $response =
new Response(200, [], $body);
493 $fileOptions =
new FileOptions();
496 $zip->addFileFromPsr7Stream(
'sample.json',
$response->getBody(), $fileOptions);
503 $this->assertEquals(array(
'sample.json'),
$files);
504 $this->assertStringEqualsFile(
$tmpDir .
'/sample.json', $body);
validateAndExtractZip($tmp)
$stream
PHP stream implementation.
getRecursiveFileList(string $path)
◆ testAddFileFromPsr7StreamWithFileSizeSet()
ZipStreamTest\ZipStreamTest::testAddFileFromPsr7StreamWithFileSizeSet |
( |
| ) |
|
Definition at line 507 of file ZipStreamTest.php.
References $files, PHPMailer\PHPMailer\$options, $response, GuzzleHttp\Psr7\$stream, $tmpDir, and ZipStream\Option\Method\STORE.
516 $body =
'Sample String Data';
517 $fileSize = strlen($body);
519 $fakePadding =
"\0\0\0\0\0\0";
520 $response =
new Response(200, [], $body . $fakePadding);
522 $fileOptions =
new FileOptions();
524 $fileOptions->setSize($fileSize);
525 $zip->addFileFromPsr7Stream(
'sample.json',
$response->getBody(), $fileOptions);
532 $this->assertEquals(array(
'sample.json'),
$files);
533 $this->assertStringEqualsFile(
$tmpDir .
'/sample.json', $body);
validateAndExtractZip($tmp)
$stream
PHP stream implementation.
getRecursiveFileList(string $path)
◆ testAddFileFromStream()
ZipStreamTest\ZipStreamTest::testAddFileFromStream |
( |
| ) |
|
Definition at line 405 of file ZipStreamTest.php.
References $files, PHPMailer\PHPMailer\$options, GuzzleHttp\Psr7\$stream, $tmpDir, and ZipStream\Option\Method\STORE.
417 $streamExample =
fopen(__FILE__,
'rb');
418 $zip->addFileFromStream(
'sample.txt', $streamExample);
421 $fileOptions =
new FileOptions();
424 $streamExample2 =
fopen(
'php://temp',
'wb+');
425 fwrite($streamExample2,
'More Simple Sample Data');
426 rewind($streamExample2);
427 $zip->addFileFromStream(
'test/sample.txt', $streamExample2, $fileOptions);
436 $this->assertEquals(array(
'sample.txt',
'test/sample.txt'),
$files);
438 $this->assertStringEqualsFile(__FILE__, file_get_contents(
$tmpDir .
'/sample.txt'));
439 $this->assertStringEqualsFile(
$tmpDir .
'/test/sample.txt',
'More Simple Sample Data');
validateAndExtractZip($tmp)
$stream
PHP stream implementation.
getRecursiveFileList(string $path)
◆ testAddFileFromStreamWithStorageMethod()
ZipStreamTest\ZipStreamTest::testAddFileFromStreamWithStorageMethod |
( |
| ) |
|
Definition at line 442 of file ZipStreamTest.php.
References PHPMailer\PHPMailer\$options, GuzzleHttp\Psr7\$stream, ZipStream\Option\Method\DEFLATE, and ZipStream\Option\Method\STORE.
451 $fileOptions =
new FileOptions();
454 $streamExample =
fopen(
'php://temp',
'wb+');
455 fwrite($streamExample,
'Sample String Data');
456 rewind($streamExample);
457 $zip->addFileFromStream(
'sample.txt', $streamExample, $fileOptions);
460 $streamExample2 =
fopen(
'php://temp',
'bw+');
461 fwrite($streamExample2,
'More Simple Sample Data');
462 rewind($streamExample2);
463 $zip->addFileFromStream(
'test/sample.txt', $streamExample2);
469 $zipArch = new \ZipArchive();
470 $zipArch->open($tmp);
472 $sample1 = $zipArch->statName(
'sample.txt');
475 $sample2 = $zipArch->statName(
'test/sample.txt');
$stream
PHP stream implementation.
◆ testAddFileNonUtf8NameUtfComment()
ZipStreamTest\ZipStreamTest::testAddFileNonUtf8NameUtfComment |
( |
| ) |
|
◆ testAddFileUtf8NameComment()
ZipStreamTest\ZipStreamTest::testAddFileUtf8NameComment |
( |
| ) |
|
Definition at line 153 of file ZipStreamTest.php.
References $comment, $files, $name, PHPMailer\PHPMailer\$options, GuzzleHttp\Psr7\$stream, and $tmpDir.
162 $name =
'árvíztűrő tükörfúrógép.txt';
163 $content =
'Sample String Data';
165 'Filename has every special characters ' .
166 'from Hungarian language in lowercase. ' .
167 'In uppercase: ÁÍŰŐÜÖÚÓÉ';
169 $fileOptions =
new FileOptions();
172 $zip->addFile(
$name, $content, $fileOptions);
180 $this->assertStringEqualsFile(
$tmpDir .
'/' .
$name, $content);
182 $zipArch = new \ZipArchive();
183 $zipArch->open($tmp);
184 $this->assertEquals(
$comment, $zipArch->getCommentName(
$name));
validateAndExtractZip($tmp)
$stream
PHP stream implementation.
getRecursiveFileList(string $path)
◆ testAddFileUtf8NameNonUtfComment()
ZipStreamTest\ZipStreamTest::testAddFileUtf8NameNonUtfComment |
( |
| ) |
|
◆ testAddFileWithStorageMethod()
ZipStreamTest\ZipStreamTest::testAddFileWithStorageMethod |
( |
| ) |
|
◆ testAddLargeFileFromPath()
ZipStreamTest\ZipStreamTest::testAddLargeFileFromPath |
( |
| ) |
|
◆ testCreateArchiveWithFlushOptionSet()
ZipStreamTest\ZipStreamTest::testCreateArchiveWithFlushOptionSet |
( |
| ) |
|
Definition at line 536 of file ZipStreamTest.php.
References $files, PHPMailer\PHPMailer\$options, GuzzleHttp\Psr7\$stream, and $tmpDir.
546 $zip->addFile(
'sample.txt',
'Sample String Data');
547 $zip->addFile(
'test/sample.txt',
'More Simple Sample Data');
555 $this->assertEquals([
'sample.txt',
'test/sample.txt'],
$files);
557 $this->assertStringEqualsFile(
$tmpDir .
'/sample.txt',
'Sample String Data');
558 $this->assertStringEqualsFile(
$tmpDir .
'/test/sample.txt',
'More Simple Sample Data');
validateAndExtractZip($tmp)
$stream
PHP stream implementation.
getRecursiveFileList(string $path)
◆ testCreateArchiveWithOutputBufferingOffAndFlushOptionSet()
ZipStreamTest\ZipStreamTest::testCreateArchiveWithOutputBufferingOffAndFlushOptionSet |
( |
| ) |
|
◆ testDecompressFileWithMacUnarchiver()
ZipStreamTest\ZipStreamTest::testDecompressFileWithMacUnarchiver |
( |
| ) |
|
Definition at line 257 of file ZipStreamTest.php.
References PHPMailer\PHPMailer\$options, Sabre\VObject\$output, and GuzzleHttp\Psr7\$stream.
259 if (!file_exists(self::OSX_ARCHIVE_UTILITY)) {
260 $this->markTestSkipped(
'The Mac OSX Archive Utility is not available.');
270 $folder = uniqid(
'',
true);
272 $zip->addFile($folder .
'/sample.txt',
'Sample Data');
276 exec(escapeshellarg(self::OSX_ARCHIVE_UTILITY) .
' ' . escapeshellarg($tmp),
$output, $returnStatus);
278 $this->assertEquals(0, $returnStatus);
279 $this->assertCount(0,
$output);
281 $this->assertFileExists(dirname($tmp) .
'/' . $folder .
'/sample.txt');
282 $this->assertStringEqualsFile(dirname($tmp) .
'/' . $folder .
'/sample.txt',
'Sample Data');
$stream
PHP stream implementation.
◆ testDostime()
ZipStreamTest\ZipStreamTest::testDostime |
( |
| ) |
|
Definition at line 44 of file ZipStreamTest.php.
47 $class = new \ReflectionClass(File::class);
48 $method = $class->getMethod(
'dostime');
49 $method->setAccessible(
true);
51 $this->assertSame($method->invoke(null, 1416246368), 1165069764);
54 $this->assertSame($method->invoke(null, 315532800), 2162688);
57 $this->assertSame($method->invoke(null, 0), 2162688);
◆ testFileNotFoundException()
ZipStreamTest\ZipStreamTest::testFileNotFoundException |
( |
| ) |
|
Definition at line 23 of file ZipStreamTest.php.
30 $zip->addFileFromPath(
'foobar.php',
'/foo/bar/foobar.php');
◆ testFileNotReadableException()
ZipStreamTest\ZipStreamTest::testFileNotReadableException |
( |
| ) |
|
Definition at line 33 of file ZipStreamTest.php.
References $root.
36 $root = vfsStream::setup(
'vfs');
38 $file = vfsStream::newFile(
'foo.txt', 0000)->at(
$root)->setContent(
'bar');
41 $zip->addFileFromPath(
'foo.txt', $file->url());
◆ validateAndExtractZip()
ZipStreamTest\ZipStreamTest::validateAndExtractZip |
( |
|
$tmp | ) |
|
|
protected |
- Parameters
-
- Returns
- string
Definition at line 99 of file ZipStreamTest.php.
References $res, and $tmpDir.
103 $zipArch = new \ZipArchive;
104 $res = $zipArch->open($tmp);
107 $this->fail(
"Failed to open {$tmp}. Code: $res");
112 $this->assertEquals(0, $zipArch->status);
113 $this->assertEquals(0, $zipArch->statusSys);
foreach($_POST as $key=> $value) $res
◆ OSX_ARCHIVE_UTILITY
const ZipStreamTest\ZipStreamTest::OSX_ARCHIVE_UTILITY |
Initial value:=
'/System/Library/CoreServices/Applications/Archive Utility.app/Contents/MacOS/Archive Utility'
Definition at line 20 of file ZipStreamTest.php.
The documentation for this class was generated from the following file: