Issue24Test.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. public static function setUpBeforeClass()
  15. {
  16. stream_wrapper_register('dummyfs', Internal\DummyFileSystemStream::class);
  17. }
  18. /**
  19. * @throws ZipException
  20. * @throws \Exception
  21. */
  22. public function testDummyFS()
  23. {
  24. $fileContents = str_repeat(base64_encode(random_bytes(12000)), 100);
  25. // create zip file
  26. $zip = new ZipFile();
  27. $zip->addFromString(
  28. 'file.txt',
  29. $fileContents,
  30. ZipFile::METHOD_DEFLATED
  31. );
  32. $zip->saveAsFile($this->outputFilename);
  33. $zip->close();
  34. static::assertCorrectZipArchive($this->outputFilename);
  35. $stream = fopen('dummyfs://localhost/' . $this->outputFilename, 'rb');
  36. static::assertNotFalse($stream);
  37. $zip->openFromStream($stream);
  38. static::assertSame($zip->getListFiles(), ['file.txt']);
  39. static::assertSame($zip['file.txt'], $fileContents);
  40. $zip->close();
  41. }
  42. }