Issue24Test.php 1.2 KB

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