From 91f08b9f55689c85c9d83114657bbb0fef0f7cf0 Mon Sep 17 00:00:00 2001 From: Frederik Buus Sauer Date: Thu, 12 Apr 2018 11:10:45 +0200 Subject: [PATCH 1/2] Updated composer.json regarding unit tests, and corrected PSR implementation --- composer.json | 88 ++++++++++++++++++------------------ src/PhpZip/ZipFile.php | 10 ++-- tests/PhpZip/ZipFileTest.php | 6 ++- 3 files changed, 54 insertions(+), 50 deletions(-) diff --git a/composer.json b/composer.json index 7a55c83..e159650 100644 --- a/composer.json +++ b/composer.json @@ -1,45 +1,47 @@ { - "name": "nelexa/zip", - "description": "PhpZip is a php-library for extended work with ZIP-archives. Open, create, update, delete, extract and get info tool. Supports appending to existing ZIP files, WinZip AES encryption, Traditional PKWARE Encryption, ZipAlign tool, BZIP2 compression, external file attributes and ZIP64 extensions. Alternative ZipArchive. It does not require php-zip extension.", - "type": "library", - "keywords": [ - "zip", - "unzip", - "archive", - "extract", - "winzip", - "zipalign", - "ziparchive" - ], - "require-dev": { - "phpunit/phpunit": "4.8" - }, - "license": "MIT", - "authors": [ - { - "name": "Ne-Lexa", - "email": "alexey@nelexa.ru", - "role": "Developer" - } - ], - "minimum-stability": "stable", - "require": { - "php": "^5.5 || ^7.0", - "psr/http-message": "^1.0" - }, - "autoload": { - "psr-4": { - "PhpZip\\": "src/PhpZip" - } - }, - "autoload-dev": { - "psr-4": { - "PhpZip\\": "tests/PhpZip" - } - }, - "suggest": { - "ext-openssl": "Needed to support encrypt zip entries or use ext-mcrypt", - "ext-mcrypt": "Needed to support encrypt zip entries or use ext-openssl", - "ext-bz2": "Needed to support BZIP2 compression" - } + "name": "nelexa/zip", + "type": "library", + "description": "PhpZip is a php-library for extended work with ZIP-archives. Open, create, update, delete, extract and get info tool. Supports appending to existing ZIP files, WinZip AES encryption, Traditional PKWARE Encryption, ZipAlign tool, BZIP2 compression, external file attributes and ZIP64 extensions. Alternative ZipArchive. It does not require php-zip extension.", + "keywords": [ + "zip", + "unzip", + "archive", + "extract", + "winzip", + "zipalign", + "ziparchive" + ], + "homepage": "https://github.com/Ne-Lexa/php-zip", + "license": "MIT", + "authors": [ + { + "name": "Ne-Lexa", + "email": "alexey@nelexa.ru", + "role": "Developer" + } + ], + "require": { + "php": "^5.5 || ^7.0", + "psr/http-message": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.8|~5.7", + "zendframework/zend-diactoros": "^1.7" + }, + "autoload": { + "psr-4": { + "PhpZip\\": "src/PhpZip" + } + }, + "autoload-dev": { + "psr-4": { + "PhpZip\\": "tests/PhpZip" + } + }, + "suggest": { + "ext-openssl": "Needed to support encrypt zip entries or use ext-mcrypt", + "ext-mcrypt": "Needed to support encrypt zip entries or use ext-openssl", + "ext-bz2": "Needed to support BZIP2 compression" + }, + "minimum-stability": "stable" } diff --git a/src/PhpZip/ZipFile.php b/src/PhpZip/ZipFile.php index 483288a..a5db71a 100644 --- a/src/PhpZip/ZipFile.php +++ b/src/PhpZip/ZipFile.php @@ -1299,11 +1299,11 @@ class ZipFile implements ZipFileInterface } $stream = new ResponseStream($handle); - $response->withHeader('Content-Type', $mimeType); - $response->withHeader('Content-Disposition', $contentDispositionValue); - $response->withHeader('Content-Length', $stream->getSize()); - $response->withBody($stream); - return $response; + return $response + ->withHeader('Content-Type', $mimeType) + ->withHeader('Content-Disposition', $contentDispositionValue) + ->withHeader('Content-Length', $stream->getSize()) + ->withBody($stream); } /** diff --git a/tests/PhpZip/ZipFileTest.php b/tests/PhpZip/ZipFileTest.php index 2adf1ee..4cbc75e 100644 --- a/tests/PhpZip/ZipFileTest.php +++ b/tests/PhpZip/ZipFileTest.php @@ -7,6 +7,7 @@ use PhpZip\Model\ZipInfo; use PhpZip\Util\CryptoUtil; use PhpZip\Util\FilesUtil; use Psr\Http\Message\ResponseInterface; +use Zend\Diactoros\Response; /** * ZipFile test @@ -1786,9 +1787,10 @@ class ZipFileTest extends ZipTestCase $zipFile[$i] = $i; } $filename = 'file.jar'; - $response = $this->getMock(ResponseInterface::class); - $response = $zipFile->outputAsResponse($response, $filename); + $response = $zipFile->outputAsResponse(new Response(), $filename); $this->assertInstanceOf(ResponseInterface::class, $response); + $this->assertEquals('application/java-archive', $response->getHeaderLine('content-type')); + $this->assertEquals('attachment; filename="file.jar"', $response->getHeaderLine('content-disposition')); } public function testCompressionLevel() From 6808e4ffdcd6abda16ea955c0d6e739b276b3a3d Mon Sep 17 00:00:00 2001 From: Frederik Buus Sauer Date: Thu, 12 Apr 2018 11:25:12 +0200 Subject: [PATCH 2/2] Lowered requirement to support PHP 5.5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e159650..16b02fd 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ }, "require-dev": { "phpunit/phpunit": "~4.8|~5.7", - "zendframework/zend-diactoros": "^1.7" + "zendframework/zend-diactoros": "^1.4" }, "autoload": { "psr-4": {