Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/5'
Browse files Browse the repository at this point in the history
Close #5
  • Loading branch information
michalbundyra committed Oct 17, 2017
2 parents 7287ebc + 0f315da commit 85a783a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
45 changes: 44 additions & 1 deletion test/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public function testDoNothingInNoInteractionMode()

$rootPackage = $this->prophesize(RootPackageInterface::class);
$rootPackage->getRequires()->willReturn([]);
$rootPackage->getDevRequires()->willReturn([]);

$this->composer->getPackage()->willReturn($rootPackage);

Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 85a783a

Please sign in to comment.