From 0f315da036a13cc5eada1e04d1372b433a5b02df Mon Sep 17 00:00:00 2001 From: webimpress Date: Tue, 17 Oct 2017 17:58:25 +0100 Subject: [PATCH] Check if package is defined in require-dev, if so, skip adding Resolves #5 --- src/Plugin.php | 3 ++- test/PluginTest.php | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index b177a27..e8c31b1 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -214,7 +214,8 @@ private function createInstaller(Composer $composer, IOInterface $io, RootPackag private function hasPackage($package) { - $requires = $this->composer->getPackage()->getRequires(); + $rootPackage = $this->composer->getPackage(); + $requires = $rootPackage->getRequires() + $rootPackage->getDevRequires(); foreach ($requires as $name => $link) { if (strtolower($name) === strtolower($package)) { return true; diff --git a/test/PluginTest.php b/test/PluginTest.php index e055606..fff6b98 100644 --- a/test/PluginTest.php +++ b/test/PluginTest.php @@ -175,6 +175,7 @@ public function testDoNothingInNoInteractionMode() $rootPackage = $this->prophesize(RootPackageInterface::class); $rootPackage->getRequires()->willReturn([]); + $rootPackage->getDevRequires()->willReturn([]); $this->composer->getPackage()->willReturn($rootPackage); @@ -222,7 +223,40 @@ public function testDependencyAlreadyIsInRequiredSection() $link->getTarget()->willReturn('extra-dependency-foo'); $rootPackage = $this->prophesize(RootPackageInterface::class); - $rootPackage->getRequires()->willReturn(['extra-dependency-foo' => $link->reveal()]); + $rootPackage->getDevRequires()->willReturn(['extra-dependency-foo' => $link->reveal()]); + + $this->composer->getPackage()->willReturn($rootPackage); + + $this->assertNull($this->plugin->onPostPackage($event->reveal())); + } + + public function testDependencyAlreadyIsInRequiredDevSection() + { + /** @var PackageInterface|ObjectProphecy $package */ + $package = $this->prophesize(PackageInterface::class); + $package->getName()->willReturn('some/component'); + $package->getExtra()->willReturn([ + 'dependency' => [ + 'extra-dependency-foo', + ], + ]); + + $operation = $this->prophesize(InstallOperation::class); + $operation->getPackage()->willReturn($package->reveal()); + + $event = $this->prophesize(PackageEvent::class); + $event->isDevMode()->willReturn(true); + $event->getOperation()->willReturn($operation->reveal()); + + $this->io->isInteractive()->willReturn(true)->shouldBeCalled(); + $this->io->askAndValidate(Argument::any())->shouldNotBeCalled(); + + $link = $this->prophesize(Link::class); + $link->getTarget()->willReturn('extra-dependency-foo'); + + $rootPackage = $this->prophesize(RootPackageInterface::class); + $rootPackage->getRequires()->willReturn([]); + $rootPackage->getDevRequires()->willReturn(['extra-dependency-foo' => $link->reveal()]); $this->composer->getPackage()->willReturn($rootPackage); @@ -247,12 +281,16 @@ public function testInstallSingleDependencyOnPackageUpdate() $event->isDevMode()->willReturn(true); $event->getOperation()->willReturn($operation->reveal()); + $this->io->isInteractive()->willReturn(true)->shouldBeCalled(); + $this->io->askAndValidate(Argument::any())->shouldNotBeCalled(); + $config = $this->prophesize(Config::class); $config->get('sort-packages')->willReturn(true); $config->get(Argument::any())->willReturn(null); $rootPackage = $this->prophesize(RootPackageInterface::class); $rootPackage->getRequires()->willReturn([]); + $rootPackage->getDevRequires()->willReturn([]); $rootPackage->setRequires(Argument::that(function ($arguments) { if (! is_array($arguments)) { return false; @@ -327,6 +365,7 @@ public function testInstallSingleDependencyOnPackageInstall() $rootPackage = $this->prophesize(RootPackageInterface::class); $rootPackage->getRequires()->willReturn([]); + $rootPackage->getDevRequires()->willReturn([]); $rootPackage->setRequires(Argument::that(function ($arguments) { if (! is_array($arguments)) { return false; @@ -405,6 +444,7 @@ public function testInstallOneDependenciesWhenOneIsAlreadyInstalled() $rootPackage = $this->prophesize(RootPackageInterface::class); $rootPackage->getRequires()->willReturn(['extra-dependency-bar' => $link->reveal()]); + $rootPackage->getDevRequires()->willReturn([]); $rootPackage->setRequires(Argument::that(function ($arguments) { if (! is_array($arguments)) { return false; @@ -488,6 +528,7 @@ public function testInstallSingleDependencyAndAutomaticallyChooseLatestVersion() $rootPackage = $this->prophesize(RootPackageInterface::class); $rootPackage->getRequires()->willReturn([]); + $rootPackage->getDevRequires()->willReturn([]); $rootPackage->setRequires(Argument::that(function ($arguments) { if (! is_array($arguments)) { return false; @@ -582,6 +623,7 @@ public function testInstallSingleDependencyAndAutomaticallyChooseLatestVersionNo $rootPackage = $this->prophesize(RootPackageInterface::class); $rootPackage->getRequires()->willReturn([]); + $rootPackage->getDevRequires()->willReturn([]); $rootPackage->getMinimumStability()->willReturn('stable'); $this->composer->getPackage()->willReturn($rootPackage); @@ -640,6 +682,7 @@ public function testUpdateComposerWithCurrentlyInstalledVersion() $rootPackage = $this->prophesize(RootPackageInterface::class); $rootPackage->getRequires()->willReturn([]); + $rootPackage->getDevRequires()->willReturn([]); $rootPackage->setRequires(Argument::that(function ($arguments) { if (! is_array($arguments)) { return false;