Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/install-by-default' into develop
Browse files Browse the repository at this point in the history
Close #49
  • Loading branch information
weierophinney committed Feb 6, 2018
2 parents e61bb34 + dcf123f commit d6fb377
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 39 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 1.2.0 - TBD
## 2.0.0 - TBD

### Added

- Nothing.

### Changed

- Nothing.
- [#49](https://github.com/zendframework/zend-component-installer/pull/49)
modifies the default options for installer prompts. If providers and/or
modules are discovered, the installer uses the first discovered as the default
option, instead of the "Do not inject" option. Additionally, the "remember
this selection" prompt now defaults to "y" instead of "n".

### Deprecated

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev",
"dev-develop": "1.2-dev"
"dev-master": "1.1.x-dev",
"dev-develop": "2.0.x-dev"
},
"class": "Zend\\ComponentInstaller\\ComponentInstaller"
},
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/ComponentInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ private function promptForConfigOption($name, Collection $options, $packageType)
return $cachedInjector;
}

// Default to first discovered option; index 0 is always "Do not inject"
$default = $options->count() > 1 ? 1 : 0;
$ask = $options->reduce(function ($ask, $option, $index) {
$ask[] = sprintf(
" [<comment>%d</comment>] %s\n",
Expand All @@ -428,10 +430,10 @@ private function promptForConfigOption($name, Collection $options, $packageType)
"\n <question>Please select which config file you wish to inject '%s' into:</question>\n",
$name
));
$ask[] = ' Make your selection (default is <comment>0</comment>):';
$ask[] = sprintf(' Make your selection (default is <comment>%d</comment>):', $default);

while (true) {
$answer = $this->io->ask($ask, 0);
$answer = $this->io->ask($ask, $default);

if (is_numeric($answer) && isset($options[(int) $answer])) {
$injector = $options[(int) $answer]->getInjector();
Expand All @@ -453,10 +455,10 @@ private function promptForConfigOption($name, Collection $options, $packageType)
*/
private function promptToRememberOption(Injector\InjectorInterface $injector, $packageType)
{
$ask = ["\n <question>Remember this option for other packages of the same type? (y/N)</question>"];
$ask = ["\n <question>Remember this option for other packages of the same type? (Y/n)</question>"];

while (true) {
$answer = strtolower($this->io->ask($ask, 'n'));
$answer = strtolower($this->io->ask($ask, 'y'));

switch ($answer) {
case 'y':
Expand Down
69 changes: 39 additions & 30 deletions test/ComponentInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function getModuleDependencies()
}

return true;
}), 0)->willReturn(1);
}), 1)->willReturn(1);

$this->io->ask(Argument::that(function ($argument) {
if (! is_array($argument)) {
Expand All @@ -162,7 +162,7 @@ public function getModuleDependencies()
}

return true;
}), 'n')->willReturn('n');
}), 'y')->willReturn('y');

$this->io->write(Argument::that(function ($argument) {
return strstr($argument, 'Installing SomeComponent from package some/component');
Expand Down Expand Up @@ -525,7 +525,7 @@ public function getModuleDependencies()
}

return true;
}), 0)->willReturn(1);
}), 1)->willReturn(1);

$this->io->ask(Argument::that(function ($argument) {
if (! is_array($argument)) {
Expand All @@ -536,7 +536,7 @@ public function getModuleDependencies()
}

return true;
}), 'n')->willReturn('n');
}), 'y')->willReturn('y');

$this->io->write(Argument::that(function ($argument) use ($packageName) {
return strstr($argument, sprintf('Installing %s from package some/component', $packageName));
Expand Down Expand Up @@ -647,7 +647,7 @@ public function testModuleBeforeApplicationModules(array $availableModules, arra
}

return true;
}), 0)->willReturn(1);
}), 1)->willReturn(1);

$this->io->ask(Argument::that(function ($argument) {
if (! is_array($argument)) {
Expand All @@ -658,7 +658,7 @@ public function testModuleBeforeApplicationModules(array $availableModules, arra
}

return true;
}), 'n')->willReturn('n');
}), 'y')->willReturn('y');

$this->io->write(Argument::that(function ($argument) {
return strstr($argument, 'Installing SomeModule from package some/module');
Expand Down Expand Up @@ -806,7 +806,7 @@ public function testOnPostPackageInstallPromptsForConfigOptions()
}

return true;
}), 0)->willReturn(1);
}), 1)->willReturn(1);

$this->io->ask(Argument::that(function ($argument) {
if (! is_array($argument)) {
Expand All @@ -817,7 +817,7 @@ public function testOnPostPackageInstallPromptsForConfigOptions()
}

return true;
}), 'n')->willReturn('n');
}), 'y')->willReturn('y');

$this->io->write(Argument::that(function ($argument) {
return strstr($argument, 'Installing Some\Component from package some/component');
Expand Down Expand Up @@ -870,7 +870,7 @@ public function testOnPostPackageInstallPromptsForConfigOptionsWhenDefinedAsArra
}

return true;
}), 0)->willReturn(1);
}), 1)->willReturn(1);

$this->io->ask(Argument::that(function ($argument) {
if (! is_array($argument)) {
Expand All @@ -893,24 +893,33 @@ public function testOnPostPackageInstallPromptsForConfigOptionsWhenDefinedAsArra
}

return true;
}), 0)->willReturn(1);
}), 1)->willReturn(1);

$this->io->ask(Argument::that(function ($argument) {
$io = $this->io;
$askValidator = function ($argument) {
if (! is_array($argument)) {
return false;
return false;
}
if (false === strpos($argument[0], 'Remember')) {
return false;
}

return true;
}), 'n')->willReturn('n')->shouldBeCalledTimes(2);

$this->io->write(Argument::that(function ($argument) {
};
$io
->ask(Argument::that($askValidator), 'y')
->will(function () use ($io, $askValidator) {
$io
->ask(Argument::that($askValidator), 'y')
->willReturn('y');
return 'n';
});

$io->write(Argument::that(function ($argument) {
return strstr($argument, 'Installing Some\Component from package some/component');
}))->shouldBeCalled();

$this->io->write(Argument::that(function ($argument) {
$io->write(Argument::that(function ($argument) {
return strstr($argument, 'Installing Other\Component from package some/component');
}))->shouldBeCalled();

Expand Down Expand Up @@ -960,7 +969,7 @@ public function testMultipleInvocationsOfOnPostPackageInstallCanPromptMultipleTi
}

return true;
}), 0)->willReturn(1);
}), 1)->willReturn(1);

$this->io->ask(Argument::that(function ($argument) {
if (! is_array($argument)) {
Expand All @@ -971,7 +980,7 @@ public function testMultipleInvocationsOfOnPostPackageInstallCanPromptMultipleTi
}

return true;
}), 'n')->willReturn('n');
}), 'y')->willReturn('n');

$this->io->write(Argument::that(function ($argument) {
return strstr($argument, 'Installing Some\Component from package some/component');
Expand Down Expand Up @@ -1017,7 +1026,7 @@ public function testMultipleInvocationsOfOnPostPackageInstallCanPromptMultipleTi
}

return true;
}), 0)->willReturn(1);
}), 1)->willReturn(1);

$this->io->ask(Argument::that(function ($argument) {
if (! is_array($argument)) {
Expand All @@ -1028,7 +1037,7 @@ public function testMultipleInvocationsOfOnPostPackageInstallCanPromptMultipleTi
}

return true;
}), 'n')->willReturn('n');
}), 'y')->willReturn('y');

$this->io->write(Argument::that(function ($argument) {
return strstr($argument, 'Installing Other\Component from package other/component');
Expand Down Expand Up @@ -1079,7 +1088,7 @@ public function testMultipleInvocationsOfOnPostPackageInstallCanReuseOptions()
}

return true;
}), 0)->willReturn(1);
}), 1)->willReturn(1);

$this->io->ask(Argument::that(function ($argument) {
if (! is_array($argument)) {
Expand All @@ -1090,7 +1099,7 @@ public function testMultipleInvocationsOfOnPostPackageInstallCanReuseOptions()
}

return true;
}), 'n')->willReturn('y');
}), 'y')->willReturn('y')->shouldBeCalledTimes(1);

$this->io->write(Argument::that(function ($argument) {
return strstr($argument, 'Installing Some\Component from package some/component');
Expand Down Expand Up @@ -1268,7 +1277,7 @@ public function testModuleIsAppended()
}

return true;
}), 0)->willReturn(1);
}), 1)->willReturn(1);

$this->io->ask(Argument::that(function ($argument) {
if (! is_array($argument)) {
Expand All @@ -1279,7 +1288,7 @@ public function testModuleIsAppended()
}

return true;
}), 'n')->willReturn('n');
}), 'y')->willReturn('y');

$this->io->write(Argument::that(function ($argument) {
return strstr($argument, 'Installing Some\Module from package some/module');
Expand Down Expand Up @@ -1336,7 +1345,7 @@ public function testAppendModuleAndPrependComponent()
}

return true;
}), 0)->willReturn(1);
}), 1)->willReturn(1);

$this->io->ask(Argument::that(function ($argument) {
if (! is_array($argument)) {
Expand All @@ -1359,7 +1368,7 @@ public function testAppendModuleAndPrependComponent()
}

return true;
}), 0)->willReturn(1);
}), 1)->willReturn(1);

$this->io->ask(Argument::that(function ($argument) {
if (! is_array($argument)) {
Expand All @@ -1370,7 +1379,7 @@ public function testAppendModuleAndPrependComponent()
}

return true;
}), 'n')->willReturn('n');
}), 'y')->willReturn('n');

$this->io->write(Argument::that(function ($argument) {
return strstr($argument, 'Installing Some\Module from package some/package');
Expand Down Expand Up @@ -1432,7 +1441,7 @@ public function testPrependComponentAndAppendModule()
}

return true;
}), 0)->willReturn(1);
}), 1)->willReturn(1);

$this->io->ask(Argument::that(function ($argument) {
if (! is_array($argument)) {
Expand All @@ -1455,7 +1464,7 @@ public function testPrependComponentAndAppendModule()
}

return true;
}), 0)->willReturn(1);
}), 1)->willReturn(1);

$this->io->ask(Argument::that(function ($argument) {
if (! is_array($argument)) {
Expand All @@ -1466,7 +1475,7 @@ public function testPrependComponentAndAppendModule()
}

return true;
}), 'n')->willReturn('n');
}), 'y')->willReturn('n');

$this->io->write(Argument::that(function ($argument) {
return strstr($argument, 'Installing Some\Module from package some/package');
Expand Down

0 comments on commit d6fb377

Please sign in to comment.