ArchiveManagerTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\TarArchiver);
  31. $this->manager->addArchiver(new Archiver\ZipArchiver);
  32. }
  33. public function testUnknownFormat()
  34. {
  35. $this->setExpectedException('RuntimeException');
  36. $package = $this->setupPackage();
  37. $this->manager->archive($package, '__unknown_format__');
  38. }
  39. public function testArchiveTarWithVcs()
  40. {
  41. $this->setupGitRepo();
  42. $package = $this->setupPackage();
  43. // The package is source from git,
  44. // so it should `git archive --format tar`
  45. $this->manager->archive($package, 'tar');
  46. $target = $this->getTargetName($package, 'tar');
  47. $this->assertFileExists($target);
  48. unlink($target);
  49. $this->removeGitRepo();
  50. }
  51. public function testArchiveTarWithoutVcs()
  52. {
  53. $this->setupGitRepo();
  54. $package = $this->setupPackage();
  55. // This should use the TarArchiver
  56. $this->manager->archive($package, 'tar');
  57. $package->setSourceType('__unknown_type__'); // disable VCS recognition
  58. $target = $this->getTargetName($package, 'tar');
  59. $this->assertFileExists($target);
  60. unlink($target);
  61. $this->removeGitRepo();
  62. }
  63. protected function getTargetName(PackageInterface $package, $format)
  64. {
  65. $packageName = str_replace('/', DIRECTORY_SEPARATOR, $package->getUniqueName());
  66. $target = $this->workDir.DIRECTORY_SEPARATOR.$packageName.'.'.$format;
  67. return $target;
  68. }
  69. }