Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Zend\Filter\Compress\Tar::setMode() should work with case-insensitive -
Browse files Browse the repository at this point in the history
  • Loading branch information
sasezaki authored and Ocramius committed Apr 9, 2014
1 parent 79a0d3d commit 1a04c2e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Compress/Tar.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,16 @@ public function getMode()
*/
public function setMode($mode)
{
$mode = ucfirst(strtolower($mode));
if (($mode != 'Bz2') && ($mode != 'Gz')) {
$mode = strtolower($mode);
if (($mode != 'bz2') && ($mode != 'gz')) {
throw new Exception\InvalidArgumentException("The mode '$mode' is unknown");
}

if (($mode == 'Bz2') && (!extension_loaded('bz2'))) {
if (($mode == 'bz2') && (!extension_loaded('bz2'))) {
throw new Exception\ExtensionNotLoadedException('This mode needs the bz2 extension');
}

if (($mode == 'Gz') && (!extension_loaded('zlib'))) {
if (($mode == 'gz') && (!extension_loaded('zlib'))) {
throw new Exception\ExtensionNotLoadedException('This mode needs the zlib extension');
}

Expand Down
18 changes: 17 additions & 1 deletion test/Compress/TarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public function tearDown()
dirname(__DIR__) . '/_files/_compress/Compress',
dirname(__DIR__) . '/_files/_compress/zipextracted.txt',
dirname(__DIR__) . '/_files/_compress',
dirname(__DIR__) . '/_files/compressed.tar'
dirname(__DIR__) . '/_files/compressed.tar',
dirname(__DIR__) . '/_files/compressed.tar.gz',
dirname(__DIR__) . '/_files/compressed.tar.bz2'
);

foreach ($files as $file) {
Expand Down Expand Up @@ -215,6 +217,20 @@ public function testTarCompressDirectory()
. DIRECTORY_SEPARATOR . 'compressed.tar', $content);
}

public function testSetModeShouldWorkWithCaseInsensitive()
{
$filter = new TarCompression;
$filter->setTarget(dirname(__DIR__).'/_files/zipextracted.txt');

foreach(array('GZ', 'Bz2') as $mode) {
$archive = dirname(__DIR__).'/_files/compressed.tar.'.strtolower($mode);
$filter->setArchive($archive);
$filter->setMode($mode);
$content = $filter->compress('compress me');
$this->assertEquals($archive, $content);
}
}

/**
* testing toString
*
Expand Down

0 comments on commit 1a04c2e

Please sign in to comment.