From d5cef3201219d3e86deb8933981efcb7b3ca28e6 Mon Sep 17 00:00:00 2001 From: Jelle Sebreghts Date: Mon, 30 Jan 2017 10:01:07 +0100 Subject: [PATCH 1/3] Issue #6: Fix too many arguments error. --- src/DrupalConsoleStack.php | 29 +++++++++++++++++++--- tests/DrupalConsoleStackTest.php | 42 ++++++++++++++++---------------- 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/DrupalConsoleStack.php b/src/DrupalConsoleStack.php index d1849b3..12176b5 100644 --- a/src/DrupalConsoleStack.php +++ b/src/DrupalConsoleStack.php @@ -44,7 +44,9 @@ class DrupalConsoleStack extends CommandStack { - use CommandArguments; + use CommandArguments { + option as optionNoEqualSign; + } /** * Verbosity levels: @@ -89,6 +91,27 @@ public function __construct($pathToDrupalConsole = 'drupal') $this->executable = $pathToDrupalConsole; } + /** + * Pass option to executable. Options are prefixed with `--` , value can be provided in second parameter. + * Option values are automatically escaped. + * + * @param string $option + * The option name. + * @param string $value + * The option value. + * + * @return $this + */ + public function option($option, $value = null) + { + if ($option !== null and strpos($option, '-') !== 0) { + $option = "--$option"; + } + $this->arguments .= null == $option ? '' : " " . $option; + $this->arguments .= null == $value ? '' : "=" . static::escape($value); + return $this; + } + /** * Pass an option to the executable; applies to the next command only. * @@ -732,8 +755,8 @@ protected function injectArguments($command, $assumeYes) { $optionsForNextCmd = ''; foreach ($this->optionsForNextCmd as $option => $value) { - $optionsForNextCmd .= ' --'.$option.( - is_null($value) ? '' : ' '.static::escape($value) + $optionsForNextCmd .= ' --' . $option . ( + is_null($value) ? '' : '=' . static::escape($value) ); } $cmd = $command; diff --git a/tests/DrupalConsoleStackTest.php b/tests/DrupalConsoleStackTest.php index 91ed59d..16f9fc4 100644 --- a/tests/DrupalConsoleStackTest.php +++ b/tests/DrupalConsoleStackTest.php @@ -109,7 +109,7 @@ public function testOptionsArePrependedBeforeEachCommand() ->drupal('command-1') ->drupal('command-2') ->getCommand(); - $this->assertRegExp('#--root /var/www/html/app#', $command); + $this->assertRegExp('#--root=/var/www/html/app#', $command); } /** @@ -300,7 +300,7 @@ public function testListCommandOutsideDrupalSite() public function testDrupalRootDirectoryOption() { $this->assertEquals( - 'drupal command --root '.static::escape(__DIR__), + 'drupal command --root='.static::escape(__DIR__), $this->getTestOptionCommand('drupalRootDirectory', __DIR__) ); } @@ -311,7 +311,7 @@ public function testDrupalRootDirectoryOption() public function testUriOption() { $this->assertEquals( - 'drupal command --uri '.static::escape('http://example.com'), + 'drupal command --uri='.static::escape('http://example.com'), $this->getTestOptionCommand('uri', 'http://example.com') ); } @@ -322,7 +322,7 @@ public function testUriOption() public function testEnvironmentOption() { $this->assertEquals( - 'drupal command --env prod', + 'drupal command --env=prod', $this->getTestOptionCommand('environment', 'prod') ); } @@ -350,7 +350,7 @@ public function testVerboseOption() ]; foreach ($levels as $level) { $this->assertEquals( - 'drupal command --verbose '.$level, + 'drupal command --verbose='.$level, $this->getTestOptionCommand('verbose', $level) ); } @@ -362,7 +362,7 @@ public function testVerboseOption() public function testSiteNameOption() { $this->assertEquals( - 'drupal command --site-name Digipolis', + 'drupal command --site-name=Digipolis', $this->getTestOptionCommand('siteName', 'Digipolis') ); } @@ -373,7 +373,7 @@ public function testSiteNameOption() public function testSiteMailOption() { $this->assertEquals( - 'drupal command --site-mail digipolis@example.com', + 'drupal command --site-mail=digipolis@example.com', $this->getTestOptionCommand('siteMail', 'digipolis@example.com') ); } @@ -384,7 +384,7 @@ public function testSiteMailOption() public function testFileOption() { $this->assertEquals( - 'drupal command --file '.static::escape(__FILE__), + 'drupal command --file='.static::escape(__FILE__), $this->getTestOptionCommand('file', __FILE__) ); } @@ -395,7 +395,7 @@ public function testFileOption() public function testDirectoryOption() { $this->assertEquals( - 'drupal command --directory '.static::escape(__DIR__), + 'drupal command --directory='.static::escape(__DIR__), $this->getTestOptionCommand('directory', __DIR__) ); } @@ -417,7 +417,7 @@ public function testTarOption() public function testLangcodeOption() { $this->assertEquals( - 'drupal command --langcode nl', + 'drupal command --langcode=nl', $this->getTestOptionCommand('langcode', 'nl') ); } @@ -428,7 +428,7 @@ public function testLangcodeOption() public function testDbTypeOption() { $this->assertEquals( - 'drupal command --db-type mysql', + 'drupal command --db-type=mysql', $this->getTestOptionCommand('dbType', 'mysql') ); } @@ -439,7 +439,7 @@ public function testDbTypeOption() public function testDbFileOption() { $this->assertEquals( - 'drupal command --db-file .h.sqlite', + 'drupal command --db-file=.h.sqlite', $this->getTestOptionCommand('dbFile', '.h.sqlite') ); } @@ -450,7 +450,7 @@ public function testDbFileOption() public function testDbHostOption() { $this->assertEquals( - 'drupal command --db-host localhost', + 'drupal command --db-host=localhost', $this->getTestOptionCommand('dbHost', 'localhost') ); } @@ -461,7 +461,7 @@ public function testDbHostOption() public function testDbNameOption() { $this->assertEquals( - 'drupal command --db-name db_digipolis', + 'drupal command --db-name=db_digipolis', $this->getTestOptionCommand('dbName', 'db_digipolis') ); } @@ -472,7 +472,7 @@ public function testDbNameOption() public function testDbUserOption() { $this->assertEquals( - 'drupal command --db-user db_user', + 'drupal command --db-user=db_user', $this->getTestOptionCommand('dbUser', 'db_user') ); } @@ -483,7 +483,7 @@ public function testDbUserOption() public function testDbPassOption() { $this->assertEquals( - 'drupal command --db-pass db_pass', + 'drupal command --db-pass=db_pass', $this->getTestOptionCommand('dbPass', 'db_pass') ); } @@ -494,7 +494,7 @@ public function testDbPassOption() public function testDbPrefixOption() { $this->assertEquals( - 'drupal command --db-prefix prefix_', + 'drupal command --db-prefix=prefix_', $this->getTestOptionCommand('dbPrefix', 'prefix_') ); } @@ -505,7 +505,7 @@ public function testDbPrefixOption() public function testDbPortOption() { $this->assertEquals( - 'drupal command --db-port 1234', + 'drupal command --db-port=1234', $this->getTestOptionCommand('dbPort', '1234') ); } @@ -516,7 +516,7 @@ public function testDbPortOption() public function testAccountMailOption() { $this->assertEquals( - 'drupal command --account-mail account@example.com', + 'drupal command --account-mail=account@example.com', $this->getTestOptionCommand('accountMail', 'account@example.com') ); $this->getTestOptionCommand( @@ -532,7 +532,7 @@ public function testAccountMailOption() public function testAccountNameOption() { $this->assertEquals( - 'drupal command --account-name accountName', + 'drupal command --account-name=accountName', $this->getTestOptionCommand('accountName', 'accountName') ); $this->getTestOptionCommand( @@ -548,7 +548,7 @@ public function testAccountNameOption() public function testAccountPassOption() { $this->assertEquals( - 'drupal command --account-pass MyPwD123_', + 'drupal command --account-pass=MyPwD123_', $this->getTestOptionCommand('accountPass', 'MyPwD123_') ); $this->getTestOptionCommand('accountPass', 'account-pass', 'MyPwD123_'); From eef7af92c4a394d184e48a825a10d3174f9312fa Mon Sep 17 00:00:00 2001 From: Jelle Sebreghts Date: Mon, 30 Jan 2017 10:04:39 +0100 Subject: [PATCH 2/3] Code style fixes. --- src/DrupalConsoleStack.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DrupalConsoleStack.php b/src/DrupalConsoleStack.php index 12176b5..a2c50ad 100644 --- a/src/DrupalConsoleStack.php +++ b/src/DrupalConsoleStack.php @@ -104,11 +104,11 @@ public function __construct($pathToDrupalConsole = 'drupal') */ public function option($option, $value = null) { - if ($option !== null and strpos($option, '-') !== 0) { + if (!is_null($option) && strpos($option, '-') !== 0) { $option = "--$option"; } - $this->arguments .= null == $option ? '' : " " . $option; - $this->arguments .= null == $value ? '' : "=" . static::escape($value); + $this->arguments .= is_null($option) ? '' : " " . $option; + $this->arguments .= is_null($value) ? '' : "=" . static::escape($value); return $this; } From 50b26fcfe09d84807e78d873b64903f8eeb12ba8 Mon Sep 17 00:00:00 2001 From: Jelle Sebreghts Date: Mon, 30 Jan 2017 10:04:39 +0100 Subject: [PATCH 3/3] Fixes #6 --- src/DrupalConsoleStack.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DrupalConsoleStack.php b/src/DrupalConsoleStack.php index 12176b5..a2c50ad 100644 --- a/src/DrupalConsoleStack.php +++ b/src/DrupalConsoleStack.php @@ -104,11 +104,11 @@ public function __construct($pathToDrupalConsole = 'drupal') */ public function option($option, $value = null) { - if ($option !== null and strpos($option, '-') !== 0) { + if (!is_null($option) && strpos($option, '-') !== 0) { $option = "--$option"; } - $this->arguments .= null == $option ? '' : " " . $option; - $this->arguments .= null == $value ? '' : "=" . static::escape($value); + $this->arguments .= is_null($option) ? '' : " " . $option; + $this->arguments .= is_null($value) ? '' : "=" . static::escape($value); return $this; }