1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-10 09:02:59 +00:00

Add setters used by composer-merge-plugin to RootPackageInterface

Extend RootPackageInterface with setter functions used by
composer-merge-plugin and implement them for RootAliasPackage. This will
allow composer-merge-plugin and similar code that manipulates the root
package at runtime to ignore the difference between a RootPackage and
a RootAliasPackage.
This commit is contained in:
Bryan Davis 2015-10-26 20:59:05 -06:00 committed by Bryan Davis
parent 2eb0af264b
commit 06c44ce998
3 changed files with 203 additions and 0 deletions

View file

@ -0,0 +1,94 @@
<?php
/*
* 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;
use Composer\TestCase;
use Prophecy\Argument;
class RootAliasPackageTest extends TestCase
{
public function testUpdateRequires()
{
$root = $this->getMockRootPackageInterface();
$root->setRequires(Argument::type('array'))->shouldBeCalled();
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getRequires());
$links = array(new Link('a', 'b', null, 'foo', 'self.version'));
$alias->setRequires($links);
$this->assertNotEmpty($alias->getRequires());
}
public function testUpdateDevRequires()
{
$root = $this->getMockRootPackageInterface();
$root->setDevRequires(Argument::type('array'))->shouldBeCalled();
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getDevRequires());
$links = array(new Link('a', 'b', null, 'foo', 'self.version'));
$alias->setDevRequires($links);
$this->assertNotEmpty($alias->getDevRequires());
}
public function testUpdateConflicts()
{
$root = $this->getMockRootPackageInterface();
$root->setConflicts(Argument::type('array'))->shouldBeCalled();
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getConflicts());
$links = array(new Link('a', 'b', null, 'foo', 'self.version'));
$alias->setConflicts($links);
$this->assertNotEmpty($alias->getConflicts());
}
public function testUpdateProvides()
{
$root = $this->getMockRootPackageInterface();
$root->setProvides(Argument::type('array'))->shouldBeCalled();
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getProvides());
$links = array(new Link('a', 'b', null, 'foo', 'self.version'));
$alias->setProvides($links);
$this->assertNotEmpty($alias->getProvides());
}
public function testUpdateReplaces()
{
$root = $this->getMockRootPackageInterface();
$root->setReplaces(Argument::type('array'))->shouldBeCalled();
$alias = new RootAliasPackage($root->reveal(), '1.0', '1.0.0.0');
$this->assertEmpty($alias->getReplaces());
$links = array(new Link('a', 'b', null, 'foo', 'self.version'));
$alias->setReplaces($links);
$this->assertNotEmpty($alias->getReplaces());
}
protected function getMockRootPackageInterface()
{
$root = $this->prophesize('Composer\\Package\\RootPackageInterface');
$root->getName()->willReturn('something/something')->shouldBeCalled();
$root->getRequires()->willReturn(array())->shouldBeCalled();
$root->getDevRequires()->willReturn(array())->shouldBeCalled();
$root->getConflicts()->willReturn(array())->shouldBeCalled();
$root->getProvides()->willReturn(array())->shouldBeCalled();
$root->getReplaces()->willReturn(array())->shouldBeCalled();
return $root;
}
}