forked from Ne-Lexa/php-zip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-enable support for remote streams, fix Ne-Lexa#25
- Loading branch information
1 parent
9934a86
commit e903642
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace PhpZip; | ||
|
||
use PhpZip\Exception\ZipException; | ||
use PhpZip\Util\Iterator\IgnoreFilesFilterIterator; | ||
use PhpZip\Util\Iterator\IgnoreFilesRecursiveFilterIterator; | ||
|
||
/** | ||
* Test add remote files to zip archive | ||
*/ | ||
class ZipRemoteFileTest extends ZipTestCase | ||
{ | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* @throws ZipException | ||
*/ | ||
public function testAddRemoteFileFromStream() | ||
{ | ||
$zipFile = new ZipFile(); | ||
$outputZip = $this->outputFilename; | ||
$fileUrl = 'https://raw.githubusercontent.com/Ne-Lexa/php-zip/master/README.md'; | ||
$fp = @fopen($fileUrl, 'rb', false, stream_context_create([ | ||
'http' => [ | ||
'timeout' => 3, | ||
] | ||
])); | ||
if ($fp === false) { | ||
self::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(); | ||
self::assertCount(1, $files); | ||
self::assertSame($fileName, $files[0]); | ||
$zipFile->close(); | ||
} | ||
|
||
} |