12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- declare(strict_types=1);
- /*
- * This file is part of the nelexa/zip package.
- * (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- 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 $exceptionClass
- * @param ?string $exceptionMessage
- *
- * @throws ZipException
- */
- public function testOpenStream($resource, ?string $exceptionClass = null, ?string $exceptionMessage = null): void
- {
- if ($resource === null || $resource === false) {
- static::markTestSkipped('skip resource');
- }
- if ($exceptionClass !== null) {
- $this->expectException($exceptionClass);
- $this->expectExceptionMessage($exceptionMessage);
- }
- static::assertIsResource($resource);
- $zipFile = new ZipFile();
- $zipFile->openFromStream($resource);
- static::assertTrue(fclose($resource));
- }
- public function provideStreams(): array
- {
- 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.',
- ],
- ];
- }
- /**
- * @return resource
- */
- private function getTempResource(string $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;
- }
- }
|