ArtifactRepositoryTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. }
  40. //Files jsonInFirstLevel.zip, jsonInRoot.zip and jsonInSecondLevel.zip were generated with:
  41. //
  42. //$archivesToCreate = array(
  43. // 'jsonInRoot' => array(
  44. // "extra.txt" => "Testing testing testing",
  45. // "composer.json" => '{ "name": "test/jsonInRoot", "version": "1.0.0" }',
  46. // "subdir/extra.txt" => "Testing testing testing",
  47. // "subdir/extra2.txt" => "Testing testing testing",
  48. // ),
  49. //
  50. // 'jsonInFirstLevel' => array(
  51. // "extra.txt" => "Testing testing testing",
  52. // "subdir/composer.json" => '{ "name": "test/jsonInFirstLevel", "version": "1.0.0" }',
  53. // "subdir/extra.txt" => "Testing testing testing",
  54. // "subdir/extra2.txt" => "Testing testing testing",
  55. // ),
  56. //
  57. // 'jsonInSecondLevel' => array(
  58. // "extra.txt" => "Testing testing testing",
  59. // "subdir/extra1.txt" => "Testing testing testing",
  60. // "subdir/foo/composer.json" => '{ "name": "test/jsonInSecondLevel", "version": "1.0.0" }',
  61. // "subdir/foo/extra1.txt" => "Testing testing testing",
  62. // "subdir/extra2.txt" => "Testing testing testing",
  63. // "subdir/extra3.txt" => "Testing testing testing",
  64. // ),
  65. //);
  66. //
  67. //foreach($archivesToCreate as $archiveName => $fileDetails) {
  68. // $zipFile = new ZipArchive();
  69. // $zipFile->open("$archiveName.zip", ZIPARCHIVE::CREATE);
  70. //
  71. // foreach ($fileDetails as $filename => $fileContents) {
  72. // $zipFile->addFromString($filename, $fileContents);
  73. // }
  74. //
  75. // $zipFile->close();
  76. //}