2012-06-09 05:48:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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\Pear;
|
2012-06-09 05:48:52 +00:00
|
|
|
|
2016-10-05 08:45:22 +00:00
|
|
|
use Composer\Repository\Pear\ChannelInfo;
|
|
|
|
use Composer\Repository\Pear\DependencyConstraint;
|
|
|
|
use Composer\Repository\Pear\DependencyInfo;
|
|
|
|
use Composer\Repository\Pear\PackageInfo;
|
|
|
|
use Composer\Repository\Pear\ReleaseInfo;
|
2013-09-25 08:14:42 +00:00
|
|
|
use Composer\TestCase;
|
2015-09-24 14:32:36 +00:00
|
|
|
use Composer\Semver\VersionParser;
|
|
|
|
use Composer\Semver\Constraint\Constraint;
|
2012-06-09 05:48:52 +00:00
|
|
|
use Composer\Package\Link;
|
2012-08-23 13:52:40 +00:00
|
|
|
use Composer\Package\CompletePackage;
|
2012-06-09 05:48:52 +00:00
|
|
|
use Composer\Test\Mock\RemoteFilesystemMock;
|
|
|
|
|
|
|
|
class ChannelReaderTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testShouldBuildPackagesFromPearSchema()
|
|
|
|
{
|
|
|
|
$rfs = new RemoteFilesystemMock(array(
|
|
|
|
'http://pear.net/channel.xml' => file_get_contents(__DIR__ . '/Fixtures/channel.1.1.xml'),
|
|
|
|
'http://test.loc/rest11/c/categories.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.1/categories.xml'),
|
|
|
|
'http://test.loc/rest11/c/Default/packagesinfo.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.1/packagesinfo.xml'),
|
|
|
|
));
|
|
|
|
|
|
|
|
$reader = new \Composer\Repository\Pear\ChannelReader($rfs);
|
|
|
|
|
|
|
|
$channelInfo = $reader->read('http://pear.net/');
|
|
|
|
$packages = $channelInfo->getPackages();
|
|
|
|
|
|
|
|
$this->assertCount(3, $packages);
|
|
|
|
$this->assertEquals('HTTP_Client', $packages[0]->getPackageName());
|
|
|
|
$this->assertEquals('HTTP_Request', $packages[1]->getPackageName());
|
|
|
|
$this->assertEquals('MDB2', $packages[2]->getPackageName());
|
|
|
|
|
|
|
|
$mdb2releases = $packages[2]->getReleases();
|
|
|
|
$this->assertEquals(9, count($mdb2releases['2.4.0']->getDependencyInfo()->getOptionals()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testShouldSelectCorrectReader()
|
|
|
|
{
|
|
|
|
$rfs = new RemoteFilesystemMock(array(
|
|
|
|
'http://pear.1.0.net/channel.xml' => file_get_contents(__DIR__ . '/Fixtures/channel.1.0.xml'),
|
|
|
|
'http://test.loc/rest10/p/packages.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.0/packages.xml'),
|
|
|
|
'http://test.loc/rest10/p/http_client/info.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.0/http_client_info.xml'),
|
|
|
|
'http://test.loc/rest10/p/http_request/info.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.0/http_request_info.xml'),
|
|
|
|
'http://pear.1.1.net/channel.xml' => file_get_contents(__DIR__ . '/Fixtures/channel.1.1.xml'),
|
|
|
|
'http://test.loc/rest11/c/categories.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.1/categories.xml'),
|
|
|
|
'http://test.loc/rest11/c/Default/packagesinfo.xml' => file_get_contents(__DIR__ . '/Fixtures/Rest1.1/packagesinfo.xml'),
|
|
|
|
));
|
|
|
|
|
|
|
|
$reader = new \Composer\Repository\Pear\ChannelReader($rfs);
|
|
|
|
|
|
|
|
$reader->read('http://pear.1.0.net/');
|
|
|
|
$reader->read('http://pear.1.1.net/');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testShouldCreatePackages()
|
|
|
|
{
|
2012-06-24 15:41:54 +00:00
|
|
|
$reader = $this->getMockBuilder('\Composer\Repository\PearRepository')
|
2012-06-09 05:48:52 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$ref = new \ReflectionMethod($reader, 'buildComposerPackages');
|
|
|
|
$ref->setAccessible(true);
|
|
|
|
|
2012-06-24 15:41:54 +00:00
|
|
|
$channelInfo = new ChannelInfo(
|
2012-06-09 05:48:52 +00:00
|
|
|
'test.loc',
|
2012-06-24 15:41:54 +00:00
|
|
|
'test',
|
2012-06-09 05:48:52 +00:00
|
|
|
array(
|
2012-06-24 15:41:54 +00:00
|
|
|
new PackageInfo(
|
|
|
|
'test.loc',
|
|
|
|
'sample',
|
|
|
|
'license',
|
|
|
|
'shortDescription',
|
|
|
|
'description',
|
|
|
|
array(
|
|
|
|
'1.0.0.1' => new ReleaseInfo(
|
|
|
|
'stable',
|
|
|
|
new DependencyInfo(
|
|
|
|
array(
|
|
|
|
new DependencyConstraint(
|
|
|
|
'required',
|
|
|
|
'> 5.2.0.0',
|
|
|
|
'php',
|
|
|
|
''
|
|
|
|
),
|
|
|
|
new DependencyConstraint(
|
|
|
|
'conflicts',
|
|
|
|
'== 2.5.6.0',
|
|
|
|
'pear.php.net',
|
|
|
|
'broken'
|
|
|
|
),
|
2012-06-09 05:48:52 +00:00
|
|
|
),
|
2012-06-24 15:41:54 +00:00
|
|
|
array(
|
|
|
|
'*' => array(
|
|
|
|
new DependencyConstraint(
|
|
|
|
'optional',
|
|
|
|
'*',
|
|
|
|
'ext',
|
|
|
|
'xml'
|
|
|
|
),
|
2015-09-28 09:51:14 +00:00
|
|
|
),
|
2012-06-24 15:41:54 +00:00
|
|
|
)
|
2012-06-09 05:48:52 +00:00
|
|
|
)
|
2015-09-28 09:51:14 +00:00
|
|
|
),
|
2012-06-09 05:48:52 +00:00
|
|
|
)
|
2015-09-28 09:51:14 +00:00
|
|
|
),
|
2012-06-09 05:48:52 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2012-06-24 15:41:54 +00:00
|
|
|
$packages = $ref->invoke($reader, $channelInfo, new VersionParser());
|
2012-06-09 05:48:52 +00:00
|
|
|
|
2015-09-28 09:51:14 +00:00
|
|
|
$expectedPackage = new CompletePackage('pear-test.loc/sample', '1.0.0.1', '1.0.0.1');
|
2012-06-27 05:27:01 +00:00
|
|
|
$expectedPackage->setType('pear-library');
|
|
|
|
$expectedPackage->setDistType('file');
|
2012-06-09 05:48:52 +00:00
|
|
|
$expectedPackage->setDescription('description');
|
2014-12-16 17:45:36 +00:00
|
|
|
$expectedPackage->setLicense(array('license'));
|
2012-06-09 05:48:52 +00:00
|
|
|
$expectedPackage->setDistUrl("http://test.loc/get/sample-1.0.0.1.tgz");
|
|
|
|
$expectedPackage->setAutoload(array('classmap' => array('')));
|
|
|
|
$expectedPackage->setIncludePaths(array('/'));
|
|
|
|
$expectedPackage->setRequires(array(
|
|
|
|
new Link('pear-test.loc/sample', 'php', $this->createConstraint('>', '5.2.0.0'), 'required', '> 5.2.0.0'),
|
|
|
|
));
|
|
|
|
$expectedPackage->setConflicts(array(
|
|
|
|
new Link('pear-test.loc/sample', 'pear-pear.php.net/broken', $this->createConstraint('==', '2.5.6.0'), 'conflicts', '== 2.5.6.0'),
|
|
|
|
));
|
|
|
|
$expectedPackage->setSuggests(array(
|
|
|
|
'*-ext-xml' => '*',
|
|
|
|
));
|
|
|
|
$expectedPackage->setReplaces(array(
|
2015-09-24 14:32:36 +00:00
|
|
|
new Link('pear-test.loc/sample', 'pear-test/sample', new Constraint('==', '1.0.0.1'), 'replaces', '== 1.0.0.1'),
|
2012-06-09 05:48:52 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertCount(1, $packages);
|
|
|
|
$this->assertEquals($expectedPackage, $packages[0], 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createConstraint($operator, $version)
|
|
|
|
{
|
2015-09-24 14:32:36 +00:00
|
|
|
$constraint = new Constraint($operator, $version);
|
2012-06-09 05:48:52 +00:00
|
|
|
$constraint->setPrettyString($operator.' '.$version);
|
|
|
|
|
|
|
|
return $constraint;
|
|
|
|
}
|
|
|
|
}
|