2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2015-10-27 02:59:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Package;
|
|
|
|
|
|
|
|
use Composer\Package\Link;
|
|
|
|
use Composer\Package\RootAliasPackage;
|
2021-12-10 11:57:08 +00:00
|
|
|
use Composer\Package\RootPackage;
|
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;
|
2021-12-10 11:57:08 +00:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2015-10-27 02:59:05 +00:00
|
|
|
|
|
|
|
class RootAliasPackageTest extends TestCase
|
|
|
|
{
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testUpdateRequires(): void
|
2015-10-27 02:59:05 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$links = [new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_REQUIRE, 'self.version')];
|
2021-12-10 11:57:08 +00:00
|
|
|
|
|
|
|
$root = $this->getMockRootPackage();
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('setRequires')
|
|
|
|
->with($this->equalTo($links));
|
2015-10-27 02:59:05 +00:00
|
|
|
|
2021-12-10 11:57:08 +00:00
|
|
|
$alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEmpty($alias->getRequires());
|
2015-10-27 02:59:05 +00:00
|
|
|
$alias->setRequires($links);
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertNotEmpty($alias->getRequires());
|
2015-10-27 02:59:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testUpdateDevRequires(): void
|
2015-10-27 02:59:05 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$links = [new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_DEV_REQUIRE, 'self.version')];
|
2015-10-27 02:59:05 +00:00
|
|
|
|
2021-12-10 11:57:08 +00:00
|
|
|
$root = $this->getMockRootPackage();
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('setDevRequires')
|
|
|
|
->with($this->equalTo($links));
|
|
|
|
|
|
|
|
$alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEmpty($alias->getDevRequires());
|
2015-10-27 02:59:05 +00:00
|
|
|
$alias->setDevRequires($links);
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertNotEmpty($alias->getDevRequires());
|
2015-10-27 02:59:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testUpdateConflicts(): void
|
2015-10-27 02:59:05 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$links = [new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_CONFLICT, 'self.version')];
|
2021-12-10 11:57:08 +00:00
|
|
|
|
|
|
|
$root = $this->getMockRootPackage();
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('setConflicts')
|
|
|
|
->with($this->equalTo($links));
|
2015-10-27 02:59:05 +00:00
|
|
|
|
2021-12-10 11:57:08 +00:00
|
|
|
$alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEmpty($alias->getConflicts());
|
2015-10-27 02:59:05 +00:00
|
|
|
$alias->setConflicts($links);
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertNotEmpty($alias->getConflicts());
|
2015-10-27 02:59:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testUpdateProvides(): void
|
2015-10-27 02:59:05 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$links = [new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_PROVIDE, 'self.version')];
|
2015-10-27 02:59:05 +00:00
|
|
|
|
2021-12-10 11:57:08 +00:00
|
|
|
$root = $this->getMockRootPackage();
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('setProvides')
|
|
|
|
->with($this->equalTo($links));
|
|
|
|
|
|
|
|
$alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEmpty($alias->getProvides());
|
2015-10-27 02:59:05 +00:00
|
|
|
$alias->setProvides($links);
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertNotEmpty($alias->getProvides());
|
2015-10-27 02:59:05 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testUpdateReplaces(): void
|
2015-10-27 02:59:05 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$links = [new Link('a', 'b', new MatchAllConstraint(), Link::TYPE_REPLACE, 'self.version')];
|
2021-12-10 11:57:08 +00:00
|
|
|
|
|
|
|
$root = $this->getMockRootPackage();
|
|
|
|
$root->expects($this->once())
|
|
|
|
->method('setReplaces')
|
|
|
|
->with($this->equalTo($links));
|
2015-10-27 02:59:05 +00:00
|
|
|
|
2021-12-10 11:57:08 +00:00
|
|
|
$alias = new RootAliasPackage($root, '1.0', '1.0.0.0');
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertEmpty($alias->getReplaces());
|
2015-10-27 02:59:05 +00:00
|
|
|
$alias->setReplaces($links);
|
2024-05-29 21:12:06 +00:00
|
|
|
self::assertNotEmpty($alias->getReplaces());
|
2015-10-27 02:59:05 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 20:44:12 +00:00
|
|
|
/**
|
2021-12-10 11:57:08 +00:00
|
|
|
* @return RootPackage&MockObject
|
2021-11-01 20:44:12 +00:00
|
|
|
*/
|
2021-12-10 11:57:08 +00:00
|
|
|
protected function getMockRootPackage()
|
2015-10-27 02:59:05 +00:00
|
|
|
{
|
2021-12-10 11:57:08 +00:00
|
|
|
$root = $this->getMockBuilder(RootPackage::class)->disableOriginalConstructor()->getMock();
|
|
|
|
$root->expects($this->atLeastOnce())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn('something/something');
|
|
|
|
$root->expects($this->atLeastOnce())
|
|
|
|
->method('getRequires')
|
2022-08-17 12:20:07 +00:00
|
|
|
->willReturn([]);
|
2021-12-10 11:57:08 +00:00
|
|
|
$root->expects($this->atLeastOnce())
|
|
|
|
->method('getDevRequires')
|
2022-08-17 12:20:07 +00:00
|
|
|
->willReturn([]);
|
2021-12-10 11:57:08 +00:00
|
|
|
$root->expects($this->atLeastOnce())
|
|
|
|
->method('getConflicts')
|
2022-08-17 12:20:07 +00:00
|
|
|
->willReturn([]);
|
2021-12-10 11:57:08 +00:00
|
|
|
$root->expects($this->atLeastOnce())
|
|
|
|
->method('getProvides')
|
2022-08-17 12:20:07 +00:00
|
|
|
->willReturn([]);
|
2021-12-10 11:57:08 +00:00
|
|
|
$root->expects($this->atLeastOnce())
|
|
|
|
->method('getReplaces')
|
2022-08-17 12:20:07 +00:00
|
|
|
->willReturn([]);
|
2015-11-21 19:28:10 +00:00
|
|
|
|
2015-10-27 02:59:05 +00:00
|
|
|
return $root;
|
|
|
|
}
|
|
|
|
}
|