ArtifactRepositoryTest.php 3.8 KB

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