123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- declare(strict_types=1);
- /*
- * This file is part of the nelexa/zip package.
- * (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace PhpZip\Tests;
- use PhpZip\Constants\ZipCompressionMethod;
- use PhpZip\Exception\ZipException;
- use PhpZip\Tests\Internal\DummyFileSystemStream;
- use PhpZip\ZipFile;
- /**
- * @internal
- *
- * @small
- */
- class Issue24Test extends ZipTestCase
- {
- public const PROTO_DUMMYFS = 'dummyfs';
- /**
- * This method is called before the first test of this test class is run.
- *
- * @noinspection PhpMissingParentCallCommonInspection
- */
- public static function setUpBeforeClass(): void
- {
- stream_wrapper_register(self::PROTO_DUMMYFS, DummyFileSystemStream::class);
- }
- /**
- * @throws ZipException
- * @throws \Exception
- */
- public function testDummyFS(): void
- {
- $fileContents = str_repeat(base64_encode(random_bytes(12000)), 100);
- // create zip file
- $zip = new ZipFile();
- $zip->addFromString(
- 'file.txt',
- $fileContents,
- ZipCompressionMethod::DEFLATED
- );
- $zip->saveAsFile($this->outputFilename);
- $zip->close();
- static::assertCorrectZipArchive($this->outputFilename);
- $uri = self::PROTO_DUMMYFS . '://localhost/' . $this->outputFilename;
- $stream = fopen($uri, 'rb');
- static::assertNotFalse($stream);
- $zip->openFromStream($stream);
- static::assertSame($zip->getListFiles(), ['file.txt']);
- static::assertSame($zip['file.txt'], $fileContents);
- $zip->close();
- }
- }
|