MercurialArchiverTest.php 2.5 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\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. // Set up repository
  23. $this->setupMercurialRepo();
  24. $package = $this->setupPackage();
  25. $target = sys_get_temp_dir().'/composer_archiver_test.zip';
  26. // Test archive
  27. $archiver = new MercurialArchiver();
  28. $archiver->archive($package->getSourceUrl(), $target, 'zip', 'default');
  29. $this->assertFileExists($target);
  30. unlink($target);
  31. }
  32. public function testTarArchive()
  33. {
  34. // Set up repository
  35. $this->setupMercurialRepo();
  36. $package = $this->setupPackage();
  37. $target = sys_get_temp_dir().'/composer_archiver_test.tar';
  38. // Test archive
  39. $archiver = new MercurialArchiver();
  40. $archiver->archive($package->getSourceUrl(), $target, 'tar', 'default');
  41. $this->assertFileExists($target);
  42. unlink($target);
  43. }
  44. /**
  45. * Create local mercurial repository to run tests against!
  46. */
  47. protected function setupMercurialRepo()
  48. {
  49. $currentWorkDir = getcwd();
  50. chdir($this->testDir);
  51. $result = $this->process->execute('hg init -q');
  52. if ($result > 0) {
  53. chdir($currentWorkDir);
  54. throw new \RuntimeException('Could not init: '.$this->process->getErrorOutput());
  55. }
  56. $result = file_put_contents('b', 'a');
  57. if (false === $result) {
  58. chdir($currentWorkDir);
  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. chdir($currentWorkDir);
  64. throw new \RuntimeException('Could not commit: '.$this->process->getErrorOutput());
  65. }
  66. chdir($currentWorkDir);
  67. }
  68. protected function setupPackage()
  69. {
  70. $package = parent::setupPackage();
  71. $package->setSourceReference('default');
  72. $package->setSourceType('hg');
  73. return $package;
  74. }
  75. }