Add back abandoned key in repository search results (#10259)
parent
d7154c2a72
commit
5b47fa1896
|
@ -166,6 +166,10 @@ class ArrayRepository implements RepositoryInterface
|
||||||
'name' => $package->getPrettyName(),
|
'name' => $package->getPrettyName(),
|
||||||
'description' => $package instanceof CompletePackageInterface ? $package->getDescription() : null,
|
'description' => $package instanceof CompletePackageInterface ? $package->getDescription() : null,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($package instanceof CompletePackageInterface && $package->isAbandoned()) {
|
||||||
|
$matches[$name]['abandoned'] = $package->getReplacementPackage() ?: true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -478,9 +478,11 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
|
||||||
$results = array();
|
$results = array();
|
||||||
foreach ($search['results'] as $result) {
|
foreach ($search['results'] as $result) {
|
||||||
// do not show virtual packages in results as they are not directly useful from a composer perspective
|
// do not show virtual packages in results as they are not directly useful from a composer perspective
|
||||||
if (empty($result['virtual'])) {
|
if (!empty($result['virtual'])) {
|
||||||
$results[] = array('name' => $result['name'], 'description' => $result['description']);
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$results[] = $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
|
|
|
@ -90,7 +90,7 @@ interface RepositoryInterface extends \Countable
|
||||||
* @param string $type The type of package to search for. Defaults to all types of packages
|
* @param string $type The type of package to search for. Defaults to all types of packages
|
||||||
*
|
*
|
||||||
* @return array[] an array of array('name' => '...', 'description' => '...'|null)
|
* @return array[] an array of array('name' => '...', 'description' => '...'|null)
|
||||||
* @phpstan-return list<array{name: string, description: ?string}>
|
* @phpstan-return list<array{name: string, description: ?string, abandoned?: string|true}>
|
||||||
*/
|
*/
|
||||||
public function search($query, $mode = 0, $type = null);
|
public function search($query, $mode = 0, $type = null);
|
||||||
|
|
||||||
|
|
|
@ -131,4 +131,24 @@ class ArrayRepositoryTest extends TestCase
|
||||||
$repo->search('foo', 0, 'composer-plugin')
|
$repo->search('foo', 0, 'composer-plugin')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSearchWithAbandonedPackages()
|
||||||
|
{
|
||||||
|
$repo = new ArrayRepository();
|
||||||
|
|
||||||
|
$package1 = $this->getPackage('foo1', '1');
|
||||||
|
$package1->setAbandoned(true);
|
||||||
|
$repo->addPackage($package1);
|
||||||
|
$package2 = $this->getPackage('foo2', '1');
|
||||||
|
$package2->setAbandoned('bar');
|
||||||
|
$repo->addPackage($package2);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
array(
|
||||||
|
array('name' => 'foo1', 'description' => null, 'abandoned' => true),
|
||||||
|
array('name' => 'foo2', 'description' => null, 'abandoned' => 'bar'),
|
||||||
|
),
|
||||||
|
$repo->search('foo')
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,6 +216,55 @@ class ComposerRepositoryTest extends TestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSearchWithAbandonedPackages()
|
||||||
|
{
|
||||||
|
$repoConfig = array(
|
||||||
|
'url' => 'http://example.org',
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
'results' => array(
|
||||||
|
array(
|
||||||
|
'name' => 'foo1',
|
||||||
|
'description' => null,
|
||||||
|
'abandoned' => true,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'foo2',
|
||||||
|
'description' => null,
|
||||||
|
'abandoned' => 'bar',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$eventDispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$httpDownloader->expects($this->at(1))
|
||||||
|
->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%'))));
|
||||||
|
|
||||||
|
$httpDownloader->expects($this->at(2))
|
||||||
|
->method('get')
|
||||||
|
->with($url = 'http://example.org/search.json?q=foo')
|
||||||
|
->willReturn(new \Composer\Util\Http\Response(array('url' => $url), 200, array(), json_encode($result)));
|
||||||
|
|
||||||
|
$repository = new ComposerRepository($repoConfig, new NullIO, FactoryMock::createConfig(), $httpDownloader, $eventDispatcher);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
array(
|
||||||
|
array('name' => 'foo1', 'description' => null, 'abandoned' => true),
|
||||||
|
array('name' => 'foo2', 'description' => null, 'abandoned' => 'bar'),
|
||||||
|
),
|
||||||
|
$repository->search('foo')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideCanonicalizeUrlTestCases
|
* @dataProvider provideCanonicalizeUrlTestCases
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue