1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-01-17 20:58:22 +01:00
php-zip/tests/Issue24Test.php

58 lines
1.4 KiB
PHP
Raw Normal View History

2018-10-21 01:54:30 +03:00
<?php
namespace PhpZip\Tests;
2018-10-21 01:54:30 +03:00
2020-01-09 17:33:02 +03:00
use PhpZip\Constants\ZipCompressionMethod;
2018-10-21 01:54:30 +03:00
use PhpZip\Exception\ZipException;
use PhpZip\Tests\Internal\DummyFileSystemStream;
use PhpZip\ZipFile;
2018-10-21 01:54:30 +03:00
2019-12-05 19:36:11 +03:00
/**
* @internal
*
* @small
*/
2018-10-21 01:54:30 +03:00
class Issue24Test extends ZipTestCase
{
const PROTO_DUMMYFS = 'dummyfs';
2018-10-21 01:54:30 +03:00
/**
* This method is called before the first test of this test class is run.
2019-12-07 19:40:36 +03:00
*
* @noinspection PhpMissingParentCallCommonInspection
2018-10-21 01:54:30 +03:00
*/
public static function setUpBeforeClass()
{
stream_wrapper_register(self::PROTO_DUMMYFS, DummyFileSystemStream::class);
2018-10-21 01:54:30 +03:00
}
/**
* @throws ZipException
2019-12-06 23:23:44 +03:00
* @throws \Exception
2018-10-21 01:54:30 +03:00
*/
public function testDummyFS()
{
2019-12-06 23:23:44 +03:00
$fileContents = str_repeat(base64_encode(random_bytes(12000)), 100);
2018-10-21 01:54:30 +03:00
// create zip file
$zip = new ZipFile();
$zip->addFromString(
'file.txt',
$fileContents,
2020-01-09 17:33:02 +03:00
ZipCompressionMethod::DEFLATED
2018-10-21 01:54:30 +03:00
);
$zip->saveAsFile($this->outputFilename);
$zip->close();
2019-12-05 19:36:11 +03:00
static::assertCorrectZipArchive($this->outputFilename);
2018-10-21 01:54:30 +03:00
$uri = self::PROTO_DUMMYFS . '://localhost/' . $this->outputFilename;
$stream = fopen($uri, 'rb');
2019-12-05 19:36:11 +03:00
static::assertNotFalse($stream);
2018-10-21 01:54:30 +03:00
$zip->openFromStream($stream);
2019-12-05 19:36:11 +03:00
static::assertSame($zip->getListFiles(), ['file.txt']);
static::assertSame($zip['file.txt'], $fileContents);
2018-10-21 01:54:30 +03:00
$zip->close();
}
}