ArchiveManagerTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Package\Archiver;
  12. use Composer\Package\Archiver;
  13. use Composer\Package\Archiver\ArchiveManager;
  14. use Composer\Package\PackageInterface;
  15. /**
  16. * @author Till Klampaeckel <till@php.net>
  17. * @author Matthieu Moquet <matthieu@moquet.net>
  18. */
  19. class ArchiveManagerTest extends ArchiverTest
  20. {
  21. protected $manager;
  22. protected $workDir;
  23. public function setUp()
  24. {
  25. parent::setUp();
  26. $this->workDir = sys_get_temp_dir();
  27. $this->manager = new ArchiveManager($this->workDir);
  28. $this->manager->addArchiver(new Archiver\GitArchiver);
  29. $this->manager->addArchiver(new Archiver\MercurialArchiver);
  30. $this->manager->addArchiver(new Archiver\PharArchiver);
  31. }
  32. public function testUnknownFormat()
  33. {
  34. $this->setExpectedException('RuntimeException');
  35. $package = $this->setupPackage();
  36. $this->manager->archive($package, '__unknown_format__');
  37. }
  38. public function testArchiveTarWithVcs()
  39. {
  40. $this->setupGitRepo();
  41. $package = $this->setupPackage();
  42. // The package is source from git,
  43. // so it should `git archive --format tar`
  44. $this->manager->archive($package, 'tar');
  45. $target = $this->getTargetName($package, 'tar');
  46. $this->assertFileExists($target);
  47. unlink($target);
  48. $this->removeGitRepo();
  49. }
  50. public function testArchiveTarWithoutVcs()
  51. {
  52. $this->setupGitRepo();
  53. $package = $this->setupPackage();
  54. // This should use the TarArchiver
  55. $this->manager->archive($package, 'tar');
  56. $package->setSourceType('__unknown_type__'); // disable VCS recognition
  57. $target = $this->getTargetName($package, 'tar');
  58. $this->assertFileExists($target);
  59. unlink($target);
  60. $this->removeGitRepo();
  61. }
  62. protected function getTargetName(PackageInterface $package, $format)
  63. {
  64. $packageName = str_replace('/', DIRECTORY_SEPARATOR, $package->getUniqueName());
  65. $target = $this->workDir.DIRECTORY_SEPARATOR.$packageName.'.'.$format;
  66. return $target;
  67. }
  68. }