2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2011-04-05 15:37:19 +00:00
|
|
|
|
|
|
|
/*
|
2011-04-16 12:42:35 +00:00
|
|
|
* This file is part of Composer.
|
2011-04-05 15:37:19 +00:00
|
|
|
*
|
2011-04-16 12:42:35 +00:00
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
2011-04-05 15:37:19 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-04-17 21:45:37 +00:00
|
|
|
namespace Composer\Test\Repository;
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2011-04-17 21:45:37 +00:00
|
|
|
use Composer\Repository\ArrayRepository;
|
2016-06-21 14:38:52 +00:00
|
|
|
use Composer\Repository\RepositoryInterface;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2011-11-20 14:06:12 +00:00
|
|
|
class ArrayRepositoryTest extends TestCase
|
2011-04-05 15:37:19 +00:00
|
|
|
{
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testAddPackage(): void
|
2011-04-05 15:37:19 +00:00
|
|
|
{
|
|
|
|
$repo = new ArrayRepository;
|
2022-11-24 13:39:08 +00:00
|
|
|
$repo->addPackage(self::getPackage('foo', '1'));
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertCount(1, $repo);
|
2011-04-05 15:37:19 +00:00
|
|
|
}
|
2011-09-25 17:57:58 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testRemovePackage(): void
|
2011-09-25 17:57:58 +00:00
|
|
|
{
|
2022-11-24 13:39:08 +00:00
|
|
|
$package = self::getPackage('bar', '2');
|
2011-09-25 17:57:58 +00:00
|
|
|
|
|
|
|
$repo = new ArrayRepository;
|
2022-11-24 13:39:08 +00:00
|
|
|
$repo->addPackage(self::getPackage('foo', '1'));
|
2011-09-25 17:57:58 +00:00
|
|
|
$repo->addPackage($package);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertCount(2, $repo);
|
2011-09-25 17:57:58 +00:00
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$repo->removePackage(self::getPackage('foo', '1'));
|
2011-09-25 17:57:58 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertCount(1, $repo);
|
|
|
|
self::assertEquals([$package], $repo->getPackages());
|
2011-09-25 17:57:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testHasPackage(): void
|
2011-09-25 17:57:58 +00:00
|
|
|
{
|
|
|
|
$repo = new ArrayRepository;
|
2022-11-24 13:39:08 +00:00
|
|
|
$repo->addPackage(self::getPackage('foo', '1'));
|
|
|
|
$repo->addPackage(self::getPackage('bar', '2'));
|
2011-09-25 17:57:58 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertTrue($repo->hasPackage(self::getPackage('foo', '1')));
|
|
|
|
self::assertFalse($repo->hasPackage(self::getPackage('bar', '1')));
|
2011-09-25 17:57:58 +00:00
|
|
|
}
|
2012-01-16 21:29:22 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testFindPackages(): void
|
2012-01-16 21:29:22 +00:00
|
|
|
{
|
|
|
|
$repo = new ArrayRepository();
|
2022-11-24 13:39:08 +00:00
|
|
|
$repo->addPackage(self::getPackage('foo', '1'));
|
|
|
|
$repo->addPackage(self::getPackage('bar', '2'));
|
|
|
|
$repo->addPackage(self::getPackage('bar', '3'));
|
2012-01-16 21:29:22 +00:00
|
|
|
|
2012-02-21 13:02:08 +00:00
|
|
|
$foo = $repo->findPackages('foo');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertCount(1, $foo);
|
|
|
|
self::assertEquals('foo', $foo[0]->getName());
|
2012-01-16 21:29:22 +00:00
|
|
|
|
2012-02-21 13:02:08 +00:00
|
|
|
$bar = $repo->findPackages('bar');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertCount(2, $bar);
|
|
|
|
self::assertEquals('bar', $bar[0]->getName());
|
2012-01-16 21:29:22 +00:00
|
|
|
}
|
2013-04-01 06:10:15 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testAutomaticallyAddAliasedPackageButNotRemove(): void
|
2013-04-01 06:10:15 +00:00
|
|
|
{
|
|
|
|
$repo = new ArrayRepository();
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$package = self::getPackage('foo', '1');
|
|
|
|
$alias = self::getAliasPackage($package, '2');
|
2013-04-01 06:10:15 +00:00
|
|
|
|
|
|
|
$repo->addPackage($alias);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertCount(2, $repo);
|
|
|
|
self::assertTrue($repo->hasPackage(self::getPackage('foo', '1')));
|
|
|
|
self::assertTrue($repo->hasPackage(self::getPackage('foo', '2')));
|
2018-04-12 07:51:01 +00:00
|
|
|
|
|
|
|
$repo->removePackage($alias);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertCount(1, $repo);
|
2013-04-01 06:10:15 +00:00
|
|
|
}
|
2016-06-21 14:38:52 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSearch(): void
|
2016-06-21 14:38:52 +00:00
|
|
|
{
|
|
|
|
$repo = new ArrayRepository();
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$repo->addPackage(self::getPackage('foo', '1'));
|
|
|
|
$repo->addPackage(self::getPackage('bar', '1'));
|
2016-06-21 14:38:52 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(
|
2022-08-17 12:20:07 +00:00
|
|
|
[['name' => 'foo', 'description' => null]],
|
2016-06-21 14:38:52 +00:00
|
|
|
$repo->search('foo', RepositoryInterface::SEARCH_FULLTEXT)
|
|
|
|
);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(
|
2022-08-17 12:20:07 +00:00
|
|
|
[['name' => 'bar', 'description' => null]],
|
2016-06-21 14:38:52 +00:00
|
|
|
$repo->search('bar')
|
|
|
|
);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEmpty(
|
2016-06-21 14:38:52 +00:00
|
|
|
$repo->search('foobar')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSearchWithPackageType(): void
|
2016-06-21 14:38:52 +00:00
|
|
|
{
|
|
|
|
$repo = new ArrayRepository();
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$repo->addPackage(self::getPackage('foo', '1', 'Composer\Package\CompletePackage'));
|
|
|
|
$repo->addPackage(self::getPackage('bar', '1', 'Composer\Package\CompletePackage'));
|
2016-06-21 14:38:52 +00:00
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$package = self::getPackage('foobar', '1', 'Composer\Package\CompletePackage');
|
2016-06-21 14:38:52 +00:00
|
|
|
$package->setType('composer-plugin');
|
|
|
|
$repo->addPackage($package);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(
|
2022-08-17 12:20:07 +00:00
|
|
|
[['name' => 'foo', 'description' => null]],
|
2016-06-21 14:38:52 +00:00
|
|
|
$repo->search('foo', RepositoryInterface::SEARCH_FULLTEXT, 'library')
|
|
|
|
);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEmpty($repo->search('bar', RepositoryInterface::SEARCH_FULLTEXT, 'package'));
|
2016-06-21 14:38:52 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(
|
2022-08-17 12:20:07 +00:00
|
|
|
[['name' => 'foobar', 'description' => null]],
|
2016-06-21 14:38:52 +00:00
|
|
|
$repo->search('foo', 0, 'composer-plugin')
|
|
|
|
);
|
|
|
|
}
|
2021-11-08 09:27:45 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testSearchWithAbandonedPackages(): void
|
2021-11-08 09:27:45 +00:00
|
|
|
{
|
|
|
|
$repo = new ArrayRepository();
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$package1 = self::getPackage('foo1', '1');
|
2021-11-08 09:27:45 +00:00
|
|
|
$package1->setAbandoned(true);
|
|
|
|
$repo->addPackage($package1);
|
2022-11-24 13:39:08 +00:00
|
|
|
$package2 = self::getPackage('foo2', '1');
|
2021-11-08 09:27:45 +00:00
|
|
|
$package2->setAbandoned('bar');
|
|
|
|
$repo->addPackage($package2);
|
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertSame(
|
2022-08-17 12:20:07 +00:00
|
|
|
[
|
|
|
|
['name' => 'foo1', 'description' => null, 'abandoned' => true],
|
|
|
|
['name' => 'foo2', 'description' => null, 'abandoned' => 'bar'],
|
|
|
|
],
|
2021-11-08 09:27:45 +00:00
|
|
|
$repo->search('foo')
|
|
|
|
);
|
|
|
|
}
|
2011-04-05 15:37:19 +00:00
|
|
|
}
|