ArtifactRepositoryTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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\Repository;
  12. use Composer\Repository\ArtifactRepository;
  13. use Composer\Test\TestCase;
  14. use Composer\IO\NullIO;
  15. use Composer\Config;
  16. use Composer\Package\BasePackage;
  17. class ArtifactRepositoryTest extends TestCase
  18. {
  19. public function setUp()
  20. {
  21. parent::setUp();
  22. if (!extension_loaded('zip')) {
  23. $this->markTestSkipped('You need the zip extension to run this test.');
  24. }
  25. }
  26. public function testExtractsConfigsFromZipArchives()
  27. {
  28. $expectedPackages = array(
  29. 'vendor0/package0-0.0.1',
  30. 'composer/composer-1.0.0-alpha6',
  31. 'vendor1/package2-4.3.2',
  32. 'vendor3/package1-5.4.3',
  33. 'test/jsonInRoot-1.0.0',
  34. 'test/jsonInFirstLevel-1.0.0',
  35. //The files not-an-artifact.zip and jsonSecondLevel are not valid
  36. //artifacts and do not get detected.
  37. );
  38. $coordinates = array('type' => 'artifact', 'url' => __DIR__ . '/Fixtures/artifacts');
  39. $repo = new ArtifactRepository($coordinates, new NullIO());
  40. $foundPackages = array_map(function (BasePackage $package) {
  41. return "{$package->getPrettyName()}-{$package->getPrettyVersion()}";
  42. }, $repo->getPackages());
  43. sort($expectedPackages);
  44. sort($foundPackages);
  45. $this->assertSame($expectedPackages, $foundPackages);
  46. }
  47. public function testAbsoluteRepoUrlCreatesAbsoluteUrlPackages()
  48. {
  49. $absolutePath = __DIR__ . '/Fixtures/artifacts';
  50. $coordinates = array('type' => 'artifact', 'url' => $absolutePath);
  51. $repo = new ArtifactRepository($coordinates, new NullIO());
  52. foreach ($repo->getPackages() as $package) {
  53. $this->assertSame(strpos($package->getDistUrl(), strtr($absolutePath, '\\', '/')), 0);
  54. }
  55. }
  56. public function testRelativeRepoUrlCreatesRelativeUrlPackages()
  57. {
  58. $relativePath = 'tests/Composer/Test/Repository/Fixtures/artifacts';
  59. $coordinates = array('type' => 'artifact', 'url' => $relativePath);
  60. $repo = new ArtifactRepository($coordinates, new NullIO());
  61. foreach ($repo->getPackages() as $package) {
  62. $this->assertSame(strpos($package->getDistUrl(), $relativePath), 0);
  63. }
  64. }
  65. }
  66. //Files jsonInFirstLevel.zip, jsonInRoot.zip and jsonInSecondLevel.zip were generated with:
  67. //
  68. //$archivesToCreate = array(
  69. // 'jsonInRoot' => array(
  70. // "extra.txt" => "Testing testing testing",
  71. // "composer.json" => '{ "name": "test/jsonInRoot", "version": "1.0.0" }',
  72. // "subdir/extra.txt" => "Testing testing testing",
  73. // "subdir/extra2.txt" => "Testing testing testing",
  74. // ),
  75. //
  76. // 'jsonInFirstLevel' => array(
  77. // "extra.txt" => "Testing testing testing",
  78. // "subdir/composer.json" => '{ "name": "test/jsonInFirstLevel", "version": "1.0.0" }',
  79. // "subdir/extra.txt" => "Testing testing testing",
  80. // "subdir/extra2.txt" => "Testing testing testing",
  81. // ),
  82. //
  83. // 'jsonInSecondLevel' => array(
  84. // "extra.txt" => "Testing testing testing",
  85. // "subdir/extra1.txt" => "Testing testing testing",
  86. // "subdir/foo/composer.json" => '{ "name": "test/jsonInSecondLevel", "version": "1.0.0" }',
  87. // "subdir/foo/extra1.txt" => "Testing testing testing",
  88. // "subdir/extra2.txt" => "Testing testing testing",
  89. // "subdir/extra3.txt" => "Testing testing testing",
  90. // ),
  91. //);
  92. //
  93. //foreach ($archivesToCreate as $archiveName => $fileDetails) {
  94. // $zipFile = new ZipArchive();
  95. // $zipFile->open("$archiveName.zip", ZIPARCHIVE::CREATE);
  96. //
  97. // foreach ($fileDetails as $filename => $fileContents) {
  98. // $zipFile->addFromString($filename, $fileContents);
  99. // }
  100. //
  101. // $zipFile->close();
  102. //}