Browse Source

Updated composer.json regarding unit tests, and corrected PSR implementation

Frederik Buus Sauer 8 năm trước cách đây
mục cha
commit
91f08b9f55
3 tập tin đã thay đổi với 54 bổ sung50 xóa
  1. 45 43
      composer.json
  2. 5 5
      src/PhpZip/ZipFile.php
  3. 4 2
      tests/PhpZip/ZipFileTest.php

+ 45 - 43
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"
 }

+ 5 - 5
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);
     }
 
     /**

+ 4 - 2
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()