ArtifactRepositoryTest.php 4.0 KB

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