From fe5d968e090dc48751fab4d5e9ce72a9b66615c1 Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Wed, 21 Mar 2018 16:43:46 +0100 Subject: [PATCH 1/3] Convert questions to a string Since symfony/console 4 questions only accept a question string. Looking at its history, this was always the case and is wrong in the composer docblock. see: https://github.com/symfony/console/blob/4.0/Question/Question.php#L37 see: https://github.com/composer/composer/blob/1.6/src/Composer/IO/IOInterface.php#L106 related: https://github.com/zendframework/zend-expressive-skeleton/pull/244 related: https://github.com/zendframework/zend-expressive-skeleton/issues/243 --- src/ComponentInstaller.php | 4 +- test/ComponentInstallerTest.php | 242 +++++++++++++------------------- 2 files changed, 100 insertions(+), 146 deletions(-) diff --git a/src/ComponentInstaller.php b/src/ComponentInstaller.php index b1b833f..8a80638 100644 --- a/src/ComponentInstaller.php +++ b/src/ComponentInstaller.php @@ -449,7 +449,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 +474,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..3c3cebf 100644 --- a/test/ComponentInstallerTest.php +++ b/test/ComponentInstallerTest.php @@ -76,6 +76,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 +173,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 +521,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 +617,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 +781,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 +804,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 +845,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 +868,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 +892,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 +944,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 +967,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 +1001,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 +1024,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 +1063,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 +1086,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 +1252,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 +1275,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 +1320,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 +1343,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 +1366,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 +1416,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 +1439,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 +1462,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; } From 225ddd852560e3b2149e813d6b73e6a17919825f Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Wed, 21 Mar 2018 16:44:30 +0100 Subject: [PATCH 2/3] Remove unused imports --- src/ComponentInstaller.php | 1 - test/ComponentInstallerTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/ComponentInstaller.php b/src/ComponentInstaller.php index 8a80638..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. diff --git a/test/ComponentInstallerTest.php b/test/ComponentInstallerTest.php index 3c3cebf..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; From d59ccbfd93a8a97fe427c8ccb44a5ce63166507c Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 21 Mar 2018 11:53:43 -0500 Subject: [PATCH 3/3] Adds CHANGELOG entry for #54 --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2e76db..84bab81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.1.1 - TBD +## 2.1.1 - 2018-03-21 ### Added @@ -22,7 +22,8 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#54](https://github.com/zendframework/zend-component-installer/pull/54) fixes + issues when run with symfony/console v4 releases. ## 2.1.0 - 2018-02-08