diff --git a/src/PhpZip/ZipFile.php b/src/PhpZip/ZipFile.php index d7c3312..bc81b78 100644 --- a/src/PhpZip/ZipFile.php +++ b/src/PhpZip/ZipFile.php @@ -69,7 +69,6 @@ class ZipFile implements ZipFileInterface * @var ZipInputStreamInterface Input seekable input stream. */ protected $inputStream; - /** * @var ZipModel */ @@ -93,7 +92,7 @@ class ZipFile implements ZipFileInterface public function openFile($filename) { if (!file_exists($filename)) { - throw new ZipException("File $filename can't exists."); + throw new InvalidArgumentException("File $filename does not exist."); } if (!($handle = @fopen($filename, 'rb'))) { throw new ZipException("File $filename can't open."); @@ -560,10 +559,10 @@ class ZipFile implements ZipFileInterface } $inputDir = (string)$inputDir; if (strlen($inputDir) === 0) { - throw new InvalidArgumentException('Input dir empty'); + throw new InvalidArgumentException('The input directory is not specified'); } if (!is_dir($inputDir)) { - throw new ZipException('Directory ' . $inputDir . ' can\'t exists'); + throw new InvalidArgumentException(sprintf('The "%s" directory does not exist.', $inputDir)); } $inputDir = rtrim($inputDir, '/\\') . DIRECTORY_SEPARATOR; @@ -587,12 +586,15 @@ class ZipFile implements ZipFileInterface */ public function addDirRecursive($inputDir, $localPath = "/", $compressionMethod = null) { + if ($inputDir === null) { + throw new InvalidArgumentException('Input dir is null'); + } $inputDir = (string)$inputDir; - if (null === $inputDir || strlen($inputDir) === 0) { - throw new InvalidArgumentException('Input dir empty'); + if (strlen($inputDir) === 0) { + throw new InvalidArgumentException('The input directory is not specified'); } if (!is_dir($inputDir)) { - throw new InvalidArgumentException('Directory ' . $inputDir . ' can\'t exists'); + throw new InvalidArgumentException(sprintf('The "%s" directory does not exist.', $inputDir)); } $inputDir = rtrim($inputDir, '/\\') . DIRECTORY_SEPARATOR; @@ -703,16 +705,19 @@ class ZipFile implements ZipFileInterface $recursive = true, $compressionMethod = null ) { + if ($inputDir === null) { + throw new InvalidArgumentException('Input dir is null'); + } $inputDir = (string)$inputDir; if (strlen($inputDir) === 0) { - throw new InvalidArgumentException('Input dir empty'); + throw new InvalidArgumentException('The input directory is not specified'); } if (!is_dir($inputDir)) { - throw new ZipException('Directory ' . $inputDir . ' can\'t exists'); + throw new InvalidArgumentException(sprintf('The "%s" directory does not exist.', $inputDir)); } $globPattern = (string)$globPattern; if (empty($globPattern)) { - throw new InvalidArgumentException("glob pattern empty"); + throw new InvalidArgumentException('The glob pattern is not specified'); } $inputDir = rtrim($inputDir, '/\\') . DIRECTORY_SEPARATOR; @@ -801,14 +806,14 @@ class ZipFile implements ZipFileInterface ) { $regexPattern = (string)$regexPattern; if (empty($regexPattern)) { - throw new InvalidArgumentException("regex pattern empty"); + throw new InvalidArgumentException('The regex pattern is not specified'); } $inputDir = (string)$inputDir; if (strlen($inputDir) === 0) { - throw new InvalidArgumentException('Input dir empty'); + throw new InvalidArgumentException('The input directory is not specified'); } if (!is_dir($inputDir)) { - throw new InvalidArgumentException('Directory ' . $inputDir . ' can\'t exists'); + throw new InvalidArgumentException(sprintf('The "%s" directory does not exist.', $inputDir)); } $inputDir = rtrim($inputDir, '/\\') . DIRECTORY_SEPARATOR; @@ -876,7 +881,6 @@ class ZipFile implements ZipFileInterface * @param string $oldName Old entry name. * @param string $newName New entry name. * @return ZipFileInterface - * * @throws ZipException */ public function rename($oldName, $newName) @@ -918,7 +922,7 @@ class ZipFile implements ZipFileInterface public function deleteFromGlob($globPattern) { if ($globPattern === null || !is_string($globPattern) || empty($globPattern)) { - throw new InvalidArgumentException("Glob pattern is empty"); + throw new InvalidArgumentException("The glob pattern is not specified"); } $globPattern = '~' . FilesUtil::convertGlobToRegEx($globPattern) . '~si'; $this->deleteFromRegex($globPattern); @@ -934,7 +938,7 @@ class ZipFile implements ZipFileInterface public function deleteFromRegex($regexPattern) { if ($regexPattern === null || !is_string($regexPattern) || empty($regexPattern)) { - throw new InvalidArgumentException("Regex pattern is empty."); + throw new InvalidArgumentException("The regex pattern is not specified"); } $this->matcher()->match($regexPattern)->delete(); return $this; diff --git a/tests/PhpZip/ZipFileTest.php b/tests/PhpZip/ZipFileTest.php index 24a4d05..a1eb639 100644 --- a/tests/PhpZip/ZipFileTest.php +++ b/tests/PhpZip/ZipFileTest.php @@ -19,7 +19,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\ZipException - * @expectedExceptionMessage can't exists + * @expectedExceptionMessage does not exist */ public function testOpenFileCantExists() { @@ -1292,7 +1292,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage Input dir is null + * @expectedExceptionMessage The input directory is not specified * @throws ZipException */ public function testAddDirNullDirname() @@ -1303,7 +1303,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage Input dir empty + * @expectedExceptionMessage The input directory is not specified * @throws ZipException */ public function testAddDirEmptyDirname() @@ -1314,7 +1314,8 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\ZipException - * @expectedExceptionMessage can't exists + * @expectedExceptionMessage does not exist + * @throws ZipException */ public function testAddDirCantExists() { @@ -1324,7 +1325,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage Input dir empty + * @expectedExceptionMessage The input directory is not specified * @throws ZipException */ public function testAddDirRecursiveNullDirname() @@ -1335,7 +1336,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage Input dir empty + * @expectedExceptionMessage The input directory is not specified * @throws ZipException */ public function testAddDirRecursiveEmptyDirname() @@ -1346,7 +1347,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage can't exists + * @expectedExceptionMessage does not exist * @throws ZipException */ public function testAddDirRecursiveCantExists() @@ -1357,7 +1358,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage Input dir empty + * @expectedExceptionMessage The input directory is not specified * @throws ZipException */ public function testAddFilesFromGlobNull() @@ -1368,7 +1369,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage Input dir empty + * @expectedExceptionMessage The input directory is not specified * @throws ZipException */ public function testAddFilesFromGlobEmpty() @@ -1378,8 +1379,9 @@ class ZipFileTest extends ZipTestCase } /** - * @expectedException \PhpZip\Exception\ZipException - * @expectedExceptionMessage can't exists + * @expectedException \PhpZip\Exception\InvalidArgumentException + * @expectedExceptionMessage does not exist + * @throws ZipException */ public function testAddFilesFromGlobCantExists() { @@ -1389,7 +1391,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage glob pattern empty + * @expectedExceptionMessage The glob pattern is not specified * @throws ZipException */ public function testAddFilesFromGlobNullPattern() @@ -1400,7 +1402,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage glob pattern empty + * @expectedExceptionMessage The glob pattern is not specified * @throws ZipException */ public function testAddFilesFromGlobEmptyPattern() @@ -1411,7 +1413,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage Input dir empty + * @expectedExceptionMessage The input directory is not specified * @throws ZipException */ public function testAddFilesFromGlobRecursiveNull() @@ -1422,7 +1424,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage Input dir empty + * @expectedExceptionMessage The input directory is not specified * @throws ZipException */ public function testAddFilesFromGlobRecursiveEmpty() @@ -1432,8 +1434,8 @@ class ZipFileTest extends ZipTestCase } /** - * @expectedException \PhpZip\Exception\ZipException - * @expectedExceptionMessage can't exists + * @expectedException \PhpZip\Exception\InvalidArgumentException + * @expectedExceptionMessage does not exist * @throws ZipException */ public function testAddFilesFromGlobRecursiveCantExists() @@ -1444,7 +1446,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage glob pattern empty + * @expectedExceptionMessage The glob pattern is not specified * @throws ZipException */ public function testAddFilesFromGlobRecursiveNullPattern() @@ -1455,7 +1457,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage glob pattern empty + * @expectedExceptionMessage The glob pattern is not specified * @throws ZipException */ public function testAddFilesFromGlobRecursiveEmptyPattern() @@ -1466,7 +1468,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage Input dir empty + * @expectedExceptionMessage The input directory is not specified * @throws ZipException */ public function testAddFilesFromRegexDirectoryNull() @@ -1477,7 +1479,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage Input dir empty + * @expectedExceptionMessage The input directory is not specified * @throws ZipException */ public function testAddFilesFromRegexDirectoryEmpty() @@ -1488,7 +1490,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage can't exists + * @expectedExceptionMessage does not exist * @throws ZipException */ public function testAddFilesFromRegexCantExists() @@ -1499,7 +1501,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage regex pattern empty + * @expectedExceptionMessage The regex pattern is not specified * @throws ZipException */ public function testAddFilesFromRegexNullPattern() @@ -1510,7 +1512,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage regex pattern empty + * @expectedExceptionMessage The regex pattern is not specified * @throws ZipException */ public function testAddFilesFromRegexEmptyPattern() @@ -1521,7 +1523,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage Input dir empty + * @expectedExceptionMessage The input directory is not specified * @throws ZipException */ public function testAddFilesFromRegexRecursiveDirectoryNull() @@ -1532,7 +1534,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage Input dir empty + * @expectedExceptionMessage The input directory is not specified * @throws ZipException */ public function testAddFilesFromRegexRecursiveEmpty() @@ -1543,7 +1545,8 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\ZipException - * @expectedExceptionMessage can't exists + * @expectedExceptionMessage does not exist + * @throws ZipException */ public function testAddFilesFromRegexRecursiveCantExists() { @@ -1553,7 +1556,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage regex pattern empty + * @expectedExceptionMessage The regex pattern is not specified * @throws ZipException */ public function testAddFilesFromRegexRecursiveNullPattern() @@ -1564,7 +1567,7 @@ class ZipFileTest extends ZipTestCase /** * @expectedException \PhpZip\Exception\InvalidArgumentException - * @expectedExceptionMessage regex pattern empty + * @expectedExceptionMessage The regex pattern is not specified * @throws ZipException */ public function testAddFilesFromRegexRecursiveEmptyPattern()