GitArchiverTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\GitArchiver;
  13. /**
  14. * @author Till Klampaeckel <till@php.net>
  15. * @author Matthieu Moquet <matthieu@moquet.net>
  16. */
  17. class GitArchiverTest extends ArchiverTest
  18. {
  19. protected $targetFile;
  20. public function testZipArchive()
  21. {
  22. // Set up repository
  23. $this->setupGitRepo();
  24. $package = $this->setupPackage();
  25. $target = sys_get_temp_dir().'/composer_archiver_test.zip';
  26. // Test archive
  27. $archiver = new GitArchiver();
  28. $archiver->archive($package->getSourceUrl(), $target, 'zip', 'master');
  29. $this->assertFileExists($target);
  30. unlink($target);
  31. }
  32. public function testTarArchive()
  33. {
  34. // Set up repository
  35. $this->setupGitRepo();
  36. $package = $this->setupPackage();
  37. $target = sys_get_temp_dir().'/composer_archiver_test.tar';
  38. // Test archive
  39. $archiver = new GitArchiver();
  40. $archiver->archive($package->getSourceUrl(), $target, 'tar', 'master');
  41. $this->assertFileExists($target);
  42. unlink($target);
  43. }
  44. /**
  45. * Create local git repository to run tests against!
  46. */
  47. protected function setupGitRepo()
  48. {
  49. $currentWorkDir = getcwd();
  50. chdir($this->testDir);
  51. $result = $this->process->execute('git 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('git add b && git commit -m "commit b" -q');
  62. if ($result > 0) {
  63. chdir($currentWorkDir);
  64. throw new \RuntimeException('Could not commit: '.$this->process->getErrorOutput());
  65. }
  66. chdir($currentWorkDir);
  67. }
  68. }