updated-packages
This commit is contained in:
5
vendor/chumper/zipper/.gitignore
vendored
5
vendor/chumper/zipper/.gitignore
vendored
@@ -1,5 +0,0 @@
|
||||
/vendor
|
||||
composer.phar
|
||||
composer.lock
|
||||
.DS_Store
|
||||
/.idea
|
34
vendor/chumper/zipper/.php_cs
vendored
34
vendor/chumper/zipper/.php_cs
vendored
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
return PhpCsFixer\Config::create()
|
||||
->setRiskyAllowed(true)
|
||||
->setRules(array(
|
||||
'@Symfony' => true,
|
||||
'@Symfony:risky' => true,
|
||||
'@PHP56Migration' => true,
|
||||
'array_syntax' => array('syntax' => 'short'),
|
||||
'combine_consecutive_unsets' => true,
|
||||
// one should use PHPUnit methods to set up expected exception instead of annotations
|
||||
'general_phpdoc_annotation_remove' => array('expectedException', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp'),
|
||||
'heredoc_to_nowdoc' => false,
|
||||
'no_extra_consecutive_blank_lines' => array('break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'),
|
||||
'no_unreachable_default_argument_value' => true,
|
||||
'no_useless_else' => true,
|
||||
'no_useless_return' => true,
|
||||
'ordered_class_elements' => true,
|
||||
'ordered_imports' => true,
|
||||
'php_unit_strict' => true,
|
||||
'phpdoc_add_missing_param_annotation' => true,
|
||||
'phpdoc_order' => true,
|
||||
'psr4' => true,
|
||||
'strict_comparison' => true,
|
||||
'strict_param' => true,
|
||||
'no_php4_constructor' => true,
|
||||
'no_short_echo_tag' => true,
|
||||
'phpdoc_summary' => false,
|
||||
))
|
||||
->setFinder(
|
||||
PhpCsFixer\Finder::create()
|
||||
->in(__DIR__)
|
||||
)
|
||||
;
|
1
vendor/chumper/zipper/.php_cs.cache
vendored
1
vendor/chumper/zipper/.php_cs.cache
vendored
@@ -1 +0,0 @@
|
||||
{"php":"7.0.15","version":"2.0.0:v2.0.0#f3baf72eb2f58bf275b372540f5b47d25aed910f","rules":{"encoding":true,"full_opening_tag":true,"blank_line_after_namespace":true,"braces":true,"class_definition":{"singleLine":true},"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"binary_operator_spaces":{"align_double_arrow":false,"align_equals":false},"blank_line_after_opening_tag":true,"blank_line_before_return":true,"cast_spaces":true,"concat_space":{"spacing":"none"},"declare_equal_normalize":true,"function_typehint_space":true,"hash_to_slash_comment":true,"include":true,"lowercase_cast":true,"method_separation":true,"native_function_casing":true,"new_with_braces":true,"no_alias_functions":true,"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_consecutive_blank_lines":["break","continue","extra","return","throw","use","parenthesis_brace_block","square_brace_block","curly_brace_block"],"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_mixed_echo_print":{"use":"echo"},"no_multiline_whitespace_around_double_arrow":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_unneeded_control_parentheses":true,"no_unreachable_default_argument_value":true,"no_unused_imports":true,"no_whitespace_before_comma_in_array":true,"no_whitespace_in_blank_line":true,"normalize_index_brace":true,"object_operator_without_whitespace":true,"php_unit_fqcn_annotation":true,"phpdoc_align":true,"phpdoc_annotation_without_dot":true,"phpdoc_indent":true,"phpdoc_inline_tag":true,"phpdoc_no_access":true,"phpdoc_no_alias_tag":true,"phpdoc_no_empty_return":true,"phpdoc_no_package":true,"phpdoc_scalar":true,"phpdoc_separation":true,"phpdoc_single_line_var_spacing":true,"phpdoc_to_comment":true,"phpdoc_trim":true,"phpdoc_types":true,"phpdoc_var_without_name":true,"pre_increment":true,"return_type_declaration":true,"self_accessor":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_quote":true,"space_after_semicolon":true,"standardize_not_equals":true,"ternary_operator_spaces":true,"trailing_comma_in_multiline_array":true,"trim_array_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"php_unit_construct":true,"php_unit_dedicate_assert":true,"silenced_deprecation_error":true,"pow_to_exponentiation":true,"array_syntax":{"syntax":"short"},"combine_consecutive_unsets":true,"general_phpdoc_annotation_remove":["expectedException","expectedExceptionMessage","expectedExceptionMessageRegExp"],"no_useless_else":true,"no_useless_return":true,"ordered_class_elements":true,"ordered_imports":true,"php_unit_strict":true,"phpdoc_add_missing_param_annotation":true,"phpdoc_order":true,"psr4":true,"strict_comparison":true,"strict_param":true,"no_php4_constructor":true,"no_short_echo_tag":true},"hashes":{"src\/Chumper\/Zipper\/Facades\/Zipper.php":3336360490,"src\/Chumper\/Zipper\/Repositories\/RepositoryInterface.php":146020446,"src\/Chumper\/Zipper\/Repositories\/ZipRepository.php":1787403374,"src\/Chumper\/Zipper\/Zipper.php":3154847016,"src\/Chumper\/Zipper\/ZipperServiceProvider.php":3002562041,"tests\/ArrayArchive.php":1688992765,"tests\/Repositories\/ZipRepositoryTest.php":973823218,"tests\/ZipperTest.php":2774399588}}
|
32
vendor/chumper/zipper/.travis.yml
vendored
32
vendor/chumper/zipper/.travis.yml
vendored
@@ -1,32 +0,0 @@
|
||||
language: php
|
||||
|
||||
sudo: false
|
||||
|
||||
php:
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
|
||||
env:
|
||||
global:
|
||||
- setup=basic
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- php: 5.6
|
||||
env: setup=lowest
|
||||
- php: 5.6
|
||||
env: setup=stable
|
||||
|
||||
|
||||
before_install:
|
||||
- composer self-update
|
||||
- composer clear-cache
|
||||
|
||||
install:
|
||||
- if [[ $setup = 'basic' ]]; then travis_retry composer update --no-interaction --prefer-dist --no-suggest; fi
|
||||
- if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --no-suggest; fi
|
||||
- if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable --no-suggest; fi
|
||||
|
||||
script: vendor/bin/phpunit
|
30
vendor/chumper/zipper/README.md
vendored
30
vendor/chumper/zipper/README.md
vendored
@@ -1,3 +1,10 @@
|
||||
# Note
|
||||
|
||||
I haven't updated this package in a long time except merging PRs. The last time I was using this package was with PHP5.
|
||||
I archived the repository for the reason that I am no longer working with PHP (we all have to move on sometimes) and have no time to take proper care of it anymore.
|
||||
|
||||
Feel free to read the code, to fork it or to use it in whatever way you want.
|
||||
|
||||
# Zipper
|
||||
|
||||
[](https://travis-ci.org/Chumper/Zipper)
|
||||
@@ -13,8 +20,8 @@ This is a simple Wrapper around the ZipArchive methods with some handy functions
|
||||
|
||||
3. Go to `app/config/app.php`
|
||||
|
||||
* add to providers `'Chumper\Zipper\ZipperServiceProvider'`
|
||||
* add to aliases `'Zipper' => 'Chumper\Zipper\Zipper'`
|
||||
* add to providers `Chumper\Zipper\ZipperServiceProvider::class`
|
||||
* add to aliases `'Zipper' => Chumper\Zipper\Zipper::class`
|
||||
|
||||
You can now access Zipper with the `Zipper` alias.
|
||||
|
||||
@@ -65,12 +72,12 @@ It will return the Zipper instance so you can chain easily.
|
||||
|
||||
## add($files/folder)
|
||||
|
||||
You can add and array of Files, or a Folder which all the files in that folder will then be added, so from the first example we could instead do something like `$files = 'public/files/';`.
|
||||
You can add an array of Files, or a Folder and all the files in that folder will then be added, so from the first example we could instead do something like `$files = 'public/files/';`.
|
||||
|
||||
|
||||
## addString($filename, $content)
|
||||
|
||||
add a single file to the zip by specifying a name and content as strings.
|
||||
add a single file to the zip by specifying a name and the content as strings.
|
||||
|
||||
|
||||
## remove($file/s)
|
||||
@@ -82,9 +89,10 @@ removes a single file or an array of files from the zip.
|
||||
|
||||
Specify a folder to 'add files to' or 'remove files from' from the zip, example
|
||||
|
||||
Zipper::make('test.zip')->folder('test')->add('composer.json');
|
||||
Zipper::make('test.zip')->folder('test')->remove('composer.json');
|
||||
|
||||
```php
|
||||
Zipper::make('test.zip')->folder('test')->add('composer.json');
|
||||
Zipper::make('test.zip')->folder('test')->remove('composer.json');
|
||||
```
|
||||
|
||||
## listFiles($regexFilter = null)
|
||||
|
||||
@@ -129,7 +137,9 @@ closes the zip and writes all changes.
|
||||
|
||||
Extracts the content of the zip archive to the specified location, for example
|
||||
|
||||
Zipper::make('test.zip')->folder('test')->extractTo('foo');
|
||||
```php
|
||||
Zipper::make('test.zip')->folder('test')->extractTo('foo');
|
||||
```
|
||||
|
||||
This will go into the folder `test` in the zip file and extract the content of that folder only to the folder `foo`, this is equal to using the `Zipper::WHITELIST`.
|
||||
|
||||
@@ -187,12 +197,12 @@ Extracts the content of the zip archive matching regular expression to the speci
|
||||
|
||||
Example: extract all files ending with `.php` from `src` folder and its sub folders.
|
||||
```php
|
||||
Zipper::make('test.zip')->folder->('src')->extractMatchingRegex($path, '/\.php$/i');
|
||||
Zipper::make('test.zip')->folder('src')->extractMatchingRegex($path, '/\.php$/i');
|
||||
```
|
||||
|
||||
Example: extract all files **except** those ending with `test.php` from `src` folder and its sub folders.
|
||||
```php
|
||||
Zipper::make('test.zip')->folder->('src')->extractMatchingRegex($path, '/^(?!.*test\.php).*$/i');
|
||||
Zipper::make('test.zip')->folder('src')->extractMatchingRegex($path, '/^(?!.*test\.php).*$/i');
|
||||
```
|
||||
|
||||
# Development
|
||||
|
1
vendor/chumper/zipper/composer.json
vendored
1
vendor/chumper/zipper/composer.json
vendored
@@ -15,6 +15,7 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.6.0",
|
||||
"ext-zip": "*",
|
||||
"illuminate/support": "^5.0",
|
||||
"illuminate/filesystem": "^5.0"
|
||||
},
|
||||
|
18
vendor/chumper/zipper/phpunit.xml
vendored
18
vendor/chumper/zipper/phpunit.xml
vendored
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Package Test Suite">
|
||||
<directory suffix=".php">./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
@@ -116,6 +116,7 @@ class ZipRepository implements RepositoryInterface
|
||||
}
|
||||
call_user_func_array($callback, [
|
||||
'file' => $this->archive->getNameIndex($i),
|
||||
'stats' => $this->archive->statIndex($i)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -63,7 +63,7 @@ class Zipper
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (null !== $this->repository) {
|
||||
if (is_object($this->repository)) {
|
||||
$this->repository->close();
|
||||
}
|
||||
}
|
||||
@@ -84,22 +84,28 @@ class Zipper
|
||||
public function make($pathToFile, $type = 'zip')
|
||||
{
|
||||
$new = $this->createArchiveFile($pathToFile);
|
||||
$this->filePath = $pathToFile;
|
||||
|
||||
$objectOrName = $type;
|
||||
if (is_string($type)) {
|
||||
$objectOrName = 'Chumper\Zipper\Repositories\\'.ucwords($type).'Repository';
|
||||
$objectOrName = 'Chumper\Zipper\Repositories\\' . ucwords($type) . 'Repository';
|
||||
}
|
||||
|
||||
if (!is_subclass_of($objectOrName, 'Chumper\Zipper\Repositories\RepositoryInterface')) {
|
||||
throw new \InvalidArgumentException("Class for '{$objectOrName}' must implement RepositoryInterface interface");
|
||||
}
|
||||
|
||||
$this->repository = $type;
|
||||
if (is_string($objectOrName)) {
|
||||
$this->repository = new $objectOrName($pathToFile, $new);
|
||||
try {
|
||||
if (is_string($objectOrName)) {
|
||||
$this->repository = new $objectOrName($pathToFile, $new);
|
||||
} else {
|
||||
$this->repository = $type;
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->filePath = $pathToFile;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -561,9 +567,8 @@ class Zipper
|
||||
*/
|
||||
private function addFile($pathToAdd, $fileName = null)
|
||||
{
|
||||
$info = pathinfo($pathToAdd);
|
||||
|
||||
if (!$fileName) {
|
||||
$info = pathinfo($pathToAdd);
|
||||
$fileName = isset($info['extension']) ?
|
||||
$info['filename'].'.'.$info['extension'] :
|
||||
$info['filename'];
|
||||
@@ -608,6 +613,11 @@ class Zipper
|
||||
private function extractOneFileInternal($fileName, $path)
|
||||
{
|
||||
$tmpPath = str_replace($this->getInternalPath(), '', $fileName);
|
||||
|
||||
//Prevent Zip traversal attacks
|
||||
if (strpos($fileName, '../') !== false || strpos($fileName, '..\\') !== false) {
|
||||
throw new \RuntimeException('Special characters found within filenames');
|
||||
}
|
||||
|
||||
// We need to create the directory first in case it doesn't exist
|
||||
$dir = pathinfo($path.DIRECTORY_SEPARATOR.$tmpPath, PATHINFO_DIRNAME);
|
||||
|
141
vendor/chumper/zipper/tests/ArrayArchive.php
vendored
141
vendor/chumper/zipper/tests/ArrayArchive.php
vendored
@@ -1,141 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Chumper\Zipper;
|
||||
|
||||
use Chumper\Zipper\Repositories\RepositoryInterface;
|
||||
|
||||
class ArrayArchive implements RepositoryInterface
|
||||
{
|
||||
private $entries = [];
|
||||
|
||||
/**
|
||||
* Construct with a given path
|
||||
*
|
||||
* @param $filePath
|
||||
* @param bool $new
|
||||
* @param $archiveImplementation
|
||||
*/
|
||||
public function __construct($filePath, $new = false, $archiveImplementation = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a file to the opened Archive
|
||||
*
|
||||
* @param $pathToFile
|
||||
* @param $pathInArchive
|
||||
*/
|
||||
public function addFile($pathToFile, $pathInArchive)
|
||||
{
|
||||
$this->entries[$pathInArchive] = $pathInArchive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a file to the opened Archive using its contents
|
||||
*
|
||||
* @param $name
|
||||
* @param $content
|
||||
*/
|
||||
public function addFromString($name, $content)
|
||||
{
|
||||
$this->entries[$name] = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a file permanently from the Archive
|
||||
*
|
||||
* @param $pathInArchive
|
||||
*/
|
||||
public function removeFile($pathInArchive)
|
||||
{
|
||||
unset($this->entries[$pathInArchive]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content of a file
|
||||
*
|
||||
* @param $pathInArchive
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileContent($pathInArchive)
|
||||
{
|
||||
return $this->entries[$pathInArchive];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stream of a file
|
||||
*
|
||||
* @param $pathInArchive
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFileStream($pathInArchive)
|
||||
{
|
||||
return $this->entries[$pathInArchive];
|
||||
}
|
||||
|
||||
/**
|
||||
* Will loop over every item in the archive and will execute the callback on them
|
||||
* Will provide the filename for every item
|
||||
*
|
||||
* @param $callback
|
||||
*/
|
||||
public function each($callback)
|
||||
{
|
||||
foreach ($this->entries as $entry) {
|
||||
call_user_func_array($callback, [
|
||||
'file' => $entry,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the file is in the archive
|
||||
*
|
||||
* @param $fileInArchive
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function fileExists($fileInArchive)
|
||||
{
|
||||
return array_key_exists($fileInArchive, $this->entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status of the archive as a string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return 'OK';
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the archive and saves it
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an empty directory
|
||||
*
|
||||
* @param $dirName
|
||||
*/
|
||||
public function addEmptyDir($dirName)
|
||||
{
|
||||
// CODE...
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the password to be used for decompressing
|
||||
*
|
||||
* @param $password
|
||||
*/
|
||||
public function usePassword($password)
|
||||
{
|
||||
// CODE...
|
||||
}
|
||||
}
|
@@ -1,116 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Chumper\Zipper\Repositories;
|
||||
|
||||
use Exception;
|
||||
use Mockery;
|
||||
use ZipArchive;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* User: Nils
|
||||
* Date: 28.08.13
|
||||
* Time: 20:57
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
class ZipRepositoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var ZipRepository
|
||||
*/
|
||||
public $zip;
|
||||
|
||||
/**
|
||||
* @var \Mockery\Mock
|
||||
*/
|
||||
public $mock;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mock = Mockery::mock(new ZipArchive());
|
||||
$this->zip = new ZipRepository('foo', true, $this->mock);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
public function testMake()
|
||||
{
|
||||
$zip = new ZipRepository('foo.zip', true);
|
||||
$this->assertFalse($zip->fileExists('foo'));
|
||||
}
|
||||
|
||||
public function testOpenNonExistentZipThrowsException()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage('Error: Failed to open idonotexist.zip! Error: ZipArchive::ER_');
|
||||
new ZipRepository('idonotexist.zip', false);
|
||||
}
|
||||
|
||||
public function testOpenNonZipThrowsException()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessageRegExp('/Error: Failed to open (.*)ZipRepositoryTest.php! Error: ZipArchive::ER_NOZIP - Not a zip archive./');
|
||||
new ZipRepository(__DIR__.DIRECTORY_SEPARATOR.'ZipRepositoryTest.php', false);
|
||||
}
|
||||
|
||||
public function testAddFile()
|
||||
{
|
||||
$this->mock->shouldReceive('addFile')->once()->with('bar', 'bar');
|
||||
$this->mock->shouldReceive('addFile')->once()->with('bar', 'foo/bar');
|
||||
$this->mock->shouldReceive('addFile')->once()->with('foo/bar', 'bar');
|
||||
|
||||
$this->zip->addFile('bar', 'bar');
|
||||
$this->zip->addFile('bar', 'foo/bar');
|
||||
$this->zip->addFile('foo/bar', 'bar');
|
||||
}
|
||||
|
||||
public function testRemoveFile()
|
||||
{
|
||||
$this->mock->shouldReceive('deleteName')->once()->with('bar');
|
||||
$this->mock->shouldReceive('deleteName')->once()->with('foo/bar');
|
||||
|
||||
$this->zip->removeFile('bar');
|
||||
$this->zip->removeFile('foo/bar');
|
||||
}
|
||||
|
||||
public function testGetFileContent()
|
||||
{
|
||||
$this->mock->shouldReceive('getFromName')->once()
|
||||
->with('bar')->andReturn('foo');
|
||||
$this->mock->shouldReceive('getFromName')->once()
|
||||
->with('foo/bar')->andReturn('baz');
|
||||
|
||||
$this->assertSame('foo', $this->zip->getFileContent('bar'));
|
||||
$this->assertSame('baz', $this->zip->getFileContent('foo/bar'));
|
||||
}
|
||||
|
||||
public function testGetFileStream()
|
||||
{
|
||||
$this->mock->shouldReceive('getStream')->once()
|
||||
->with('bar')->andReturn('foo');
|
||||
$this->mock->shouldReceive('getStream')->once()
|
||||
->with('foo/bar')->andReturn('baz');
|
||||
|
||||
$this->assertSame('foo', $this->zip->getFileStream('bar'));
|
||||
$this->assertSame('baz', $this->zip->getFileStream('foo/bar'));
|
||||
}
|
||||
|
||||
public function testFileExists()
|
||||
{
|
||||
$this->mock->shouldReceive('locateName')->once()
|
||||
->with('bar')->andReturn(true);
|
||||
$this->mock->shouldReceive('locateName')->once()
|
||||
->with('foo/bar')->andReturn(false);
|
||||
|
||||
$this->assertTrue($this->zip->fileExists('bar'));
|
||||
$this->assertFalse($this->zip->fileExists('foo/bar'));
|
||||
}
|
||||
|
||||
public function testClose()
|
||||
{
|
||||
$this->zip->close();
|
||||
}
|
||||
}
|
488
vendor/chumper/zipper/tests/ZipperTest.php
vendored
488
vendor/chumper/zipper/tests/ZipperTest.php
vendored
@@ -1,488 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Chumper\Zipper;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use InvalidArgumentException;
|
||||
use Mockery;
|
||||
use RuntimeException;
|
||||
|
||||
class ZipperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Chumper\Zipper\Zipper
|
||||
*/
|
||||
public $archive;
|
||||
|
||||
/**
|
||||
* @var \Mockery\Mock
|
||||
*/
|
||||
public $file;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->file = Mockery::mock(new Filesystem());
|
||||
$this->archive = new Zipper($this->file);
|
||||
$this->archive->make('foo', new ArrayArchive('foo', true));
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
public function testMake()
|
||||
{
|
||||
$this->assertSame('Chumper\\Zipper\\ArrayArchive', $this->archive->getArchiveType());
|
||||
$this->assertSame('foo', $this->archive->getFilePath());
|
||||
}
|
||||
|
||||
public function testMakeThrowsExceptionWhenCouldNotCreateDirectory()
|
||||
{
|
||||
$path = getcwd().time();
|
||||
|
||||
$this->file->shouldReceive('makeDirectory')
|
||||
->with($path, 0755, true)
|
||||
->andReturn(false);
|
||||
|
||||
$zip = new Zipper($this->file);
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectExceptionMessage('Failed to create folder');
|
||||
|
||||
$zip->make($path.DIRECTORY_SEPARATOR.'createMe.zip');
|
||||
}
|
||||
|
||||
public function testAddAndGet()
|
||||
{
|
||||
$this->file->shouldReceive('isFile')->with('foo.bar')
|
||||
->times(1)->andReturn(true);
|
||||
$this->file->shouldReceive('isFile')->with('foo')
|
||||
->times(1)->andReturn(true);
|
||||
|
||||
$this->archive->add('foo.bar');
|
||||
$this->archive->add('foo');
|
||||
|
||||
$this->assertSame('foo', $this->archive->getFileContent('foo'));
|
||||
$this->assertSame('foo.bar', $this->archive->getFileContent('foo.bar'));
|
||||
}
|
||||
|
||||
public function testAddAndGetWithArray()
|
||||
{
|
||||
$this->file->shouldReceive('isFile')->with('foo.bar')
|
||||
->times(1)->andReturn(true);
|
||||
$this->file->shouldReceive('isFile')->with('foo')
|
||||
->times(1)->andReturn(true);
|
||||
|
||||
/**Array**/
|
||||
$this->archive->add([
|
||||
'foo.bar',
|
||||
'foo',
|
||||
]);
|
||||
|
||||
$this->assertSame('foo', $this->archive->getFileContent('foo'));
|
||||
$this->assertSame('foo.bar', $this->archive->getFileContent('foo.bar'));
|
||||
}
|
||||
|
||||
public function testAddAndGetWithCustomFilenameArray()
|
||||
{
|
||||
$this->file->shouldReceive('isFile')->with('foo.bar')
|
||||
->times(1)->andReturn(true);
|
||||
$this->file->shouldReceive('isFile')->with('foo')
|
||||
->times(1)->andReturn(true);
|
||||
|
||||
/**Array**/
|
||||
$this->archive->add([
|
||||
'custom.bar' => 'foo.bar',
|
||||
'custom' => 'foo',
|
||||
]);
|
||||
|
||||
$this->assertSame('custom', $this->archive->getFileContent('custom'));
|
||||
$this->assertSame('custom.bar', $this->archive->getFileContent('custom.bar'));
|
||||
}
|
||||
|
||||
public function testAddAndGetWithSubFolder()
|
||||
{
|
||||
/*
|
||||
* Add the local folder /path/to/fooDir as folder fooDir to the repository
|
||||
* and make sure the folder structure within the repository is there.
|
||||
*/
|
||||
$this->file->shouldReceive('isFile')->with('/path/to/fooDir')
|
||||
->once()->andReturn(false);
|
||||
|
||||
$this->file->shouldReceive('files')->with('/path/to/fooDir')
|
||||
->once()->andReturn(['fileInFooDir.bar', 'fileInFooDir.foo']);
|
||||
|
||||
$this->file->shouldReceive('directories')->with('/path/to/fooDir')
|
||||
->once()->andReturn(['fooSubdir']);
|
||||
|
||||
$this->file->shouldReceive('files')->with('/path/to/fooDir/fooSubdir')
|
||||
->once()->andReturn(['fileInFooDir.bar']);
|
||||
$this->file->shouldReceive('directories')->with('/path/to/fooDir/fooSubdir')
|
||||
->once()->andReturn([]);
|
||||
|
||||
$this->archive->folder('fooDir')
|
||||
->add('/path/to/fooDir');
|
||||
|
||||
$this->assertSame('fooDir/fileInFooDir.bar', $this->archive->getFileContent('fooDir/fileInFooDir.bar'));
|
||||
$this->assertSame('fooDir/fileInFooDir.foo', $this->archive->getFileContent('fooDir/fileInFooDir.foo'));
|
||||
$this->assertSame('fooDir/fooSubdir/fileInFooDir.bar', $this->archive->getFileContent('fooDir/fooSubdir/fileInFooDir.bar'));
|
||||
}
|
||||
|
||||
public function testGetFileContent()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage('The file "baz" cannot be found');
|
||||
|
||||
$this->archive->getFileContent('baz');
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$this->file->shouldReceive('isFile')->with('foo')
|
||||
->andReturn(true);
|
||||
|
||||
$this->archive->add('foo');
|
||||
|
||||
$this->assertTrue($this->archive->contains('foo'));
|
||||
|
||||
$this->archive->remove('foo');
|
||||
|
||||
$this->assertFalse($this->archive->contains('foo'));
|
||||
|
||||
//----
|
||||
|
||||
$this->file->shouldReceive('isFile')->with('foo')
|
||||
->andReturn(true);
|
||||
$this->file->shouldReceive('isFile')->with('fooBar')
|
||||
->andReturn(true);
|
||||
|
||||
$this->archive->add(['foo', 'fooBar']);
|
||||
|
||||
$this->assertTrue($this->archive->contains('foo'));
|
||||
$this->assertTrue($this->archive->contains('fooBar'));
|
||||
|
||||
$this->archive->remove(['foo', 'fooBar']);
|
||||
|
||||
$this->assertFalse($this->archive->contains('foo'));
|
||||
$this->assertFalse($this->archive->contains('fooBar'));
|
||||
}
|
||||
|
||||
public function testExtractWhiteList()
|
||||
{
|
||||
$this->file
|
||||
->shouldReceive('isFile')
|
||||
->with('foo')
|
||||
->andReturn(true);
|
||||
|
||||
$this->file
|
||||
->shouldReceive('isFile')
|
||||
->with('foo.log')
|
||||
->andReturn(true);
|
||||
|
||||
$this->archive
|
||||
->add('foo')
|
||||
->add('foo.log');
|
||||
|
||||
$this->file
|
||||
->shouldReceive('put')
|
||||
->with(realpath(null).DIRECTORY_SEPARATOR.'foo', 'foo');
|
||||
|
||||
$this->file
|
||||
->shouldReceive('put')
|
||||
->with(realpath(null).DIRECTORY_SEPARATOR.'foo.log', 'foo.log');
|
||||
|
||||
$this->archive
|
||||
->extractTo(getcwd(), ['foo'], Zipper::WHITELIST);
|
||||
}
|
||||
|
||||
public function testExtractToThrowsExceptionWhenCouldNotCreateDirectory()
|
||||
{
|
||||
$path = getcwd().time();
|
||||
|
||||
$this->file
|
||||
->shouldReceive('isFile')
|
||||
->with('foo.log')
|
||||
->andReturn(true);
|
||||
|
||||
$this->file->shouldReceive('makeDirectory')
|
||||
->with($path, 0755, true)
|
||||
->andReturn(false);
|
||||
|
||||
$this->archive->add('foo.log');
|
||||
|
||||
$this->file->shouldNotReceive('put')
|
||||
->with(realpath(null).DIRECTORY_SEPARATOR.'foo.log', 'foo.log');
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectExceptionMessage('Failed to create folder');
|
||||
|
||||
$this->archive
|
||||
->extractTo($path, ['foo'], Zipper::WHITELIST);
|
||||
}
|
||||
|
||||
public function testExtractWhiteListFromSubDirectory()
|
||||
{
|
||||
$this->file->shouldReceive('isFile')->andReturn(true);
|
||||
$this->file->shouldReceive('makeDirectory')->andReturn(true);
|
||||
|
||||
$this->archive
|
||||
->folder('foo/bar')
|
||||
->add('baz')
|
||||
->add('baz.log');
|
||||
|
||||
$this->file
|
||||
->shouldReceive('put')
|
||||
->with(realpath(null).DIRECTORY_SEPARATOR.'baz', 'foo/bar/baz');
|
||||
|
||||
$this->file
|
||||
->shouldReceive('put')
|
||||
->with(realpath(null).DIRECTORY_SEPARATOR.'baz.log', 'foo/bar/baz.log');
|
||||
|
||||
$this->archive
|
||||
->extractTo(getcwd(), ['baz'], Zipper::WHITELIST);
|
||||
}
|
||||
|
||||
public function testExtractWhiteListWithExactMatching()
|
||||
{
|
||||
$this->file->shouldReceive('isFile')->andReturn(true);
|
||||
$this->file->shouldReceive('makeDirectory')->andReturn(true);
|
||||
|
||||
$this->archive
|
||||
->folder('foo/bar')
|
||||
->add('baz')
|
||||
->add('baz.log');
|
||||
|
||||
$this->file
|
||||
->shouldReceive('put')
|
||||
->with(realpath(null).DIRECTORY_SEPARATOR.'baz', 'foo/bar/baz');
|
||||
|
||||
$this->archive
|
||||
->extractTo(getcwd(), ['baz'], Zipper::WHITELIST | Zipper::EXACT_MATCH);
|
||||
}
|
||||
|
||||
public function testExtractWhiteListWithExactMatchingFromSubDirectory()
|
||||
{
|
||||
$this->file->shouldReceive('isFile')->andReturn(true);
|
||||
$this->file->shouldReceive('exists')->andReturn(false);
|
||||
$this->file->shouldReceive('makeDirectory')->andReturn(true);
|
||||
|
||||
$this->archive->folder('foo/bar/subDirectory')
|
||||
->add('bazInSubDirectory')
|
||||
->add('bazInSubDirectory.log');
|
||||
|
||||
$this->archive->folder('foo/bar')
|
||||
->add('baz')
|
||||
->add('baz.log');
|
||||
|
||||
$subDirectoryPath = realpath(null).DIRECTORY_SEPARATOR.'subDirectory';
|
||||
$subDirectoryFilePath = $subDirectoryPath.'/bazInSubDirectory';
|
||||
$this->file->shouldReceive('put')
|
||||
->with($subDirectoryFilePath, 'foo/bar/subDirectory/bazInSubDirectory');
|
||||
|
||||
$this->archive
|
||||
->extractTo(getcwd(), ['subDirectory/bazInSubDirectory'], Zipper::WHITELIST | Zipper::EXACT_MATCH);
|
||||
|
||||
$this->file->shouldHaveReceived('makeDirectory')->with($subDirectoryPath, 0755, true, true);
|
||||
}
|
||||
|
||||
public function testExtractToIgnoresBlackListFile()
|
||||
{
|
||||
$this->file->shouldReceive('isFile')->with('foo')
|
||||
->andReturn(true);
|
||||
$this->file->shouldReceive('isFile')->with('bar')
|
||||
->andReturn(true);
|
||||
$this->file->shouldReceive('makeDirectory')->andReturn(true);
|
||||
|
||||
$this->archive->add('foo')
|
||||
->add('bar');
|
||||
|
||||
$this->file->shouldReceive('put')->with(realpath(null).DIRECTORY_SEPARATOR.'foo', 'foo');
|
||||
$this->file->shouldNotReceive('put')->with(realpath(null).DIRECTORY_SEPARATOR.'bar', 'bar');
|
||||
|
||||
$this->archive->extractTo(getcwd(), ['bar'], Zipper::BLACKLIST);
|
||||
}
|
||||
|
||||
public function testExtractBlackListFromSubDirectory()
|
||||
{
|
||||
$currentDir = getcwd();
|
||||
|
||||
$this->file->shouldReceive('isFile')->andReturn(true);
|
||||
$this->file->shouldReceive('makeDirectory')->andReturn(true);
|
||||
|
||||
$this->archive->add('rootLevelFile');
|
||||
|
||||
$this->archive->folder('foo/bar/sub')
|
||||
->add('fileInSubSubDir');
|
||||
|
||||
$this->archive->folder('foo/bar')
|
||||
->add('fileInSubDir')
|
||||
->add('fileBlackListedInSubDir');
|
||||
|
||||
$this->file->shouldReceive('put')->with($currentDir.DIRECTORY_SEPARATOR.'fileInSubDir', 'foo/bar/fileInSubDir');
|
||||
$this->file->shouldReceive('put')->with($currentDir.DIRECTORY_SEPARATOR.'sub/fileInSubSubDir', 'foo/bar/sub/fileInSubSubDir');
|
||||
|
||||
$this->file->shouldNotReceive('put')->with($currentDir.DIRECTORY_SEPARATOR.'fileBlackListedInSubDir', 'fileBlackListedInSubDir');
|
||||
$this->file->shouldNotReceive('put')->with($currentDir.DIRECTORY_SEPARATOR.'rootLevelFile', 'rootLevelFile');
|
||||
|
||||
$this->archive->extractTo($currentDir, ['fileBlackListedInSubDir'], Zipper::BLACKLIST);
|
||||
}
|
||||
|
||||
public function testExtractBlackListFromSubDirectoryWithExactMatching()
|
||||
{
|
||||
$this->file->shouldReceive('isFile')->with('baz')
|
||||
->andReturn(true);
|
||||
$this->file->shouldReceive('makeDirectory')->andReturn(true);
|
||||
|
||||
$this->file->shouldReceive('isFile')->with('baz.log')
|
||||
->andReturn(true);
|
||||
|
||||
$this->archive->folder('foo/bar')
|
||||
->add('baz')
|
||||
->add('baz.log');
|
||||
|
||||
$this->file->shouldReceive('put')->with(realpath(null).DIRECTORY_SEPARATOR.'baz.log', 'foo/bar/baz.log');
|
||||
|
||||
$this->archive->extractTo(getcwd(), ['baz'], Zipper::BLACKLIST | Zipper::EXACT_MATCH);
|
||||
}
|
||||
|
||||
public function testExtractMatchingRegexFromSubFolder()
|
||||
{
|
||||
$this->file->shouldReceive('isFile')->with('baz')->andReturn(true);
|
||||
$this->file->shouldReceive('isFile')->with('baz.log')->andReturn(true);
|
||||
$this->file->shouldReceive('isFile')->with('subFolderFileToIgnore')->andReturn(true);
|
||||
$this->file->shouldReceive('isFile')->with('subFolderFileToExtract.log')->andReturn(true);
|
||||
$this->file->shouldReceive('isFile')->with('rootLevelMustBeIgnored.log')->andReturn(true);
|
||||
|
||||
$this->file->shouldReceive('makeDirectory')->andReturn(true);
|
||||
|
||||
$this->archive->add('rootLevelMustBeIgnored.log');
|
||||
|
||||
$this->archive->folder('foo/bar/subFolder')
|
||||
->add('subFolderFileToIgnore')
|
||||
->add('subFolderFileToExtract.log');
|
||||
|
||||
$this->archive->folder('foo/bar')
|
||||
->add('baz')
|
||||
->add('baz.log');
|
||||
|
||||
$this->file->shouldReceive('put')->with(realpath(null).DIRECTORY_SEPARATOR.'baz.log', 'foo/bar/baz.log');
|
||||
$this->file->shouldReceive('put')->with(realpath(null).DIRECTORY_SEPARATOR.'subFolder/subFolderFileToExtract.log', 'foo/bar/subFolder/subFolderFileToExtract.log');
|
||||
$this->file->shouldNotReceive('put')->with(realpath(null).DIRECTORY_SEPARATOR.'rootLevelMustBeIgnored.log', 'rootLevelMustBeIgnored.log');
|
||||
$this->file->shouldNotReceive('put')->with(realpath(null).DIRECTORY_SEPARATOR.'baz', 'foo/bar/baz');
|
||||
$this->file->shouldNotReceive('put')->with(realpath(null).DIRECTORY_SEPARATOR.'subFolder/subFolderFileToIgnore', 'foo/bar/subFolder/subFolderFileToIgnore');
|
||||
|
||||
$this->archive->extractMatchingRegex(getcwd(), '/\.log$/i');
|
||||
}
|
||||
|
||||
public function testExtractMatchingRegexThrowsExceptionWhenRegexIsEmpty()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Missing pass valid regex parameter');
|
||||
$this->archive->extractMatchingRegex(getcwd(), '');
|
||||
}
|
||||
|
||||
public function testNavigationFolderAndHome()
|
||||
{
|
||||
$this->archive->folder('foo/bar');
|
||||
$this->assertSame('foo/bar', $this->archive->getCurrentFolderPath());
|
||||
|
||||
//----
|
||||
|
||||
$this->file->shouldReceive('isFile')->with('foo')
|
||||
->andReturn(true);
|
||||
|
||||
$this->archive->add('foo');
|
||||
$this->assertSame('foo/bar/foo', $this->archive->getFileContent('foo/bar/foo'));
|
||||
|
||||
//----
|
||||
|
||||
$this->file->shouldReceive('isFile')->with('bar')
|
||||
->andReturn(true);
|
||||
|
||||
$this->archive->home()->add('bar');
|
||||
$this->assertSame('bar', $this->archive->getFileContent('bar'));
|
||||
|
||||
//----
|
||||
|
||||
$this->file->shouldReceive('isFile')->with('baz/bar/bing')
|
||||
->andReturn(true);
|
||||
|
||||
$this->archive->folder('test')->add('baz/bar/bing');
|
||||
$this->assertSame('test/bing', $this->archive->getFileContent('test/bing'));
|
||||
}
|
||||
|
||||
public function testListFiles()
|
||||
{
|
||||
// testing empty file
|
||||
$this->file->shouldReceive('isFile')->with('foo.file')->andReturn(true);
|
||||
$this->file->shouldReceive('isFile')->with('bar.file')->andReturn(true);
|
||||
|
||||
$this->assertSame([], $this->archive->listFiles());
|
||||
|
||||
// testing not empty file
|
||||
$this->archive->add('foo.file');
|
||||
$this->archive->add('bar.file');
|
||||
|
||||
$this->assertSame(['foo.file', 'bar.file'], $this->archive->listFiles());
|
||||
|
||||
// testing with a empty sub dir
|
||||
$this->file->shouldReceive('isFile')->with('/path/to/subDirEmpty')->andReturn(false);
|
||||
|
||||
$this->file->shouldReceive('files')->with('/path/to/subDirEmpty')->andReturn([]);
|
||||
$this->file->shouldReceive('directories')->with('/path/to/subDirEmpty')->andReturn([]);
|
||||
$this->archive->folder('subDirEmpty')->add('/path/to/subDirEmpty');
|
||||
|
||||
$this->assertSame(['foo.file', 'bar.file'], $this->archive->listFiles());
|
||||
|
||||
// testing with a not empty sub dir
|
||||
$this->file->shouldReceive('isFile')->with('/path/to/subDir')->andReturn(false);
|
||||
$this->file->shouldReceive('isFile')->with('sub.file')->andReturn(true);
|
||||
|
||||
$this->file->shouldReceive('files')->with('/path/to/subDir')->andReturn(['sub.file']);
|
||||
$this->file->shouldReceive('directories')->with('/path/to/subDir')->andReturn([]);
|
||||
|
||||
$this->archive->folder('subDir')->add('/path/to/subDir');
|
||||
|
||||
$this->assertSame(['foo.file', 'bar.file', 'subDir/sub.file'], $this->archive->listFiles());
|
||||
}
|
||||
|
||||
public function testListFilesWithRegexFilter()
|
||||
{
|
||||
// add 2 files to root level in zip
|
||||
$this->file->shouldReceive('isFile')->with('foo.file')->andReturn(true);
|
||||
$this->file->shouldReceive('isFile')->with('bar.log')->andReturn(true);
|
||||
|
||||
$this->archive
|
||||
->add('foo.file')
|
||||
->add('bar.log');
|
||||
|
||||
// add sub directory with 2 files inside
|
||||
$this->file->shouldReceive('isFile')->with('/path/to/subDir')->andReturn(false);
|
||||
$this->file->shouldReceive('isFile')->with('sub.file')->andReturn(true);
|
||||
$this->file->shouldReceive('isFile')->with('anotherSub.log')->andReturn(true);
|
||||
|
||||
$this->file->shouldReceive('files')->with('/path/to/subDir')->andReturn(['sub.file', 'anotherSub.log']);
|
||||
$this->file->shouldReceive('directories')->with('/path/to/subDir')->andReturn([]);
|
||||
|
||||
$this->archive->folder('subDir')->add('/path/to/subDir');
|
||||
|
||||
$this->assertSame(
|
||||
['foo.file', 'subDir/sub.file'],
|
||||
$this->archive->listFiles('/\.file$/i') // filter out files ending with ".file" pattern
|
||||
);
|
||||
}
|
||||
|
||||
public function testListFilesThrowsExceptionWithInvalidRegexFilter()
|
||||
{
|
||||
$this->file->shouldReceive('isFile')->with('foo.file')->andReturn(true);
|
||||
$this->archive->add('foo.file');
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectExceptionMessage('regular expression match on \'foo.file\' failed with error. Please check if pattern is valid regular expression.');
|
||||
|
||||
$invalidPattern = 'asdasd';
|
||||
$this->archive->listFiles($invalidPattern);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user