2
0

Issue24Test.php 1.4 KB

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