2
0

Issue24Test.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace PhpZip;
  3. use PhpZip\Exception\ZipException;
  4. use PhpZip\Util\CryptoUtil;
  5. /**
  6. * @internal
  7. *
  8. * @small
  9. */
  10. class Issue24Test extends ZipTestCase
  11. {
  12. /**
  13. * This method is called before the first test of this test class is run.
  14. */
  15. public static function setUpBeforeClass()
  16. {
  17. stream_wrapper_register('dummyfs', Internal\DummyFileSystemStream::class);
  18. }
  19. /**
  20. * @throws ZipException
  21. */
  22. public function testDummyFS()
  23. {
  24. $fileContents = str_repeat(base64_encode(CryptoUtil::randomBytes(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. }