1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

Added --type option to search

This commit is contained in:
Pierre du Plessis 2016-06-21 16:38:52 +02:00
parent 5a3d60c0cf
commit 6a557e45b8
7 changed files with 110 additions and 11 deletions

View file

@ -13,6 +13,8 @@
namespace Composer\Test\Repository;
use Composer\IO\NullIO;
use Composer\Repository\ComposerRepository;
use Composer\Repository\RepositoryInterface;
use Composer\Test\Mock\FactoryMock;
use Composer\TestCase;
use Composer\Package\Loader\ArrayLoader;
@ -165,4 +167,45 @@ class ComposerRepositoryTest extends TestCase
$this->assertSame($packages['2'], $packages['2-root']->getAliasOf());
$this->assertSame($packages['2'], $packages['2-alias']->getAliasOf());
}
public function testSearchWithType()
{
$repoConfig = array(
'url' => 'http://example.org',
);
$result = array(
'results' => array(
array(
'name' => 'foo',
'description' => null
)
)
);
$rfs = $this->getMockBuilder('Composer\Util\RemoteFilesystem')
->disableOriginalConstructor()
->getMock();
$rfs->expects($this->at(0))
->method('getContents')
->with('example.org', 'http://example.org/packages.json', false)
->willReturn(json_encode(array('search' => '/search.json?q=%query%&type=%type%')));
$rfs->expects($this->at(1))
->method('getContents')
->with('example.org', 'http://example.org/search.json?q=foo&type=composer-plugin', false)
->willReturn(json_encode($result));
$repository = new ComposerRepository($repoConfig, new NullIO, FactoryMock::createConfig(), null, $rfs);
$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')
);
}
}