Issue24Test.php 1.2 KB

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