Issue24Test.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\Tests\Internal\DummyFileSystemStream;
  13. use PhpZip\ZipFile;
  14. /**
  15. * @internal
  16. *
  17. * @small
  18. */
  19. class Issue24Test extends ZipTestCase
  20. {
  21. public const PROTO_DUMMYFS = 'dummyfs';
  22. /**
  23. * This method is called before the first test of this test class is run.
  24. *
  25. * @noinspection PhpMissingParentCallCommonInspection
  26. */
  27. public static function setUpBeforeClass(): void
  28. {
  29. stream_wrapper_register(self::PROTO_DUMMYFS, DummyFileSystemStream::class);
  30. }
  31. /**
  32. * @throws ZipException
  33. * @throws \Exception
  34. */
  35. public function testDummyFS(): void
  36. {
  37. $fileContents = str_repeat(base64_encode(random_bytes(12000)), 100);
  38. // create zip file
  39. $zip = new ZipFile();
  40. $zip->addFromString(
  41. 'file.txt',
  42. $fileContents,
  43. ZipCompressionMethod::DEFLATED
  44. );
  45. $zip->saveAsFile($this->outputFilename);
  46. $zip->close();
  47. static::assertCorrectZipArchive($this->outputFilename);
  48. $uri = self::PROTO_DUMMYFS . '://localhost/' . $this->outputFilename;
  49. $stream = fopen($uri, 'rb');
  50. static::assertNotFalse($stream);
  51. $zip->openFromStream($stream);
  52. static::assertSame($zip->getListFiles(), ['file.txt']);
  53. static::assertSame($zip['file.txt'], $fileContents);
  54. $zip->close();
  55. }
  56. }