PharArchiverTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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\PharArchiver;
  13. /**
  14. * @author Till Klampaeckel <till@php.net>
  15. * @author Matthieu Moquet <matthieu@moquet.net>
  16. */
  17. class PharArchiverTest extends ArchiverTest
  18. {
  19. public function testTarArchive()
  20. {
  21. // Set up repository
  22. $this->setupDummyRepo();
  23. $package = $this->setupPackage();
  24. $target = sys_get_temp_dir().'/composer_archiver_test.tar';
  25. // Test archive
  26. $archiver = new PharArchiver();
  27. $archiver->archive($package->getSourceUrl(), $target, 'tar');
  28. $this->assertFileExists($target);
  29. unlink($target);
  30. }
  31. public function testZipArchive()
  32. {
  33. // Set up repository
  34. $this->setupDummyRepo();
  35. $package = $this->setupPackage();
  36. $target = sys_get_temp_dir().'/composer_archiver_test.zip';
  37. // Test archive
  38. $archiver = new PharArchiver();
  39. $archiver->archive($package->getSourceUrl(), $target, 'zip');
  40. $this->assertFileExists($target);
  41. unlink($target);
  42. }
  43. /**
  44. * Create a local dummy repository to run tests against!
  45. */
  46. protected function setupDummyRepo()
  47. {
  48. $currentWorkDir = getcwd();
  49. chdir($this->testDir);
  50. $result = file_put_contents('b', 'a');
  51. if (false === $result) {
  52. chdir($currentWorkDir);
  53. throw new \RuntimeException('Could not save file.');
  54. }
  55. chdir($currentWorkDir);
  56. }
  57. }