Laravel version update
Laravel version update
This commit is contained in:
0
vendor/chumper/zipper/tests/.gitkeep
vendored
0
vendor/chumper/zipper/tests/.gitkeep
vendored
53
vendor/chumper/zipper/tests/ArrayArchive.php
vendored
53
vendor/chumper/zipper/tests/ArrayArchive.php
vendored
@@ -1,10 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Chumper\Zipper;
|
||||
|
||||
use Chumper\Zipper\Repositories\RepositoryInterface;
|
||||
|
||||
class ArrayArchive implements RepositoryInterface
|
||||
{
|
||||
private $entries = array();
|
||||
private $entries = [];
|
||||
|
||||
/**
|
||||
* Construct with a given path
|
||||
@@ -13,7 +15,7 @@ class ArrayArchive implements RepositoryInterface
|
||||
* @param bool $new
|
||||
* @param $archiveImplementation
|
||||
*/
|
||||
function __construct($filePath, $new = false, $archiveImplementation = null)
|
||||
public function __construct($filePath, $new = false, $archiveImplementation = null)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -22,18 +24,27 @@ class ArrayArchive implements RepositoryInterface
|
||||
*
|
||||
* @param $pathToFile
|
||||
* @param $pathInArchive
|
||||
* @return void
|
||||
*/
|
||||
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
|
||||
* @return void
|
||||
*/
|
||||
public function removeFile($pathInArchive)
|
||||
{
|
||||
@@ -44,6 +55,7 @@ class ArrayArchive implements RepositoryInterface
|
||||
* Get the content of a file
|
||||
*
|
||||
* @param $pathInArchive
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileContent($pathInArchive)
|
||||
@@ -55,6 +67,7 @@ class ArrayArchive implements RepositoryInterface
|
||||
* Get the stream of a file
|
||||
*
|
||||
* @param $pathInArchive
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFileStream($pathInArchive)
|
||||
@@ -67,23 +80,22 @@ class ArrayArchive implements RepositoryInterface
|
||||
* Will provide the filename for every item
|
||||
*
|
||||
* @param $callback
|
||||
* @return void
|
||||
*/
|
||||
public function each($callback)
|
||||
{
|
||||
foreach ($this->entries as $entry) {
|
||||
call_user_func_array($callback, array(
|
||||
call_user_func_array($callback, [
|
||||
'file' => $entry,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the file is in the archive
|
||||
*
|
||||
* @param $fileInArchive
|
||||
* @return boolean
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function fileExists($fileInArchive)
|
||||
{
|
||||
@@ -97,14 +109,33 @@ class ArrayArchive implements RepositoryInterface
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return "OK";
|
||||
return 'OK';
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the archive and saves it
|
||||
* @return void
|
||||
*/
|
||||
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,5 +1,10 @@
|
||||
<?php
|
||||
use Chumper\Zipper\Repositories\ZipRepository;
|
||||
|
||||
namespace Chumper\Zipper\Repositories;
|
||||
|
||||
use Exception;
|
||||
use Mockery;
|
||||
use ZipArchive;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -8,10 +13,8 @@ use Chumper\Zipper\Repositories\ZipRepository;
|
||||
* Time: 20:57
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
|
||||
class ZipRepositoryTest extends PHPUnit_Framework_TestCase
|
||||
class ZipRepositoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ZipRepository
|
||||
*/
|
||||
@@ -24,16 +27,35 @@ class ZipRepositoryTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mock = Mockery::mock(new ZipArchive);
|
||||
$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');
|
||||
@@ -61,8 +83,8 @@ class ZipRepositoryTest extends PHPUnit_Framework_TestCase
|
||||
$this->mock->shouldReceive('getFromName')->once()
|
||||
->with('foo/bar')->andReturn('baz');
|
||||
|
||||
$this->assertEquals('foo', $this->zip->getFileContent('bar'));
|
||||
$this->assertEquals('baz', $this->zip->getFileContent('foo/bar'));
|
||||
$this->assertSame('foo', $this->zip->getFileContent('bar'));
|
||||
$this->assertSame('baz', $this->zip->getFileContent('foo/bar'));
|
||||
}
|
||||
|
||||
public function testGetFileStream()
|
||||
@@ -72,8 +94,8 @@ class ZipRepositoryTest extends PHPUnit_Framework_TestCase
|
||||
$this->mock->shouldReceive('getStream')->once()
|
||||
->with('foo/bar')->andReturn('baz');
|
||||
|
||||
$this->assertEquals('foo', $this->zip->getFileStream('bar'));
|
||||
$this->assertEquals('baz', $this->zip->getFileStream('foo/bar'));
|
||||
$this->assertSame('foo', $this->zip->getFileStream('bar'));
|
||||
$this->assertSame('baz', $this->zip->getFileStream('foo/bar'));
|
||||
}
|
||||
|
||||
public function testFileExists()
|
||||
@@ -91,11 +113,4 @@ class ZipRepositoryTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->zip->close();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
414
vendor/chumper/zipper/tests/ZipperTest.php
vendored
414
vendor/chumper/zipper/tests/ZipperTest.php
vendored
@@ -1,14 +1,15 @@
|
||||
<?php
|
||||
|
||||
use Chumper\Zipper\Zipper;
|
||||
namespace Chumper\Zipper;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use InvalidArgumentException;
|
||||
use Mockery;
|
||||
use RuntimeException;
|
||||
|
||||
require_once 'ArrayArchive.php';
|
||||
|
||||
class ZipperTest extends PHPUnit_Framework_TestCase
|
||||
class ZipperTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var \Chumper\Zipper\Zipper
|
||||
*/
|
||||
@@ -19,78 +20,121 @@ class ZipperTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public $file;
|
||||
|
||||
public function __construct()
|
||||
protected function setUp()
|
||||
{
|
||||
$this->archive = new \Chumper\Zipper\Zipper(
|
||||
$this->file = Mockery::mock(new Filesystem)
|
||||
);
|
||||
$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->assertEquals('ArrayArchive', $this->archive->getArchiveType());
|
||||
$this->assertEquals('foo', $this->archive->getFilePath());
|
||||
$this->assertSame('Chumper\\Zipper\\ArrayArchive', $this->archive->getArchiveType());
|
||||
$this->assertSame('foo', $this->archive->getFilePath());
|
||||
}
|
||||
|
||||
public function testExtractTo()
|
||||
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(3)->andReturn(true);
|
||||
->times(1)->andReturn(true);
|
||||
$this->file->shouldReceive('isFile')->with('foo')
|
||||
->times(3)->andReturn(true);
|
||||
->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(array('foo.bar', 'bar.foo'));
|
||||
->once()->andReturn(['fileInFooDir.bar', 'fileInFooDir.foo']);
|
||||
|
||||
$this->file->shouldReceive('directories')->with('/path/to/fooDir')
|
||||
->once()->andReturn(array('fooSubdir'));
|
||||
->once()->andReturn(['fooSubdir']);
|
||||
|
||||
$this->file->shouldReceive('files')->with('/path/to/fooDir/fooSubdir')
|
||||
->once()->andReturn(array('foo.bar'));
|
||||
->once()->andReturn(['fileInFooDir.bar']);
|
||||
$this->file->shouldReceive('directories')->with('/path/to/fooDir/fooSubdir')
|
||||
->once()->andReturn(array());
|
||||
->once()->andReturn([]);
|
||||
|
||||
//test1
|
||||
$this->archive->add('foo.bar');
|
||||
$this->archive->add('foo');
|
||||
|
||||
$this->assertEquals('foo', $this->archive->getFileContent('foo'));
|
||||
$this->assertEquals('foo.bar', $this->archive->getFileContent('foo.bar'));
|
||||
|
||||
//test2
|
||||
$this->archive->add(array(
|
||||
'foo.bar',
|
||||
'foo'
|
||||
));
|
||||
$this->assertEquals('foo', $this->archive->getFileContent('foo'));
|
||||
$this->assertEquals('foo.bar', $this->archive->getFileContent('foo.bar'));
|
||||
|
||||
/**
|
||||
* test3:
|
||||
* 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->archive->folder('fooDir')->add('/path/to/fooDir');
|
||||
$this->assertEquals('fooDir/foo.bar', $this->archive->getFileContent('fooDir/foo.bar'));
|
||||
$this->assertEquals('fooDir/bar.foo', $this->archive->getFileContent('fooDir/bar.foo'));
|
||||
$this->assertEquals('fooDir/fooSubdir/foo.bar', $this->archive->getFileContent('fooDir/fooSubdir/foo.bar'));
|
||||
$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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
*/
|
||||
public function testGetFileContent()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage('The file "baz" cannot be found');
|
||||
|
||||
$this->archive->getFileContent('baz');
|
||||
}
|
||||
|
||||
@@ -114,12 +158,12 @@ class ZipperTest extends PHPUnit_Framework_TestCase
|
||||
$this->file->shouldReceive('isFile')->with('fooBar')
|
||||
->andReturn(true);
|
||||
|
||||
$this->archive->add(array('foo', 'fooBar'));
|
||||
$this->archive->add(['foo', 'fooBar']);
|
||||
|
||||
$this->assertTrue($this->archive->contains('foo'));
|
||||
$this->assertTrue($this->archive->contains('fooBar'));
|
||||
|
||||
$this->archive->remove(array('foo', 'fooBar'));
|
||||
$this->archive->remove(['foo', 'fooBar']);
|
||||
|
||||
$this->assertFalse($this->archive->contains('foo'));
|
||||
$this->assertFalse($this->archive->contains('fooBar'));
|
||||
@@ -127,53 +171,222 @@ class ZipperTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testExtractWhiteList()
|
||||
{
|
||||
$this->file->shouldReceive('isFile')->with('foo')
|
||||
$this->file
|
||||
->shouldReceive('isFile')
|
||||
->with('foo')
|
||||
->andReturn(true);
|
||||
|
||||
$this->archive->add('foo');
|
||||
|
||||
$this->file->shouldReceive('put')->with(realpath(NULL) . '/foo', 'foo');
|
||||
|
||||
$this->archive->extractTo('', array('foo'), Zipper::WHITELIST);
|
||||
|
||||
//----
|
||||
$this->file->shouldReceive('isFile')->with('foo')
|
||||
$this->file
|
||||
->shouldReceive('isFile')
|
||||
->with('foo.log')
|
||||
->andReturn(true);
|
||||
|
||||
$this->archive->folder('foo/bar')->add('foo');
|
||||
$this->archive
|
||||
->add('foo')
|
||||
->add('foo.log');
|
||||
|
||||
$this->file->shouldReceive('put')->with(realpath(NULL) . '/foo', 'foo/bar/foo');
|
||||
$this->file
|
||||
->shouldReceive('put')
|
||||
->with(realpath(null).DIRECTORY_SEPARATOR.'foo', 'foo');
|
||||
|
||||
$this->archive->extractTo('', array('foo'), Zipper::WHITELIST);
|
||||
$this->file
|
||||
->shouldReceive('put')
|
||||
->with(realpath(null).DIRECTORY_SEPARATOR.'foo.log', 'foo.log');
|
||||
|
||||
$this->archive
|
||||
->extractTo(getcwd(), ['foo'], Zipper::WHITELIST);
|
||||
}
|
||||
|
||||
public function testExtractBlackList()
|
||||
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');
|
||||
$this->archive->add('foo')
|
||||
->add('bar');
|
||||
|
||||
$this->file->shouldReceive('put')->with(realpath(NULL) . '/foo', 'foo');
|
||||
$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('', array(), Zipper::BLACKLIST);
|
||||
$this->archive->extractTo(getcwd(), ['bar'], Zipper::BLACKLIST);
|
||||
}
|
||||
|
||||
//----
|
||||
$this->file->shouldReceive('isFile')->with('foo')
|
||||
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('foo');
|
||||
$this->archive->folder('foo/bar')
|
||||
->add('baz')
|
||||
->add('baz.log');
|
||||
|
||||
$this->file->shouldReceive('put')->with(realpath(NULL) . '/foo', 'foo/bar/foo');
|
||||
$this->file->shouldReceive('put')->with(realpath(null).DIRECTORY_SEPARATOR.'baz.log', 'foo/bar/baz.log');
|
||||
|
||||
$this->archive->extractTo('', array('foo'), Zipper::BLACKLIST);
|
||||
$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->assertEquals('foo/bar', $this->archive->getCurrentFolderPath());
|
||||
$this->assertSame('foo/bar', $this->archive->getCurrentFolderPath());
|
||||
|
||||
//----
|
||||
|
||||
@@ -181,7 +394,7 @@ class ZipperTest extends PHPUnit_Framework_TestCase
|
||||
->andReturn(true);
|
||||
|
||||
$this->archive->add('foo');
|
||||
$this->assertEquals('foo/bar/foo', $this->archive->getFileContent('foo/bar/foo'));
|
||||
$this->assertSame('foo/bar/foo', $this->archive->getFileContent('foo/bar/foo'));
|
||||
|
||||
//----
|
||||
|
||||
@@ -189,7 +402,7 @@ class ZipperTest extends PHPUnit_Framework_TestCase
|
||||
->andReturn(true);
|
||||
|
||||
$this->archive->home()->add('bar');
|
||||
$this->assertEquals('bar', $this->archive->getFileContent('bar'));
|
||||
$this->assertSame('bar', $this->archive->getFileContent('bar'));
|
||||
|
||||
//----
|
||||
|
||||
@@ -197,8 +410,7 @@ class ZipperTest extends PHPUnit_Framework_TestCase
|
||||
->andReturn(true);
|
||||
|
||||
$this->archive->folder('test')->add('baz/bar/bing');
|
||||
$this->assertEquals('test/bing', $this->archive->getFileContent('test/bing'));
|
||||
|
||||
$this->assertSame('test/bing', $this->archive->getFileContent('test/bing'));
|
||||
}
|
||||
|
||||
public function testListFiles()
|
||||
@@ -207,32 +419,70 @@ class ZipperTest extends PHPUnit_Framework_TestCase
|
||||
$this->file->shouldReceive('isFile')->with('foo.file')->andReturn(true);
|
||||
$this->file->shouldReceive('isFile')->with('bar.file')->andReturn(true);
|
||||
|
||||
$this->assertEquals(array(), $this->archive->listFiles());
|
||||
$this->assertSame([], $this->archive->listFiles());
|
||||
|
||||
// testing not empty file
|
||||
$this->archive->add('foo.file');
|
||||
$this->archive->add('bar.file');
|
||||
|
||||
$this->assertEquals(array('foo.file', 'bar.file'), $this->archive->listFiles());
|
||||
$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(array());
|
||||
$this->file->shouldReceive('directories')->with('/path/to/subDirEmpty')->andReturn(array());
|
||||
$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->assertEquals(array('foo.file', 'bar.file'), $this->archive->listFiles());
|
||||
$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(array('sub.file'));
|
||||
$this->file->shouldReceive('directories')->with('/path/to/subDir')->andReturn(array());
|
||||
$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->assertEquals(array('foo.file', 'bar.file', 'subDir/sub.file'), $this->archive->listFiles());
|
||||
$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