mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-08-05 15:07:26 +02:00
solving problems with lack of memory, the new ZipReader and ZipWriter class, adds .phpstorm.meta.php
#13 #16 #27 #31 #41
This commit is contained in:
62
tests/ZipRemoteFileTest.php
Normal file
62
tests/ZipRemoteFileTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace PhpZip\Tests;
|
||||
|
||||
use PhpZip\Exception\ZipException;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Test add remote files to zip archive.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @small
|
||||
*/
|
||||
class ZipRemoteFileTest extends ZipTestCase
|
||||
{
|
||||
/**
|
||||
* @throws ZipException
|
||||
*/
|
||||
public function testAddRemoteFileFromStream()
|
||||
{
|
||||
$zipFile = new ZipFile();
|
||||
$outputZip = $this->outputFilename;
|
||||
$fileUrl = 'https://raw.githubusercontent.com/Ne-Lexa/php-zip/master/README.md';
|
||||
/** @noinspection PhpUsageOfSilenceOperatorInspection */
|
||||
$fp = @fopen(
|
||||
$fileUrl,
|
||||
'rb',
|
||||
false,
|
||||
stream_context_create(
|
||||
[
|
||||
'http' => [
|
||||
'timeout' => 3,
|
||||
],
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
if ($fp === false) {
|
||||
static::markTestSkipped(
|
||||
sprintf(
|
||||
'Could not fetch remote file: %s',
|
||||
$fileUrl
|
||||
)
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fileName = 'remote-file-from-http-stream.md';
|
||||
$zipFile->addFromStream($fp, $fileName);
|
||||
$zipFile->saveAsFile($outputZip);
|
||||
$zipFile->close();
|
||||
|
||||
$zipFile = new ZipFile();
|
||||
$zipFile->openFile($outputZip);
|
||||
$files = $zipFile->getListFiles();
|
||||
static::assertCount(1, $files);
|
||||
static::assertSame($fileName, $files[0]);
|
||||
$zipFile->close();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user