2012-10-22 21:44:56 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Repository;
|
|
|
|
|
|
|
|
use Composer\IO\NullIO;
|
2016-06-21 14:38:52 +00:00
|
|
|
use Composer\Repository\ComposerRepository;
|
|
|
|
use Composer\Repository\RepositoryInterface;
|
2012-10-22 21:44:56 +00:00
|
|
|
use Composer\Test\Mock\FactoryMock;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2013-03-21 08:06:11 +00:00
|
|
|
use Composer\Package\Loader\ArrayLoader;
|
2018-10-31 11:44:54 +00:00
|
|
|
use Composer\Package\Version\VersionParser;
|
2012-10-22 21:44:56 +00:00
|
|
|
|
|
|
|
class ComposerRepositoryTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider loadDataProvider
|
|
|
|
*/
|
|
|
|
public function testLoadData(array $expected, array $repoPackages)
|
|
|
|
{
|
|
|
|
$repoConfig = array(
|
2012-11-05 14:39:43 +00:00
|
|
|
'url' => 'http://example.org',
|
2012-10-22 21:44:56 +00:00
|
|
|
);
|
|
|
|
|
2018-04-12 08:24:56 +00:00
|
|
|
$repository = $this->getMockBuilder('Composer\Repository\ComposerRepository')
|
2018-12-04 10:20:35 +00:00
|
|
|
->setMethods(array('loadRootServerFile', 'createPackages'))
|
2018-04-12 08:24:56 +00:00
|
|
|
->setConstructorArgs(array(
|
2012-10-22 21:44:56 +00:00
|
|
|
$repoConfig,
|
|
|
|
new NullIO,
|
|
|
|
FactoryMock::createConfig(),
|
2018-11-12 14:34:54 +00:00
|
|
|
$this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(),
|
|
|
|
$this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
|
2018-04-12 08:24:56 +00:00
|
|
|
))
|
|
|
|
->getMock();
|
2012-10-22 21:44:56 +00:00
|
|
|
|
|
|
|
$repository
|
2013-03-10 12:32:59 +00:00
|
|
|
->expects($this->exactly(2))
|
2012-10-22 21:44:56 +00:00
|
|
|
->method('loadRootServerFile')
|
|
|
|
->will($this->returnValue($repoPackages));
|
|
|
|
|
2018-12-04 10:20:35 +00:00
|
|
|
$stubs = array();
|
2012-10-22 21:44:56 +00:00
|
|
|
foreach ($expected as $at => $arg) {
|
2018-12-04 10:20:35 +00:00
|
|
|
$stubs[] = $this->getPackage('stub/stub', '1.0.0');
|
2012-10-22 21:44:56 +00:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:20:35 +00:00
|
|
|
$repository
|
|
|
|
->expects($this->at(2))
|
|
|
|
->method('createPackages')
|
|
|
|
->with($this->identicalTo($expected), $this->equalTo('Composer\Package\CompletePackage'))
|
|
|
|
->will($this->returnValue($stubs));
|
|
|
|
|
2012-10-22 21:44:56 +00:00
|
|
|
// Triggers initialization
|
|
|
|
$packages = $repository->getPackages();
|
|
|
|
|
|
|
|
// Final sanity check, ensure the correct number of packages were added.
|
|
|
|
$this->assertCount(count($expected), $packages);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function loadDataProvider()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
// Old repository format
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
array('name' => 'foo/bar', 'version' => '1.0.0'),
|
|
|
|
),
|
|
|
|
array('foo/bar' => array(
|
|
|
|
'name' => 'foo/bar',
|
|
|
|
'versions' => array(
|
2015-09-28 09:51:14 +00:00
|
|
|
'1.0.0' => array('name' => 'foo/bar', 'version' => '1.0.0'),
|
|
|
|
),
|
2012-10-22 21:44:56 +00:00
|
|
|
)),
|
|
|
|
),
|
|
|
|
// New repository format
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
array('name' => 'bar/foo', 'version' => '3.14'),
|
|
|
|
array('name' => 'bar/foo', 'version' => '3.145'),
|
|
|
|
),
|
|
|
|
array('packages' => array(
|
|
|
|
'bar/foo' => array(
|
2017-03-08 14:07:29 +00:00
|
|
|
'3.14' => array('name' => 'bar/foo', 'version' => '3.14'),
|
2012-10-22 21:44:56 +00:00
|
|
|
'3.145' => array('name' => 'bar/foo', 'version' => '3.145'),
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2013-03-21 08:06:11 +00:00
|
|
|
|
2015-06-18 13:40:27 +00:00
|
|
|
public function testWhatProvides()
|
2015-05-05 17:44:07 +00:00
|
|
|
{
|
2013-03-21 08:06:11 +00:00
|
|
|
$repo = $this->getMockBuilder('Composer\Repository\ComposerRepository')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->setMethods(array('fetchFile'))
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$cache = $this->getMockBuilder('Composer\Cache')->disableOriginalConstructor()->getMock();
|
|
|
|
$cache->expects($this->any())
|
|
|
|
->method('sha256')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
|
|
|
$properties = array(
|
|
|
|
'cache' => $cache,
|
|
|
|
'loader' => new ArrayLoader(),
|
2016-02-15 20:51:21 +00:00
|
|
|
'providerListing' => array('a' => array('sha256' => 'xxx')),
|
|
|
|
'providersUrl' => 'https://dummy.test.link/to/%package%/file',
|
2013-03-21 08:06:11 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($properties as $property => $value) {
|
|
|
|
$ref = new \ReflectionProperty($repo, $property);
|
|
|
|
$ref->setAccessible(true);
|
|
|
|
$ref->setValue($repo, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
$repo->expects($this->any())
|
|
|
|
->method('fetchFile')
|
|
|
|
->will($this->returnValue(array(
|
|
|
|
'packages' => array(
|
2015-06-18 13:40:27 +00:00
|
|
|
array(array(
|
|
|
|
'uid' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'version' => 'dev-master',
|
|
|
|
'extra' => array('branch-alias' => array('dev-master' => '1.0.x-dev')),
|
|
|
|
)),
|
|
|
|
array(array(
|
|
|
|
'uid' => 2,
|
|
|
|
'name' => 'a',
|
|
|
|
'version' => 'dev-develop',
|
|
|
|
'extra' => array('branch-alias' => array('dev-develop' => '1.1.x-dev')),
|
|
|
|
)),
|
|
|
|
array(array(
|
|
|
|
'uid' => 3,
|
|
|
|
'name' => 'a',
|
|
|
|
'version' => '0.6',
|
|
|
|
)),
|
2015-09-28 09:51:14 +00:00
|
|
|
),
|
2013-03-21 08:06:11 +00:00
|
|
|
)));
|
|
|
|
|
|
|
|
$versionParser = new VersionParser();
|
2015-06-18 13:40:27 +00:00
|
|
|
$repo->setRootAliases(array(
|
|
|
|
'a' => array(
|
|
|
|
$versionParser->normalize('0.6') => array('alias' => 'dev-feature', 'alias_normalized' => $versionParser->normalize('dev-feature')),
|
|
|
|
$versionParser->normalize('1.1.x-dev') => array('alias' => '1.0', 'alias_normalized' => $versionParser->normalize('1.0')),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
|
2018-09-11 11:33:29 +00:00
|
|
|
$packages = $repo->whatProvides('a', false, array($this, 'isPackageAcceptableReturnTrue'));
|
2013-03-21 08:06:11 +00:00
|
|
|
|
2015-06-18 13:40:27 +00:00
|
|
|
$this->assertCount(7, $packages);
|
|
|
|
$this->assertEquals(array('1', '1-alias', '2', '2-alias', '2-root', '3', '3-root'), array_keys($packages));
|
|
|
|
$this->assertInstanceOf('Composer\Package\AliasPackage', $packages['2-root']);
|
|
|
|
$this->assertSame($packages['2'], $packages['2-root']->getAliasOf());
|
|
|
|
$this->assertSame($packages['2'], $packages['2-alias']->getAliasOf());
|
2013-03-21 08:06:11 +00:00
|
|
|
}
|
2016-06-21 14:38:52 +00:00
|
|
|
|
2018-09-11 11:33:29 +00:00
|
|
|
public function isPackageAcceptableReturnTrue()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-21 14:38:52 +00:00
|
|
|
public function testSearchWithType()
|
|
|
|
{
|
|
|
|
$repoConfig = array(
|
|
|
|
'url' => 'http://example.org',
|
|
|
|
);
|
|
|
|
|
|
|
|
$result = array(
|
|
|
|
'results' => array(
|
|
|
|
array(
|
|
|
|
'name' => 'foo',
|
2017-03-08 14:07:29 +00:00
|
|
|
'description' => null,
|
|
|
|
),
|
|
|
|
),
|
2016-06-21 14:38:52 +00:00
|
|
|
);
|
|
|
|
|
2018-10-31 11:44:54 +00:00
|
|
|
$httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader')
|
2016-06-21 14:38:52 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2018-10-31 11:44:54 +00:00
|
|
|
$eventDispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$httpDownloader->expects($this->at(0))
|
|
|
|
->method('get')
|
|
|
|
->with($url = 'http://example.org/packages.json')
|
|
|
|
->willReturn(new \Composer\Util\Http\Response(array('url' => $url), 200, array(), json_encode(array('search' => '/search.json?q=%query%&type=%type%'))));
|
2016-06-21 14:38:52 +00:00
|
|
|
|
2018-10-31 11:44:54 +00:00
|
|
|
$httpDownloader->expects($this->at(1))
|
|
|
|
->method('get')
|
|
|
|
->with($url = 'http://example.org/search.json?q=foo&type=composer-plugin')
|
|
|
|
->willReturn(new \Composer\Util\Http\Response(array('url' => $url), 200, array(), json_encode($result)));
|
2016-06-21 14:38:52 +00:00
|
|
|
|
2018-10-31 11:44:54 +00:00
|
|
|
$httpDownloader->expects($this->at(2))
|
|
|
|
->method('get')
|
|
|
|
->with($url = 'http://example.org/search.json?q=foo&type=library')
|
|
|
|
->willReturn(new \Composer\Util\Http\Response(array('url' => $url), 200, array(), json_encode(array())));
|
2016-06-21 14:38:52 +00:00
|
|
|
|
2018-11-12 14:34:54 +00:00
|
|
|
$repository = new ComposerRepository($repoConfig, new NullIO, FactoryMock::createConfig(), $httpDownloader, $eventDispatcher);
|
2016-06-21 14:38:52 +00:00
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
array(array('name' => 'foo', 'description' => null)),
|
|
|
|
$repository->search('foo', RepositoryInterface::SEARCH_FULLTEXT, 'composer-plugin')
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEmpty(
|
|
|
|
$repository->search('foo', RepositoryInterface::SEARCH_FULLTEXT, 'library')
|
|
|
|
);
|
|
|
|
}
|
2012-10-22 21:44:56 +00:00
|
|
|
}
|