ArtifactRepositoryTest.php 3.8 KB

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