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')); }
public function search($query, $mode = 0) { // if the query exactly matches one of our vendors, return the whole list! if (isset($this->vendors[$query])) { // make sure the vendor that shows is the vendor they want $this->defaultVendor = $query; $out = []; foreach ($this->getProviderNames() as $provider) { $out[] = ['name' => $provider]; } return $out; } // try running the search handler - see if we get anything $results = Util::callFilter($this->repoConfig->get('search-handler'), $query); // if the these are the same, default to the normal provider name search if ($results === $query) { return parent::search($query, $mode); } return $results; }