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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\DependencyResolver;
|
|
|
|
|
|
|
|
use Composer\DependencyResolver\Request;
|
2011-04-17 21:45:37 +00:00
|
|
|
use Composer\Repository\ArrayRepository;
|
2020-06-05 14:41:37 +00:00
|
|
|
use Composer\Semver\Constraint\MatchAllConstraint;
|
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 RequestTest extends TestCase
|
2011-04-05 15:37:19 +00:00
|
|
|
{
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testRequestInstall(): void
|
2011-04-05 15:37:19 +00:00
|
|
|
{
|
|
|
|
$repo = new ArrayRepository;
|
2022-11-24 13:39:08 +00:00
|
|
|
$foo = self::getPackage('foo', '1');
|
|
|
|
$bar = self::getPackage('bar', '1');
|
|
|
|
$foobar = self::getPackage('foobar', '1');
|
2011-04-05 15:37:19 +00:00
|
|
|
|
|
|
|
$repo->addPackage($foo);
|
|
|
|
$repo->addPackage($bar);
|
|
|
|
$repo->addPackage($foobar);
|
|
|
|
|
2015-04-30 15:24:24 +00:00
|
|
|
$request = new Request();
|
2020-01-19 22:28:00 +00:00
|
|
|
$request->requireName('foo');
|
2011-04-05 15:37:19 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals(
|
2022-08-17 12:20:07 +00:00
|
|
|
[
|
2020-06-05 14:41:37 +00:00
|
|
|
'foo' => new MatchAllConstraint(),
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
2020-01-19 22:11:36 +00:00
|
|
|
$request->getRequires()
|
2018-07-24 12:32:52 +00:00
|
|
|
);
|
2011-04-05 15:37:19 +00:00
|
|
|
}
|
2012-02-19 15:59:04 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testRequestInstallSamePackageFromDifferentRepositories(): void
|
2012-03-06 09:11:45 +00:00
|
|
|
{
|
|
|
|
$repo1 = new ArrayRepository;
|
|
|
|
$repo2 = new ArrayRepository;
|
|
|
|
|
2022-11-24 13:39:08 +00:00
|
|
|
$foo1 = self::getPackage('foo', '1');
|
|
|
|
$foo2 = self::getPackage('foo', '1');
|
2012-03-06 09:11:45 +00:00
|
|
|
|
|
|
|
$repo1->addPackage($foo1);
|
|
|
|
$repo2->addPackage($foo2);
|
|
|
|
|
2015-04-30 15:24:24 +00:00
|
|
|
$request = new Request();
|
2022-11-24 13:39:08 +00:00
|
|
|
$request->requireName('foo', $constraint = self::getVersionConstraint('=', '1'));
|
2012-03-06 09:11:45 +00:00
|
|
|
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEquals(
|
2022-08-17 12:20:07 +00:00
|
|
|
[
|
2020-01-19 22:11:36 +00:00
|
|
|
'foo' => $constraint,
|
2022-08-17 12:20:07 +00:00
|
|
|
],
|
2020-01-19 22:11:36 +00:00
|
|
|
$request->getRequires()
|
2012-03-06 09:11:45 +00:00
|
|
|
);
|
|
|
|
}
|
2011-04-05 15:37:19 +00:00
|
|
|
}
|