ArtifactRepositoryTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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\Test\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. );
  28. $coordinates = array('type' => 'artifact', 'url' => __DIR__ . '/Fixtures/artifacts/correct');
  29. $repo = new ArtifactRepository($coordinates, new NullIO(), new Config());
  30. $foundPackages = array_map(function(BasePackage $package) {
  31. return "{$package->getPrettyName()}-{$package->getPrettyVersion()}";
  32. }, $repo->getPackages());
  33. sort($expectedPackages);
  34. sort($foundPackages);
  35. $this->assertSame($expectedPackages, $foundPackages);
  36. }
  37. public function testExtractConfigFails()
  38. {
  39. $this->setExpectedException('RuntimeException', "Shouldn't have picked up composer.json from a location other than root or first level directory.");
  40. $coordinates = array('type' => 'artifact', 'url' => __DIR__ . '/Fixtures/artifacts/error/jsonWrongDirectory');
  41. new ArtifactRepository($coordinates, new NullIO(), new Config());
  42. }
  43. }
  44. //$archivesToCreate = array(
  45. // 'jsonInRoot' => array(
  46. // "extra.txt" => "Testing testing testing",
  47. // "composer.json" => '{ "name": "test/jsonInRoot", "version": "1.0.0" }',
  48. // "subdir/extra.txt" => "Testing testing testing",
  49. // "subdir/extra2.txt" => "Testing testing testing",
  50. // ),
  51. //
  52. // 'jsonInFirstLevel' => array(
  53. // "extra.txt" => "Testing testing testing",
  54. // "subdir/composer.json" => '{ "name": "test/jsonInFirstLevel", "version": "1.0.0" }',
  55. // "subdir/extra.txt" => "Testing testing testing",
  56. // "subdir/extra2.txt" => "Testing testing testing",
  57. // ),
  58. //
  59. // 'jsonInSecondLevel' => array(
  60. // "extra.txt" => "Testing testing testing",
  61. // "subdir/extra1.txt" => "Testing testing testing",
  62. // "subdir/foo/composer.json" => '{ "name": "test/jsonInSecondLevel", "version": "1.0.0" }',
  63. // "subdir/foo/extra1.txt" => "Testing testing testing",
  64. // "subdir/extra2.txt" => "Testing testing testing",
  65. // "subdir/extra3.txt" => "Testing testing testing",
  66. // ),
  67. //);
  68. //
  69. //foreach($archivesToCreate as $archiveName => $fileDetails) {
  70. // $zipFile = new ZipArchive();
  71. // $zipFile->open("$archiveName.zip", ZIPARCHIVE::CREATE);
  72. //
  73. // foreach ($fileDetails as $filename => $fileContents) {
  74. // $zipFile->addFromString($filename, $fileContents);
  75. // }
  76. //
  77. // $zipFile->close();
  78. //}