2013-03-24 19:27:50 +00:00
|
|
|
<?php
|
2013-03-24 23:41:10 +00:00
|
|
|
|
2013-03-24 19:27:50 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2016-10-05 08:45:22 +00:00
|
|
|
namespace Composer\Test\Repository;
|
2013-03-24 19:27:50 +00:00
|
|
|
|
2016-10-05 08:45:22 +00:00
|
|
|
use Composer\Repository\ArtifactRepository;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2013-03-24 19:27:50 +00:00
|
|
|
use Composer\IO\NullIO;
|
2013-03-31 19:44:48 +00:00
|
|
|
use Composer\Package\BasePackage;
|
2013-03-24 19:27:50 +00:00
|
|
|
|
|
|
|
class ArtifactRepositoryTest extends TestCase
|
|
|
|
{
|
2021-12-08 16:03:05 +00:00
|
|
|
public function setUp(): void
|
2015-01-08 07:56:12 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
if (!extension_loaded('zip')) {
|
|
|
|
$this->markTestSkipped('You need the zip extension to run this test.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testExtractsConfigsFromZipArchives(): void
|
2013-03-24 23:41:10 +00:00
|
|
|
{
|
2013-03-24 19:27:50 +00:00
|
|
|
$expectedPackages = array(
|
2013-03-31 20:01:55 +00:00
|
|
|
'vendor0/package0-0.0.1',
|
2013-03-31 19:53:34 +00:00
|
|
|
'composer/composer-1.0.0-alpha6',
|
2013-03-24 19:27:50 +00:00
|
|
|
'vendor1/package2-4.3.2',
|
2013-06-13 14:20:52 +00:00
|
|
|
'vendor3/package1-5.4.3',
|
2014-02-20 17:30:51 +00:00
|
|
|
'test/jsonInRoot-1.0.0',
|
2020-08-12 18:30:58 +00:00
|
|
|
'test/jsonInRootTarFile-1.0.0',
|
2014-02-21 09:44:04 +00:00
|
|
|
'test/jsonInFirstLevel-1.0.0',
|
2014-06-10 14:02:44 +00:00
|
|
|
//The files not-an-artifact.zip and jsonSecondLevel are not valid
|
2014-02-21 09:44:04 +00:00
|
|
|
//artifacts and do not get detected.
|
2013-03-24 19:27:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$coordinates = array('type' => 'artifact', 'url' => __DIR__ . '/Fixtures/artifacts');
|
2018-11-12 14:23:32 +00:00
|
|
|
$repo = new ArtifactRepository($coordinates, new NullIO());
|
2013-03-24 19:27:50 +00:00
|
|
|
|
2014-06-10 14:02:44 +00:00
|
|
|
$foundPackages = array_map(function (BasePackage $package) {
|
2013-03-24 19:27:50 +00:00
|
|
|
return "{$package->getPrettyName()}-{$package->getPrettyVersion()}";
|
|
|
|
}, $repo->getPackages());
|
|
|
|
|
2013-03-31 20:01:55 +00:00
|
|
|
sort($expectedPackages);
|
|
|
|
sort($foundPackages);
|
|
|
|
|
|
|
|
$this->assertSame($expectedPackages, $foundPackages);
|
2020-08-12 18:30:58 +00:00
|
|
|
|
|
|
|
$tarPackage = array_filter($repo->getPackages(), function (BasePackage $package) {
|
|
|
|
return $package->getPrettyName() === 'test/jsonInRootTarFile';
|
|
|
|
});
|
|
|
|
$this->assertCount(1, $tarPackage);
|
|
|
|
$tarPackage = array_pop($tarPackage);
|
|
|
|
$this->assertSame('tar', $tarPackage->getDistType());
|
2013-03-24 19:27:50 +00:00
|
|
|
}
|
2014-02-18 22:28:45 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testAbsoluteRepoUrlCreatesAbsoluteUrlPackages(): void
|
2014-02-18 22:28:45 +00:00
|
|
|
{
|
|
|
|
$absolutePath = __DIR__ . '/Fixtures/artifacts';
|
|
|
|
$coordinates = array('type' => 'artifact', 'url' => $absolutePath);
|
2018-11-12 14:23:32 +00:00
|
|
|
$repo = new ArtifactRepository($coordinates, new NullIO());
|
2014-02-18 22:28:45 +00:00
|
|
|
|
|
|
|
foreach ($repo->getPackages() as $package) {
|
2017-12-03 04:41:58 +00:00
|
|
|
$this->assertSame(strpos($package->getDistUrl(), strtr($absolutePath, '\\', '/')), 0);
|
2014-02-18 22:28:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testRelativeRepoUrlCreatesRelativeUrlPackages(): void
|
2014-02-18 22:28:45 +00:00
|
|
|
{
|
|
|
|
$relativePath = 'tests/Composer/Test/Repository/Fixtures/artifacts';
|
|
|
|
$coordinates = array('type' => 'artifact', 'url' => $relativePath);
|
2018-11-12 14:23:32 +00:00
|
|
|
$repo = new ArtifactRepository($coordinates, new NullIO());
|
2014-02-18 22:28:45 +00:00
|
|
|
|
|
|
|
foreach ($repo->getPackages() as $package) {
|
2017-12-03 04:41:58 +00:00
|
|
|
$this->assertSame(strpos($package->getDistUrl(), $relativePath), 0);
|
2014-02-18 22:28:45 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-24 19:27:50 +00:00
|
|
|
}
|
2014-02-20 17:30:51 +00:00
|
|
|
|
2014-02-21 09:49:12 +00:00
|
|
|
//Files jsonInFirstLevel.zip, jsonInRoot.zip and jsonInSecondLevel.zip were generated with:
|
|
|
|
//
|
2014-02-20 17:30:51 +00:00
|
|
|
//$archivesToCreate = array(
|
|
|
|
// 'jsonInRoot' => array(
|
|
|
|
// "extra.txt" => "Testing testing testing",
|
|
|
|
// "composer.json" => '{ "name": "test/jsonInRoot", "version": "1.0.0" }',
|
|
|
|
// "subdir/extra.txt" => "Testing testing testing",
|
|
|
|
// "subdir/extra2.txt" => "Testing testing testing",
|
|
|
|
// ),
|
|
|
|
//
|
|
|
|
// 'jsonInFirstLevel' => array(
|
|
|
|
// "extra.txt" => "Testing testing testing",
|
|
|
|
// "subdir/composer.json" => '{ "name": "test/jsonInFirstLevel", "version": "1.0.0" }',
|
|
|
|
// "subdir/extra.txt" => "Testing testing testing",
|
|
|
|
// "subdir/extra2.txt" => "Testing testing testing",
|
|
|
|
// ),
|
|
|
|
//
|
|
|
|
// 'jsonInSecondLevel' => array(
|
|
|
|
// "extra.txt" => "Testing testing testing",
|
|
|
|
// "subdir/extra1.txt" => "Testing testing testing",
|
|
|
|
// "subdir/foo/composer.json" => '{ "name": "test/jsonInSecondLevel", "version": "1.0.0" }',
|
|
|
|
// "subdir/foo/extra1.txt" => "Testing testing testing",
|
|
|
|
// "subdir/extra2.txt" => "Testing testing testing",
|
|
|
|
// "subdir/extra3.txt" => "Testing testing testing",
|
|
|
|
// ),
|
|
|
|
//);
|
|
|
|
//
|
2014-06-10 14:02:44 +00:00
|
|
|
//foreach ($archivesToCreate as $archiveName => $fileDetails) {
|
2014-02-20 17:30:51 +00:00
|
|
|
// $zipFile = new ZipArchive();
|
|
|
|
// $zipFile->open("$archiveName.zip", ZIPARCHIVE::CREATE);
|
|
|
|
//
|
|
|
|
// foreach ($fileDetails as $filename => $fileContents) {
|
|
|
|
// $zipFile->addFromString($filename, $fileContents);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// $zipFile->close();
|
|
|
|
//}
|