2
0

Zip64Test.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the nelexa/zip package.
  5. * (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace PhpZip\Tests;
  10. use PhpZip\Constants\ZipCompressionMethod;
  11. use PhpZip\Exception\ZipException;
  12. use PhpZip\ZipFile;
  13. /**
  14. * Class Zip64Test.
  15. *
  16. * @internal
  17. *
  18. * @medium
  19. */
  20. class Zip64Test extends ZipTestCase
  21. {
  22. /**
  23. * Test support ZIP64 ext (slow test - normal).
  24. * Create > 65535 files in archive and open and extract to /dev/null.
  25. *
  26. * @throws ZipException
  27. */
  28. public function testOver65535FilesInZip(): void
  29. {
  30. if (\PHP_INT_SIZE === 4) { // php 32 bit
  31. static::markTestSkipped('Only php-64 bit.');
  32. }
  33. $countFiles = 0xFFFF + 1;
  34. $zipFile = new ZipFile();
  35. for ($i = 0; $i < $countFiles; $i++) {
  36. $zipFile->addFromString($i . '.txt', (string) $i, ZipCompressionMethod::STORED);
  37. }
  38. $zipFile->saveAsFile($this->outputFilename);
  39. $zipFile->close();
  40. static::assertCorrectZipArchive($this->outputFilename);
  41. $zipFile->openFile($this->outputFilename);
  42. static::assertSame($zipFile->count(), $countFiles);
  43. $i = 0;
  44. foreach ($zipFile as $entry => $content) {
  45. static::assertSame($entry, $i . '.txt');
  46. static::assertSame($content, (string) $i);
  47. $i++;
  48. }
  49. $zipFile->close();
  50. }
  51. }