mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-01-17 12:48:28 +01:00
91 lines
2.2 KiB
PHP
91 lines
2.2 KiB
PHP
<?php
|
|
|
|
/** @noinspection PhpUsageOfSilenceOperatorInspection */
|
|
|
|
namespace PhpZip\Tests;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use PhpZip\Exception\InvalidArgumentException;
|
|
use PhpZip\Exception\ZipException;
|
|
use PhpZip\ZipFile;
|
|
|
|
/**
|
|
* Class ZipStreamOpenTest.
|
|
*
|
|
* @internal
|
|
*
|
|
* @medium
|
|
*/
|
|
class ZipStreamOpenTest extends TestCase
|
|
{
|
|
/**
|
|
* @dataProvider provideStreams
|
|
*
|
|
* @param resource $resource
|
|
* @param string|null $exceptionClass
|
|
* @param string|null $exceptionMessage
|
|
*
|
|
* @throws ZipException
|
|
*/
|
|
public function testOpenStream($resource, $exceptionClass = null, $exceptionMessage = null)
|
|
{
|
|
if ($resource === null) {
|
|
static::markTestSkipped('skip null resource');
|
|
|
|
return;
|
|
}
|
|
|
|
if ($exceptionClass !== null) {
|
|
$this->setExpectedException(
|
|
$exceptionClass,
|
|
$exceptionMessage
|
|
);
|
|
}
|
|
|
|
static::assertInternalType('resource', $resource);
|
|
|
|
$zipFile = new ZipFile();
|
|
$zipFile->openFromStream($resource);
|
|
|
|
static::assertTrue(fclose($resource));
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function provideStreams()
|
|
{
|
|
return [
|
|
[@fopen(__DIR__ . '/resources/apk.zip', 'rb'), null, null],
|
|
[
|
|
@fopen(__DIR__, 'rb'),
|
|
InvalidArgumentException::class,
|
|
'Directory stream not supported',
|
|
],
|
|
[$this->getTempResource('php://temp'), null, null],
|
|
[$this->getTempResource('php://memory'), null, null],
|
|
[
|
|
@fopen('https://github.com/Ne-Lexa/php-zip/archive/master.zip', 'rb'),
|
|
InvalidArgumentException::class,
|
|
'The stream wrapper type "http" is not supported.',
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param string $filename
|
|
*
|
|
* @return resource
|
|
*/
|
|
private function getTempResource($filename)
|
|
{
|
|
$fp = fopen(__DIR__ . '/resources/apk.zip', 'rb');
|
|
$stream = fopen($filename, 'r+b');
|
|
stream_copy_to_stream($fp, $stream);
|
|
fclose($fp);
|
|
rewind($stream);
|
|
|
|
return $stream;
|
|
}
|
|
}
|