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

63 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace PhpZip\Tests;
use PhpZip\Exception\ZipException;
use PhpZip\ZipFile;
/**
2019-12-05 19:36:11 +03:00
* 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';
2019-12-05 19:36:11 +03:00
/** @noinspection PhpUsageOfSilenceOperatorInspection */
$fp = @fopen(
$fileUrl,
'rb',
false,
stream_context_create(
[
'http' => [
'timeout' => 3,
],
]
)
);
if ($fp === false) {
2019-12-05 19:36:11 +03:00
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();
2019-12-05 19:36:11 +03:00
static::assertCount(1, $files);
static::assertSame($fileName, $files[0]);
$zipFile->close();
}
}