MercurialArchiverTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\MercurialArchiver;
  13. use Composer\Package\Package;
  14. /**
  15. * @author Matthieu Moquet <matthieu@moquet.net>
  16. * @author Till Klampaeckel <till@php.net>
  17. */
  18. class MercurialArchiverTest extends ArchiverTest
  19. {
  20. public function testZipArchive()
  21. {
  22. $this->setupMercurialRepo();
  23. $package = $this->setupMercurialPackage();
  24. $target = sys_get_temp_dir().'/composer_archiver_test.zip';
  25. // Test archive
  26. $archiver = new MercurialArchiver();
  27. $archiver->archive($package->getSourceUrl(), $target, 'zip', 'default');
  28. $this->assertFileExists($target);
  29. unlink($target);
  30. $this->removeMercurialRepo();
  31. }
  32. public function testTarArchive()
  33. {
  34. $this->setupMercurialRepo();
  35. $package = $this->setupMercurialPackage();
  36. $target = sys_get_temp_dir().'/composer_archiver_test.tar';
  37. // Test archive
  38. $archiver = new MercurialArchiver();
  39. $archiver->archive($package->getSourceUrl(), $target, 'tar', 'default');
  40. $this->assertFileExists($target);
  41. unlink($target);
  42. $this->removeMercurialRepo();
  43. }
  44. /**
  45. * Create local git repository to run tests against!
  46. */
  47. protected function setupMercurialRepo()
  48. {
  49. $this->filesystem->removeDirectory($this->testDir);
  50. $this->filesystem->ensureDirectoryExists($this->testDir);
  51. $currentWorkDir = getcwd();
  52. chdir($this->testDir);
  53. $result = $this->process->execute('hg init -q');
  54. if ($result > 0) {
  55. throw new \RuntimeException('Could not init: '.$this->process->getErrorOutput());
  56. }
  57. $result = file_put_contents('b', 'a');
  58. if (false === $result) {
  59. throw new \RuntimeException('Could not save file.');
  60. }
  61. $result = $this->process->execute('hg add b && hg commit -m "commit b" --config ui.username=test -q');
  62. if ($result > 0) {
  63. throw new \RuntimeException('Could not commit: '.$this->process->getErrorOutput());
  64. }
  65. chdir($currentWorkDir);
  66. }
  67. protected function removeMercurialRepo()
  68. {
  69. $this->filesystem->removeDirectory($this->testDir);
  70. }
  71. protected function setupMercurialPackage()
  72. {
  73. $package = new Package('archivertest/archivertest', 'master', 'master');
  74. $package->setSourceUrl(realpath($this->testDir));
  75. $package->setSourceReference('default');
  76. $package->setSourceType('hg');
  77. return $package;
  78. }
  79. }