ZipTestCase.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace PhpZip;
  3. /**
  4. * PHPUnit test case and helper methods.
  5. */
  6. class ZipTestCase extends \PHPUnit_Framework_TestCase
  7. {
  8. /**
  9. * Assert correct zip archive.
  10. *
  11. * @param $filename
  12. */
  13. public static function assertCorrectZipArchive($filename)
  14. {
  15. if (DIRECTORY_SEPARATOR !== '\\' && `which zip`) {
  16. exec("zip -T " . escapeshellarg($filename), $output, $returnCode);
  17. $output = implode(PHP_EOL, $output);
  18. self::assertEquals($returnCode, 0);
  19. self::assertNotContains('zip error', $output);
  20. self::assertContains(' OK', $output);
  21. }
  22. }
  23. /**
  24. * Assert correct empty zip archive.
  25. *
  26. * @param $filename
  27. */
  28. public static function assertCorrectEmptyZip($filename)
  29. {
  30. if (DIRECTORY_SEPARATOR !== '\\' && `which zipinfo`) {
  31. exec("zipinfo " . escapeshellarg($filename), $output, $returnCode);
  32. $output = implode(PHP_EOL, $output);
  33. self::assertContains('Empty zipfile', $output);
  34. }
  35. $actualEmptyZipData = pack('VVVVVv', ZipConstants::END_OF_CENTRAL_DIRECTORY_RECORD_SIG, 0, 0, 0, 0, 0);
  36. self::assertEquals(file_get_contents($filename), $actualEmptyZipData);
  37. }
  38. }