Explorar el Código

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.
Bryan Davis hace 9 años
padre
commit
06c44ce998

+ 48 - 0
src/Composer/Package/RootAliasPackage.php

@@ -109,6 +109,54 @@ class RootAliasPackage extends AliasPackage implements RootPackageInterface
         $this->aliasOf->setReplaces($replaces);
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    public function setRepositories($repositories)
+    {
+        $this->aliasOf->setRepositories($repositories);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function setAutoload(array $autoload)
+    {
+        $this->aliasOf->setAutoload($autoload);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function setDevAutoload(array $devAutoload)
+    {
+        $this->aliasOf->setDevAutoload($devAutoload);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function setStabilityFlags(array $stabilityFlags)
+    {
+        $this->aliasOf->setStabilityFlags($stabilityFlags);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function setSuggests(array $suggests)
+    {
+        $this->aliasOf->setSuggests($suggests);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function setExtra(array $extra)
+    {
+        $this->aliasOf->setExtra($extra);
+    }
+
     public function __clone()
     {
         parent::__clone();

+ 61 - 0
src/Composer/Package/RootPackageInterface.php

@@ -71,4 +71,65 @@ interface RootPackageInterface extends CompletePackageInterface
      * @param array $devRequires A set of package links
      */
     public function setDevRequires(array $devRequires);
+
+    /**
+     * Set the conflicting packages
+     *
+     * @param array $conflicts A set of package links
+     */
+    public function setConflicts(array $conflicts);
+
+    /**
+     * Set the provided virtual packages
+     *
+     * @param array $provides A set of package links
+     */
+    public function setProvides(array $provides);
+
+    /**
+     * Set the packages this one replaces
+     *
+     * @param array $replaces A set of package links
+     */
+    public function setReplaces(array $replaces);
+
+    /**
+     * Set the repositories
+     *
+     * @param array $repositories
+     */
+    public function setRepositories($repositories);
+
+    /**
+     * Set the autoload mapping
+     *
+     * @param array $autoload Mapping of autoloading rules
+     */
+    public function setAutoload(array $autoload);
+
+    /**
+     * Set the dev autoload mapping
+     *
+     * @param array $devAutoload Mapping of dev autoloading rules
+     */
+    public function setDevAutoload(array $devAutoload);
+
+    /**
+     * Set the stabilityFlags
+     *
+     * @param array $stabilityFlags
+     */
+    public function setStabilityFlags(array $stabilityFlags);
+
+    /**
+     * Set the suggested packages
+     *
+     * @param array $suggests A set of package names/comments
+     */
+    public function setSuggests(array $suggests);
+
+    /**
+     * @param array $extra
+     */
+    public function setExtra(array $extra);
 }

+ 94 - 0
tests/Composer/Test/Package/RootAliasPackageTest.php

@@ -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;
+    }
+}