ArtifactRepositoryTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. );
  27. $coordinates = array('type' => 'artifact', 'url' => __DIR__ . '/Fixtures/artifacts');
  28. $repo = new ArtifactRepository($coordinates, new NullIO(), new Config());
  29. $foundPackages = array_map(function(BasePackage $package) {
  30. return "{$package->getPrettyName()}-{$package->getPrettyVersion()}";
  31. }, $repo->getPackages());
  32. sort($expectedPackages);
  33. sort($foundPackages);
  34. $this->assertSame($expectedPackages, $foundPackages);
  35. }
  36. public function testAbsoluteRepoUrlCreatesAbsoluteUrlPackages()
  37. {
  38. $absolutePath = __DIR__ . '/Fixtures/artifacts';
  39. $coordinates = array('type' => 'artifact', 'url' => $absolutePath);
  40. $repo = new ArtifactRepository($coordinates, new NullIO(), new Config());
  41. foreach ($repo->getPackages() as $package) {
  42. $this->assertTrue(strpos($package->getDistUrl(), $absolutePath) === 0);
  43. }
  44. }
  45. public function testRelativeRepoUrlCreatesRelativeUrlPackages()
  46. {
  47. $relativePath = 'tests/Composer/Test/Repository/Fixtures/artifacts';
  48. $coordinates = array('type' => 'artifact', 'url' => $relativePath);
  49. $repo = new ArtifactRepository($coordinates, new NullIO(), new Config());
  50. foreach ($repo->getPackages() as $package) {
  51. $this->assertTrue(strpos($package->getDistUrl(), $relativePath) === 0);
  52. }
  53. }
  54. }