FunctionalTestCase.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Alchemy\Zippy\Functional;
  3. use Alchemy\Zippy\Adapter\AdapterInterface;
  4. use Alchemy\Zippy\Adapter\AdapterContainer;
  5. use Symfony\Component\Filesystem\Filesystem;
  6. abstract class FunctionalTestCase extends \PHPUnit_Framework_TestCase
  7. {
  8. public function tearDown()
  9. {
  10. $filesystem = new Filesystem();
  11. $filesystem->remove(__DIR__ . '/samples/tmp');
  12. mkdir(__DIR__ . '/samples/tmp');
  13. }
  14. /**
  15. * @return AdapterInterface
  16. */
  17. protected function getAdapter()
  18. {
  19. if (false === getenv('ZIPPY_ADAPTER')) {
  20. throw new \RuntimeException('ZIPPY_ADAPTER environment variable is not set');
  21. }
  22. $adapter = 'Alchemy\\Zippy\\Adapter\\' . getenv('ZIPPY_ADAPTER');
  23. if (!class_exists($adapter)) {
  24. throw new \InvalidArgumentException(sprintf('class %s does not exist', $adapter));
  25. }
  26. $container = AdapterContainer::load();
  27. $adapter = $container[$adapter];
  28. if (!$adapter->isSupported()) {
  29. $this->markTestSkipped(sprintf('Adapter %s is not supported', $adapter->getName()));
  30. }
  31. return $adapter;
  32. }
  33. protected function getArchiveFileForAdapter($adapter)
  34. {
  35. switch (get_class($adapter)) {
  36. case 'Alchemy\Zippy\Adapter\ZipAdapter':
  37. case 'Alchemy\Zippy\Adapter\ZipExtensionAdapter':
  38. return __DIR__ . '/samples/archive.zip';
  39. break;
  40. case 'Alchemy\Zippy\Adapter\BSDTar\TarGzBSDTarAdapter':
  41. case 'Alchemy\Zippy\Adapter\GNUTar\TarGzGNUTarAdapter':
  42. return __DIR__ . '/samples/archive.tar.gz';
  43. break;
  44. case 'Alchemy\Zippy\Adapter\BSDTar\TarBz2BSDTarAdapter':
  45. case 'Alchemy\Zippy\Adapter\GNUTar\TarBz2GNUTarAdapter':
  46. return __DIR__ . '/samples/archive.tar.bz2';
  47. break;
  48. case 'Alchemy\Zippy\Adapter\BSDTar\TarBSDTarAdapter':
  49. case 'Alchemy\Zippy\Adapter\GNUTar\TarGNUTarAdapter':
  50. return __DIR__ . '/samples/archive.tar';
  51. break;
  52. default:
  53. throw new \InvalidArgumentException(sprintf('Unable to find an archive file for %s', get_class($adapter)));
  54. break;
  55. }
  56. }
  57. protected function getArchiveExtensionForAdapter($adapter)
  58. {
  59. switch (get_class($adapter)) {
  60. case 'Alchemy\Zippy\Adapter\ZipAdapter':
  61. case 'Alchemy\Zippy\Adapter\ZipExtensionAdapter':
  62. return 'zip';
  63. break;
  64. case 'Alchemy\Zippy\Adapter\BSDTar\TarGzBSDTarAdapter':
  65. case 'Alchemy\Zippy\Adapter\GNUTar\TarGzGNUTarAdapter':
  66. return 'tar.gz';
  67. break;
  68. case 'Alchemy\Zippy\Adapter\BSDTar\TarBz2BSDTarAdapter':
  69. case 'Alchemy\Zippy\Adapter\GNUTar\TarBz2GNUTarAdapter':
  70. return 'tar.bz2';
  71. break;
  72. case 'Alchemy\Zippy\Adapter\BSDTar\TarBSDTarAdapter':
  73. case 'Alchemy\Zippy\Adapter\GNUTar\TarGNUTarAdapter':
  74. return 'tar';
  75. break;
  76. default:
  77. throw new \InvalidArgumentException(sprintf('Unable to find an archive file for %s', get_class($adapter)));
  78. break;
  79. }
  80. }
  81. }