diff --git a/src/ComponentInstaller.php b/src/ComponentInstaller.php
index b1b833f..9c43da2 100644
--- a/src/ComponentInstaller.php
+++ b/src/ComponentInstaller.php
@@ -18,7 +18,6 @@
use Zend\ComponentInstaller\Injector\AbstractInjector;
use Zend\ComponentInstaller\Injector\ConfigInjectorChain;
use Zend\ComponentInstaller\Injector\InjectorInterface;
-use Zend\ComponentInstaller\Injector\NoopInjector;
/**
* If a package represents a component module, update the application configuration.
@@ -449,7 +448,7 @@ private function promptForConfigOption(
$ask[] = sprintf(' Make your selection (default is %d):', $default);
while (true) {
- $answer = $this->io->ask($ask, $default);
+ $answer = $this->io->ask(implode($ask), $default);
if (is_numeric($answer) && isset($options[(int) $answer])) {
$injector = $options[(int) $answer]->getInjector();
@@ -474,7 +473,7 @@ private function promptToRememberOption(Injector\InjectorInterface $injector, $p
$ask = ["\n Remember this option for other packages of the same type? (Y/n)"];
while (true) {
- $answer = strtolower($this->io->ask($ask, 'y'));
+ $answer = strtolower($this->io->ask(implode($ask), 'y'));
switch ($answer) {
case 'y':
diff --git a/test/ComponentInstallerTest.php b/test/ComponentInstallerTest.php
index 8e6f451..59a04a7 100644
--- a/test/ComponentInstallerTest.php
+++ b/test/ComponentInstallerTest.php
@@ -16,7 +16,6 @@
use Composer\Package\RootPackageInterface;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
-use org\bovigo\vfs\vfsStreamWrapper;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
@@ -76,6 +75,38 @@ public function setUp()
$this->composer->getInstallationManager()->willReturn($this->installationManager->reveal());
}
+ public static function assertPrompt($argument, $packageName = null)
+ {
+ if (! is_string($argument)) {
+ return false;
+ }
+
+ if (false !== strpos($argument, 'Remember this option for other packages of the same type?')) {
+ return true;
+ }
+
+ if (! $packageName) {
+ return false;
+ }
+
+ if (false === strpos(
+ $argument,
+ sprintf("Please select which config file you wish to inject '%s' into", $packageName)
+ )) {
+ return false;
+ }
+
+ if (false === strpos($argument, 'Do not inject')) {
+ return false;
+ }
+
+ if (false === strpos($argument, 'application.config.php')) {
+ return false;
+ }
+
+ return true;
+ }
+
public function createApplicationConfig($contents = null)
{
$contents = $contents ?: '<' . "?php\nreturn [\n 'modules' => [\n ]\n];";
@@ -141,37 +172,11 @@ public function getModuleDependencies()
$event->getOperation()->willReturn($operation->reveal());
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
- return false;
- }
-
- if (false === strpos(
- $argument[0],
- "Please select which config file you wish to inject 'SomeComponent' into"
- )) {
- return false;
- }
-
- if (false === strpos($argument[1], 'Do not inject')) {
- return false;
- }
-
- if (false === strpos($argument[2], 'application.config.php')) {
- return false;
- }
-
- return true;
+ return ComponentInstallerTest::assertPrompt($argument, 'SomeComponent');
}), 1)->willReturn(1);
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
- return false;
- }
- if (false === strpos($argument[0], 'Remember')) {
- return false;
- }
-
- return true;
+ return ComponentInstallerTest::assertPrompt($argument);
}), 'y')->willReturn('y');
$this->io->write(Argument::that(function ($argument) {
@@ -515,37 +520,11 @@ public function getModuleDependencies()
$event->getOperation()->willReturn($operation->reveal());
$this->io->ask(Argument::that(function ($argument) use ($packageName) {
- if (! is_array($argument)) {
- return false;
- }
-
- if (false === strpos(
- $argument[0],
- sprintf("Please select which config file you wish to inject '%s' into", $packageName)
- )) {
- return false;
- }
-
- if (false === strpos($argument[1], 'Do not inject')) {
- return false;
- }
-
- if (false === strpos($argument[2], 'application.config.php')) {
- return false;
- }
-
- return true;
+ return ComponentInstallerTest::assertPrompt($argument, $packageName);
}), 1)->willReturn(1);
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
- return false;
- }
- if (false === strpos($argument[0], 'Remember')) {
- return false;
- }
-
- return true;
+ return ComponentInstallerTest::assertPrompt($argument);
}), 'y')->willReturn('y');
$this->io->write(Argument::that(function ($argument) use ($packageName) {
@@ -637,37 +616,11 @@ public function testModuleBeforeApplicationModules(array $availableModules, arra
$event->getOperation()->willReturn($operation->reveal());
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
- return false;
- }
-
- if (false === strpos(
- $argument[0],
- "Please select which config file you wish to inject 'SomeModule' into"
- )) {
- return false;
- }
-
- if (false === strpos($argument[1], 'Do not inject')) {
- return false;
- }
-
- if (false === strpos($argument[2], 'application.config.php')) {
- return false;
- }
-
- return true;
+ return ComponentInstallerTest::assertPrompt($argument, 'SomeModule');
}), 1)->willReturn(1);
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
- return false;
- }
- if (false === strpos($argument[0], 'Remember')) {
- return false;
- }
-
- return true;
+ return ComponentInstallerTest::assertPrompt($argument);
}), 'y')->willReturn('y');
$this->io->write(Argument::that(function ($argument) {
@@ -827,22 +780,22 @@ public function testOnPostPackageInstallPromptsForConfigOptions()
$event->getOperation()->willReturn($operation->reveal());
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
if (false === strpos(
- $argument[0],
+ $argument,
"Please select which config file you wish to inject 'Some\Component' into"
)) {
return false;
}
- if (false === strpos($argument[1], 'Do not inject')) {
+ if (false === strpos($argument, 'Do not inject')) {
return false;
}
- if (false === strpos($argument[2], 'application.config.php')) {
+ if (false === strpos($argument, 'application.config.php')) {
return false;
}
@@ -850,10 +803,10 @@ public function testOnPostPackageInstallPromptsForConfigOptions()
}), 1)->willReturn(1);
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
- if (false === strpos($argument[0], 'Remember')) {
+ if (false === strpos($argument, 'Remember')) {
return false;
}
@@ -891,22 +844,22 @@ public function testOnPostPackageInstallPromptsForConfigOptionsWhenDefinedAsArra
$event->getOperation()->willReturn($operation->reveal());
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
if (false === strpos(
- $argument[0],
+ $argument,
"Please select which config file you wish to inject 'Some\Component' into"
)) {
return false;
}
- if (false === strpos($argument[1], 'Do not inject')) {
+ if (false === strpos($argument, 'Do not inject')) {
return false;
}
- if (false === strpos($argument[2], 'application.config.php')) {
+ if (false === strpos($argument, 'application.config.php')) {
return false;
}
@@ -914,22 +867,22 @@ public function testOnPostPackageInstallPromptsForConfigOptionsWhenDefinedAsArra
}), 1)->willReturn(1);
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
if (false === strpos(
- $argument[0],
+ $argument,
"Please select which config file you wish to inject 'Other\Component' into"
)) {
return false;
}
- if (false === strpos($argument[1], 'Do not inject')) {
+ if (false === strpos($argument, 'Do not inject')) {
return false;
}
- if (false === strpos($argument[2], 'application.config.php')) {
+ if (false === strpos($argument, 'application.config.php')) {
return false;
}
@@ -938,10 +891,10 @@ public function testOnPostPackageInstallPromptsForConfigOptionsWhenDefinedAsArra
$io = $this->io;
$askValidator = function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
- if (false === strpos($argument[0], 'Remember')) {
+ if (false === strpos($argument, 'Remember')) {
return false;
}
@@ -990,22 +943,22 @@ public function testMultipleInvocationsOfOnPostPackageInstallCanPromptMultipleTi
$event->getOperation()->willReturn($operation->reveal());
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
if (false === strpos(
- $argument[0],
+ $argument,
"Please select which config file you wish to inject 'Some\Component' into"
)) {
return false;
}
- if (false === strpos($argument[1], 'Do not inject')) {
+ if (false === strpos($argument, 'Do not inject')) {
return false;
}
- if (false === strpos($argument[2], 'application.config.php')) {
+ if (false === strpos($argument, 'application.config.php')) {
return false;
}
@@ -1013,10 +966,10 @@ public function testMultipleInvocationsOfOnPostPackageInstallCanPromptMultipleTi
}), 1)->willReturn(1);
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
- if (false === strpos($argument[0], 'Remember')) {
+ if (false === strpos($argument, 'Remember')) {
return false;
}
@@ -1047,22 +1000,22 @@ public function testMultipleInvocationsOfOnPostPackageInstallCanPromptMultipleTi
$event->getOperation()->willReturn($operation->reveal());
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
if (false === strpos(
- $argument[0],
+ $argument,
"Please select which config file you wish to inject 'Other\Component' into"
)) {
return false;
}
- if (false === strpos($argument[1], 'Do not inject')) {
+ if (false === strpos($argument, 'Do not inject')) {
return false;
}
- if (false === strpos($argument[2], 'application.config.php')) {
+ if (false === strpos($argument, 'application.config.php')) {
return false;
}
@@ -1070,10 +1023,10 @@ public function testMultipleInvocationsOfOnPostPackageInstallCanPromptMultipleTi
}), 1)->willReturn(1);
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
- if (false === strpos($argument[0], 'Remember')) {
+ if (false === strpos($argument, 'Remember')) {
return false;
}
@@ -1109,22 +1062,22 @@ public function testMultipleInvocationsOfOnPostPackageInstallCanReuseOptions()
$event->getOperation()->willReturn($operation->reveal());
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
if (false === strpos(
- $argument[0],
+ $argument,
"Please select which config file you wish to inject 'Some\Component' into"
)) {
return false;
}
- if (false === strpos($argument[1], 'Do not inject')) {
+ if (false === strpos($argument, 'Do not inject')) {
return false;
}
- if (false === strpos($argument[2], 'application.config.php')) {
+ if (false === strpos($argument, 'application.config.php')) {
return false;
}
@@ -1132,10 +1085,10 @@ public function testMultipleInvocationsOfOnPostPackageInstallCanReuseOptions()
}), 1)->willReturn(1);
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
- if (false === strpos($argument[0], 'Remember')) {
+ if (false === strpos($argument, 'Remember')) {
return false;
}
@@ -1298,22 +1251,22 @@ public function testModuleIsAppended()
$event->getOperation()->willReturn($operation->reveal());
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
if (false === strpos(
- $argument[0],
+ $argument,
"Please select which config file you wish to inject 'Some\Module' into"
)) {
return false;
}
- if (false === strpos($argument[1], 'Do not inject')) {
+ if (false === strpos($argument, 'Do not inject')) {
return false;
}
- if (false === strpos($argument[2], 'application.config.php')) {
+ if (false === strpos($argument, 'application.config.php')) {
return false;
}
@@ -1321,10 +1274,10 @@ public function testModuleIsAppended()
}), 1)->willReturn(1);
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
- if (false === strpos($argument[0], 'Remember')) {
+ if (false === strpos($argument, 'Remember')) {
return false;
}
@@ -1366,22 +1319,22 @@ public function testAppendModuleAndPrependComponent()
$event->getOperation()->willReturn($operation->reveal());
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
if (false === strpos(
- $argument[0],
+ $argument,
"Please select which config file you wish to inject 'Some\Module' into"
)) {
return false;
}
- if (false === strpos($argument[1], 'Do not inject')) {
+ if (false === strpos($argument, 'Do not inject')) {
return false;
}
- if (false === strpos($argument[2], 'application.config.php')) {
+ if (false === strpos($argument, 'application.config.php')) {
return false;
}
@@ -1389,22 +1342,22 @@ public function testAppendModuleAndPrependComponent()
}), 1)->willReturn(1);
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
if (false === strpos(
- $argument[0],
+ $argument,
"Please select which config file you wish to inject 'Some\Component' into"
)) {
return false;
}
- if (false === strpos($argument[1], 'Do not inject')) {
+ if (false === strpos($argument, 'Do not inject')) {
return false;
}
- if (false === strpos($argument[2], 'application.config.php')) {
+ if (false === strpos($argument, 'application.config.php')) {
return false;
}
@@ -1412,10 +1365,10 @@ public function testAppendModuleAndPrependComponent()
}), 1)->willReturn(1);
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
- if (false === strpos($argument[0], 'Remember')) {
+ if (false === strpos($argument, 'Remember')) {
return false;
}
@@ -1462,22 +1415,22 @@ public function testPrependComponentAndAppendModule()
$event->getOperation()->willReturn($operation->reveal());
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
if (false === strpos(
- $argument[0],
+ $argument,
"Please select which config file you wish to inject 'Some\Module' into"
)) {
return false;
}
- if (false === strpos($argument[1], 'Do not inject')) {
+ if (false === strpos($argument, 'Do not inject')) {
return false;
}
- if (false === strpos($argument[2], 'application.config.php')) {
+ if (false === strpos($argument, 'application.config.php')) {
return false;
}
@@ -1485,22 +1438,22 @@ public function testPrependComponentAndAppendModule()
}), 1)->willReturn(1);
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
if (false === strpos(
- $argument[0],
+ $argument,
"Please select which config file you wish to inject 'Some\Component' into"
)) {
return false;
}
- if (false === strpos($argument[1], 'Do not inject')) {
+ if (false === strpos($argument, 'Do not inject')) {
return false;
}
- if (false === strpos($argument[2], 'application.config.php')) {
+ if (false === strpos($argument, 'application.config.php')) {
return false;
}
@@ -1508,10 +1461,10 @@ public function testPrependComponentAndAppendModule()
}), 1)->willReturn(1);
$this->io->ask(Argument::that(function ($argument) {
- if (! is_array($argument)) {
+ if (! is_string($argument)) {
return false;
}
- if (false === strpos($argument[0], 'Remember')) {
+ if (false === strpos($argument, 'Remember')) {
return false;
}