Issue24Test.php 1.4 KB

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