From 6b207eb4806708da435d7f605043fb9ad59fa674 Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Sat, 17 Jan 2015 23:29:12 +0100 Subject: [PATCH 01/33] Obtain environment variables --- Mage/Task/AbstractTask.php | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/Mage/Task/AbstractTask.php b/Mage/Task/AbstractTask.php index 491adfb..3637148 100644 --- a/Mage/Task/AbstractTask.php +++ b/Mage/Task/AbstractTask.php @@ -307,4 +307,53 @@ abstract class AbstractTask } return $result; } + + /** + * Returns the array of environment variables + * Returned array contains both system variables and variables set in config + * WARNING: To access system's variables you need to set proper value in your php.ini at variables_order key + * @see http://php.net/manual/en/ini.core.php#ini.variables-order + * + * @return array + */ + protected function getEnvVariables() + { + $configVars = array_merge( + $this->getConfig()->general('env', []), + $this->getConfig()->environmentConfig('env', []), + $this->getConfig()->getParameter('env', []) + ); + + if (isset($configVars['variables'])) { + $configVars = $configVars['variables']; + } + + $envVariables = array_merge( + $_ENV, + $configVars + ); + + return $envVariables; + } + + /** + * Returns ready to inject environment string + * The string is build from env vars array in schema: + * key1=value1 key2=value3 ... + * + * @return string + */ + protected function getEnvVarsString() + { + $envVarsArray = $this->getEnvVariables(); + $envVars = array_map( + function ($key, $value) { + return "$key=$value"; + }, + array_keys($envVarsArray), + $this->getEnvVariables() + ); + + return join(' ', $envVars); + } } From e4ba19679a456d8861d079d44e3d061127404cca Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Sat, 17 Jan 2015 23:34:47 +0100 Subject: [PATCH 02/33] Prepend environment variables to command --- Mage/Task/AbstractTask.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Mage/Task/AbstractTask.php b/Mage/Task/AbstractTask.php index 3637148..14bf390 100644 --- a/Mage/Task/AbstractTask.php +++ b/Mage/Task/AbstractTask.php @@ -224,6 +224,7 @@ abstract class AbstractTask */ protected final function runCommand($command, &$output = null) { + $command = ltrim($this->getEnvVarsString() . ' ' . $command); if ($this->getStage() == self::STAGE_DEPLOY || $this->getStage() == self::STAGE_POST_RELEASE) { return $this->runCommandRemote($command, $output); } else { From d7db7cb66d0a7c1b469ccc63045131130c6aa27a Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Sun, 18 Jan 2015 14:17:26 +0100 Subject: [PATCH 03/33] Add some usage examples --- docs/example-config/.mage/config/environment/production.yml | 3 +++ docs/example-config/.mage/config/general.yml | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/docs/example-config/.mage/config/environment/production.yml b/docs/example-config/.mage/config/environment/production.yml index 97a3fcc..1af997f 100644 --- a/docs/example-config/.mage/config/environment/production.yml +++ b/docs/example-config/.mage/config/environment/production.yml @@ -22,3 +22,6 @@ tasks: - sampleTask - sampleTaskRollbackAware verbose_logging: true +env: + variables: + symfony_env: prod diff --git a/docs/example-config/.mage/config/general.yml b/docs/example-config/.mage/config/general.yml index c3a9b6d..3accc0e 100644 --- a/docs/example-config/.mage/config/general.yml +++ b/docs/example-config/.mage/config/general.yml @@ -7,3 +7,7 @@ verbose_logging: false scm: type: git url: git://github.com/andres-montanez/Zend-Framework-Twig-example-app.git +env: + variables: + node_path: "/bin/node" + symfony_env: prod From acd1891c66c3fd7f9eb518ae350e8e500bf12276 Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Sun, 18 Jan 2015 20:10:26 +0100 Subject: [PATCH 04/33] Add shorten version for env.variables in task config --- Mage/Task/AbstractTask.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Mage/Task/AbstractTask.php b/Mage/Task/AbstractTask.php index 14bf390..1ac923e 100644 --- a/Mage/Task/AbstractTask.php +++ b/Mage/Task/AbstractTask.php @@ -322,7 +322,10 @@ abstract class AbstractTask $configVars = array_merge( $this->getConfig()->general('env', []), $this->getConfig()->environmentConfig('env', []), - $this->getConfig()->getParameter('env', []) + $this->getConfig()->getParameter('env', []), + [ + 'variables' => $this->getConfig()->getParameter('env.variables', []) + ] ); if (isset($configVars['variables'])) { From 5e5d85980a23a4eef551b9221060c5d2858f7541 Mon Sep 17 00:00:00 2001 From: Markus Malkusch Date: Tue, 14 Apr 2015 22:07:27 +0200 Subject: [PATCH 05/33] malkusch/php-mock moved to php-mock/php-mock --- composer.json | 2 +- composer.lock | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index a8b9d75..a040276 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "require-dev": { "phpunit/phpunit": "4.3.5", "satooshi/php-coveralls": ">=0.6.1", - "malkusch/php-mock": "dev-php-5.3" + "php-mock/php-mock": "^0.1" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 7d89680..f3ff639 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "caa09089c7b57461ed42e97a4449f2c6", + "hash": "38a662749dc90d3cd6bb06c095ec14f1", "packages": [], "packages-dev": [ { @@ -154,17 +154,17 @@ "time": "2014-08-11 04:32:36" }, { - "name": "malkusch/php-mock", - "version": "dev-php-5.3", + "name": "php-mock/php-mock", + "version": "0.1.1", "source": { "type": "git", - "url": "https://github.com/malkusch/php-mock.git", - "reference": "37b301b4b479601232f3919920451c6e777c3264" + "url": "https://github.com/php-mock/php-mock.git", + "reference": "b48b05bfd43d8b051103a4515ab5613cb90e71da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/malkusch/php-mock/zipball/37b301b4b479601232f3919920451c6e777c3264", - "reference": "37b301b4b479601232f3919920451c6e777c3264", + "url": "https://api.github.com/repos/php-mock/php-mock/zipball/b48b05bfd43d8b051103a4515ab5613cb90e71da", + "reference": "b48b05bfd43d8b051103a4515ab5613cb90e71da", "shasum": "" }, "require": { @@ -199,7 +199,7 @@ "stub", "test" ], - "time": "2014-12-01 18:01:18" + "time": "2015-04-14 18:12:12" }, { "name": "phpunit/php-code-coverage", @@ -1256,9 +1256,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "malkusch/php-mock": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { From 6f1bd5c0cc30f40e9128fad5283090e6a2ebe879 Mon Sep 17 00:00:00 2001 From: Kirill Date: Wed, 29 Apr 2015 17:11:18 -0700 Subject: [PATCH 06/33] resultFetch is always false when owner is specified in config --- Mage/Task/BuiltIn/Deployment/ReleaseTask.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php index 93df8cf..266205f 100644 --- a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php +++ b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php @@ -74,7 +74,7 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride } } - if ($resultFetch && $userGroup != '') { + if ($userGroup != '') { $command = 'chown -R ' . $userGroup . ' ' . $currentCopy . ' && ' . 'chown ' . $userGroup . ' ' . $releasesDirectory; From a3219e8f683799342b3457636d10f5a88bbd15cb Mon Sep 17 00:00:00 2001 From: Kirill Date: Thu, 30 Apr 2015 15:58:43 -0700 Subject: [PATCH 07/33] Default userGroup to 33:33. Removing extra condition. --- Mage/Task/BuiltIn/Deployment/ReleaseTask.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php index 266205f..d635c2d 100644 --- a/Mage/Task/BuiltIn/Deployment/ReleaseTask.php +++ b/Mage/Task/BuiltIn/Deployment/ReleaseTask.php @@ -70,18 +70,16 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride if (!empty($infoArray[3])) { $group = $infoArray[3]; } - $userGroup = $user . ':' . $group; } + $userGroup = $user . ':' . $group; } - if ($userGroup != '') { - $command = 'chown -R ' . $userGroup . ' ' . $currentCopy - . ' && ' - . 'chown ' . $userGroup . ' ' . $releasesDirectory; - $result = $this->runCommandRemote($command); - if (!$result) { - return $result; - } + $command = 'chown -R ' . $userGroup . ' ' . $currentCopy + . ' && ' + . 'chown ' . $userGroup . ' ' . $releasesDirectory; + $result = $this->runCommandRemote($command); + if (!$result) { + return $result; } // Switch symlink and change owner From 4c519dd3bce62d072ae0e64c657967f5629e1553 Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Sat, 7 Mar 2015 23:08:52 +0100 Subject: [PATCH 08/33] Add command help option --- Mage/Command/AbstractCommand.php | 65 +++++++ .../MageTest/Command/AbstractCommandTest.php | 171 ++++++++++++++++++ 2 files changed, 236 insertions(+) diff --git a/Mage/Command/AbstractCommand.php b/Mage/Command/AbstractCommand.php index f69b0ef..bc020dc 100644 --- a/Mage/Command/AbstractCommand.php +++ b/Mage/Command/AbstractCommand.php @@ -26,6 +26,10 @@ abstract class AbstractCommand */ protected $config = null; + private $helpMessage; + private $usageExamples = []; + private $syntaxMessage; + /** * Runs the Command * @return integer exit code @@ -52,4 +56,65 @@ abstract class AbstractCommand { return $this->config; } + + public function setHelpMessage($message) + { + $this->helpMessage = $message; + + return $this; + } + + public function addUsageExample($snippet, $description = '') + { + array_push($this->usageExamples, [$snippet, $description]); + + return $this; + } + + public function setSyntaxMessage($message) + { + $this->syntaxMessage = $message; + + return $this; + } + + public function getInfoMessage() + { + $indent = str_repeat(" ", 4); + + $output = ""; + + if (!empty($this->helpMessage)) { + $output .= "\n"; + $output .= $this->helpMessage . "\n"; + } + + if (!empty($this->syntaxMessage)) { + $output .= "\n"; + $output .= "Syntax:\n"; + $output .= $indent; + $output .= $this->syntaxMessage; + $output .= "\n"; + } + + if (!empty($this->usageExamples)) { + $output .= "\n"; + $output .= "Usage examples:\n"; + foreach ($this->usageExamples as $example) { + $snippet = $example[0]; + $description = $example[1]; + $output .= "$indent* "; + if (!empty($description)) { + $description = rtrim($description, ': ') . ":"; + $output .= $description; + $output .= "\n$indent$indent"; + } + + $output .= $snippet; + $output .= "\n"; + } + } + + return $output; + } } diff --git a/tests/MageTest/Command/AbstractCommandTest.php b/tests/MageTest/Command/AbstractCommandTest.php index fed7df5..22a73f6 100644 --- a/tests/MageTest/Command/AbstractCommandTest.php +++ b/tests/MageTest/Command/AbstractCommandTest.php @@ -44,4 +44,175 @@ class AbstractCommandTest extends BaseTest $configMock = $this->getMock('Mage\Config'); $this->doTestGetter($this->abstractCommand, 'config', $configMock); } + + public function infoMessageProvider() + { + return [ + 'happy_path' => [ + 'helpMessage' => 'This command does everything you want to', + 'examples' => [ + [ + 'snippet' => 'mage example', + 'description' => 'Default command' + ], + [ + 'snippet' => 'mage example light', + 'description' => 'Runs the command with lights' + ] + ], + 'syntax' => 'mage example [light]', + 'output' => "\n" + . "This command does everything you want to\n" + . "\n" + . "Syntax:\n" + . " mage example [light]\n" + . "\n" + . "Usage examples:\n" + . " * Default command:\n" + . " mage example\n" + . " * Runs the command with lights:\n" + . " mage example light\n" + ], + 'no_help_message' => [ + 'helpMessage' => '', + 'examples' => [ + [ + 'snippet' => 'mage example', + 'description' => 'Default command' + ], + [ + 'snippet' => 'mage example light', + 'description' => 'Runs the command with lights' + ] + ], + 'syntax' => 'mage example [light]', + 'output' => "\n" + . "Syntax:\n" + . " mage example [light]\n" + . "\n" + . "Usage examples:\n" + . " * Default command:\n" + . " mage example\n" + . " * Runs the command with lights:\n" + . " mage example light\n" + ], + 'no_examples' => [ + 'helpMessage' => 'This command does everything you want to', + 'examples' => [], + 'syntax' => 'mage example [light]', + 'output' => "\n" + . "This command does everything you want to\n" + . "\n" + . "Syntax:\n" + . " mage example [light]\n" + ], + "no_syntax" => [ + 'helpMessage' => 'This command does everything you want to', + 'examples' => [ + [ + 'snippet' => 'mage example', + 'description' => 'Default command' + ], + [ + 'snippet' => 'mage example light', + 'description' => 'Runs the command with lights' + ] + ], + 'syntax' => '', + 'output' => "\n" + . "This command does everything you want to\n" + . "\n" + . "Usage examples:\n" + . " * Default command:\n" + . " mage example\n" + . " * Runs the command with lights:\n" + . " mage example light\n" + ], + "stripping_colons" => [ + 'helpMessage' => 'This command does everything you want to', + 'examples' => [ + [ + 'snippet' => 'mage example', + 'description' => 'Default command:' + ], + [ + 'snippet' => 'mage example light', + 'description' => 'Runs the command with lights:' + ] + ], + 'syntax' => 'mage example [light]', + 'output' => "\n" + . "This command does everything you want to\n" + . "\n" + . "Syntax:\n" + . " mage example [light]\n" + . "\n" + . "Usage examples:\n" + . " * Default command:\n" + . " mage example\n" + . " * Runs the command with lights:\n" + . " mage example light\n" + ], + "only_help" => [ + 'helpMessage' => 'This command does everything you want to', + 'examples' => [], + 'syntax' => '', + 'output' => "\n" + . "This command does everything you want to\n" + ], + "only_examples" => [ + 'helpMessage' => '', + 'examples' => [ + [ + 'snippet' => 'mage example', + 'description' => 'Default command' + ], + [ + 'snippet' => 'mage example light', + 'description' => 'Runs the command with lights' + ] + ], + 'syntax' => '', + 'output' => "\n" + . "Usage examples:\n" + . " * Default command:\n" + . " mage example\n" + . " * Runs the command with lights:\n" + . " mage example light\n" + ], + "only_syntax" => [ + 'helpMessage' => '', + 'examples' => [], + 'syntax' => 'mage example [light]', + 'output' => "\n" + . "Syntax:\n" + . " mage example [light]\n" + ] + ]; + } + + /** + * @covers ::getInfoMessage + * @covers ::setHelpMessage + * @covers ::addUsageExample + * @covers ::setSyntaxMessage + * + * @dataProvider infoMessageProvider + */ + public function testGetInfoMessage($helpMessage, $examples, $syntax, $expectedMessage) + { + /** @var AbstractCommand $command */ + $command = $this->getMockForAbstractClass('Mage\Command\AbstractCommand'); + + foreach ($examples as $example) { + $command->addUsageExample($example['snippet'], $example['description']); + } + + $command->setHelpMessage($helpMessage); + $command->setSyntaxMessage($syntax); + + $actualMessage = $command->getInfoMessage(); + $this->assertEquals($expectedMessage, $actualMessage); + + } } From 94d301f66fdb4f9c2c1834afc9e7bafae61891da Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Sat, 7 Mar 2015 23:36:31 +0100 Subject: [PATCH 09/33] Add console colours to command info output --- Mage/Command/AbstractCommand.php | 11 ++-- .../MageTest/Command/AbstractCommandTest.php | 60 +++++++++---------- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/Mage/Command/AbstractCommand.php b/Mage/Command/AbstractCommand.php index bc020dc..403b7db 100644 --- a/Mage/Command/AbstractCommand.php +++ b/Mage/Command/AbstractCommand.php @@ -86,20 +86,19 @@ abstract class AbstractCommand if (!empty($this->helpMessage)) { $output .= "\n"; - $output .= $this->helpMessage . "\n"; + $output .= "{$this->helpMessage}\n"; } if (!empty($this->syntaxMessage)) { $output .= "\n"; - $output .= "Syntax:\n"; - $output .= $indent; - $output .= $this->syntaxMessage; + $output .= "Syntax:\n"; + $output .= "$indent{$this->syntaxMessage}"; $output .= "\n"; } if (!empty($this->usageExamples)) { $output .= "\n"; - $output .= "Usage examples:\n"; + $output .= "Usage examples:\n"; foreach ($this->usageExamples as $example) { $snippet = $example[0]; $description = $example[1]; @@ -110,7 +109,7 @@ abstract class AbstractCommand $output .= "\n$indent$indent"; } - $output .= $snippet; + $output .= "$snippet"; $output .= "\n"; } } diff --git a/tests/MageTest/Command/AbstractCommandTest.php b/tests/MageTest/Command/AbstractCommandTest.php index 22a73f6..ebf5af7 100644 --- a/tests/MageTest/Command/AbstractCommandTest.php +++ b/tests/MageTest/Command/AbstractCommandTest.php @@ -62,16 +62,16 @@ class AbstractCommandTest extends BaseTest ], 'syntax' => 'mage example [light]', 'output' => "\n" - . "This command does everything you want to\n" + . "This command does everything you want to\n" . "\n" - . "Syntax:\n" - . " mage example [light]\n" + . "Syntax:\n" + . " mage example [light]\n" . "\n" - . "Usage examples:\n" + . "Usage examples:\n" . " * Default command:\n" - . " mage example\n" + . " mage example\n" . " * Runs the command with lights:\n" - . " mage example light\n" + . " mage example light\n" ], 'no_help_message' => [ 'helpMessage' => '', @@ -87,24 +87,24 @@ class AbstractCommandTest extends BaseTest ], 'syntax' => 'mage example [light]', 'output' => "\n" - . "Syntax:\n" - . " mage example [light]\n" + . "Syntax:\n" + . " mage example [light]\n" . "\n" - . "Usage examples:\n" + . "Usage examples:\n" . " * Default command:\n" - . " mage example\n" + . " mage example\n" . " * Runs the command with lights:\n" - . " mage example light\n" + . " mage example light\n" ], 'no_examples' => [ 'helpMessage' => 'This command does everything you want to', 'examples' => [], 'syntax' => 'mage example [light]', 'output' => "\n" - . "This command does everything you want to\n" + . "This command does everything you want to\n" . "\n" - . "Syntax:\n" - . " mage example [light]\n" + . "Syntax:\n" + . " mage example [light]\n" ], "no_syntax" => [ 'helpMessage' => 'This command does everything you want to', @@ -120,13 +120,13 @@ class AbstractCommandTest extends BaseTest ], 'syntax' => '', 'output' => "\n" - . "This command does everything you want to\n" + . "This command does everything you want to\n" . "\n" - . "Usage examples:\n" + . "Usage examples:\n" . " * Default command:\n" - . " mage example\n" + . " mage example\n" . " * Runs the command with lights:\n" - . " mage example light\n" + . " mage example light\n" ], "stripping_colons" => [ 'helpMessage' => 'This command does everything you want to', @@ -142,23 +142,23 @@ class AbstractCommandTest extends BaseTest ], 'syntax' => 'mage example [light]', 'output' => "\n" - . "This command does everything you want to\n" + . "This command does everything you want to\n" . "\n" - . "Syntax:\n" - . " mage example [light]\n" + . "Syntax:\n" + . " mage example [light]\n" . "\n" - . "Usage examples:\n" + . "Usage examples:\n" . " * Default command:\n" - . " mage example\n" + . " mage example\n" . " * Runs the command with lights:\n" - . " mage example light\n" + . " mage example light\n" ], "only_help" => [ 'helpMessage' => 'This command does everything you want to', 'examples' => [], 'syntax' => '', 'output' => "\n" - . "This command does everything you want to\n" + . "This command does everything you want to\n" ], "only_examples" => [ 'helpMessage' => '', @@ -174,19 +174,19 @@ class AbstractCommandTest extends BaseTest ], 'syntax' => '', 'output' => "\n" - . "Usage examples:\n" + . "Usage examples:\n" . " * Default command:\n" - . " mage example\n" + . " mage example\n" . " * Runs the command with lights:\n" - . " mage example light\n" + . " mage example light\n" ], "only_syntax" => [ 'helpMessage' => '', 'examples' => [], 'syntax' => 'mage example [light]', 'output' => "\n" - . "Syntax:\n" - . " mage example [light]\n" + . "Syntax:\n" + . " mage example [light]\n" ] ]; } From 4e18ae1f8c40f736b9e568be7f2592e87109ead5 Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Sun, 8 Mar 2015 12:23:42 +0100 Subject: [PATCH 10/33] Add command name as an option --- Mage/Command/AbstractCommand.php | 15 ++++- .../MageTest/Command/AbstractCommandTest.php | 60 ++++++++++++++++--- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/Mage/Command/AbstractCommand.php b/Mage/Command/AbstractCommand.php index 403b7db..800dd09 100644 --- a/Mage/Command/AbstractCommand.php +++ b/Mage/Command/AbstractCommand.php @@ -29,6 +29,7 @@ abstract class AbstractCommand private $helpMessage; private $usageExamples = []; private $syntaxMessage; + private $name; /** * Runs the Command @@ -57,6 +58,13 @@ abstract class AbstractCommand return $this->config; } + public function setName($name) + { + $this->name = $name; + + return $this; + } + public function setHelpMessage($message) { $this->helpMessage = $message; @@ -83,10 +91,15 @@ abstract class AbstractCommand $indent = str_repeat(" ", 4); $output = ""; + if (!empty($this->name)) { + $output .= "\n"; + $output .= "Command: "; + $output .= $this->name; + } if (!empty($this->helpMessage)) { $output .= "\n"; - $output .= "{$this->helpMessage}\n"; + $output .= "{$this->helpMessage}\n"; } if (!empty($this->syntaxMessage)) { diff --git a/tests/MageTest/Command/AbstractCommandTest.php b/tests/MageTest/Command/AbstractCommandTest.php index ebf5af7..877dfae 100644 --- a/tests/MageTest/Command/AbstractCommandTest.php +++ b/tests/MageTest/Command/AbstractCommandTest.php @@ -49,6 +49,7 @@ class AbstractCommandTest extends BaseTest { return [ 'happy_path' => [ + 'name' => 'Example command', 'helpMessage' => 'This command does everything you want to', 'examples' => [ [ @@ -62,7 +63,8 @@ class AbstractCommandTest extends BaseTest ], 'syntax' => 'mage example [light]', 'output' => "\n" - . "This command does everything you want to\n" + . "Command: Example command\n" + . "This command does everything you want to\n" . "\n" . "Syntax:\n" . " mage example [light]\n" @@ -74,6 +76,7 @@ class AbstractCommandTest extends BaseTest . " mage example light\n" ], 'no_help_message' => [ + 'name' => 'Example command', 'helpMessage' => '', 'examples' => [ [ @@ -87,6 +90,7 @@ class AbstractCommandTest extends BaseTest ], 'syntax' => 'mage example [light]', 'output' => "\n" + . "Command: Example command\n" . "Syntax:\n" . " mage example [light]\n" . "\n" @@ -97,16 +101,19 @@ class AbstractCommandTest extends BaseTest . " mage example light\n" ], 'no_examples' => [ + 'name' => 'Example command', 'helpMessage' => 'This command does everything you want to', 'examples' => [], 'syntax' => 'mage example [light]', 'output' => "\n" - . "This command does everything you want to\n" + . "Command: Example command\n" + . "This command does everything you want to\n" . "\n" . "Syntax:\n" . " mage example [light]\n" ], "no_syntax" => [ + 'name' => 'Example command', 'helpMessage' => 'This command does everything you want to', 'examples' => [ [ @@ -120,7 +127,8 @@ class AbstractCommandTest extends BaseTest ], 'syntax' => '', 'output' => "\n" - . "This command does everything you want to\n" + . "Command: Example command\n" + . "This command does everything you want to\n" . "\n" . "Usage examples:\n" . " * Default command:\n" @@ -129,20 +137,22 @@ class AbstractCommandTest extends BaseTest . " mage example light\n" ], "stripping_colons" => [ + 'name' => 'Example command', 'helpMessage' => 'This command does everything you want to', 'examples' => [ [ 'snippet' => 'mage example', - 'description' => 'Default command:' + 'description' => 'Default command : ' ], [ 'snippet' => 'mage example light', - 'description' => 'Runs the command with lights:' + 'description' => 'Runs the command with lights: ' ] ], 'syntax' => 'mage example [light]', 'output' => "\n" - . "This command does everything you want to\n" + . "Command: Example command\n" + . "This command does everything you want to\n" . "\n" . "Syntax:\n" . " mage example [light]\n" @@ -154,13 +164,16 @@ class AbstractCommandTest extends BaseTest . " mage example light\n" ], "only_help" => [ + 'name' => 'Example command', 'helpMessage' => 'This command does everything you want to', 'examples' => [], 'syntax' => '', 'output' => "\n" - . "This command does everything you want to\n" + . "Command: Example command\n" + . "This command does everything you want to\n" ], "only_examples" => [ + 'name' => 'Example command', 'helpMessage' => '', 'examples' => [ [ @@ -174,6 +187,7 @@ class AbstractCommandTest extends BaseTest ], 'syntax' => '', 'output' => "\n" + . "Command: Example command\n" . "Usage examples:\n" . " * Default command:\n" . " mage example\n" @@ -181,12 +195,40 @@ class AbstractCommandTest extends BaseTest . " mage example light\n" ], "only_syntax" => [ + 'name' => 'Example command', 'helpMessage' => '', 'examples' => [], 'syntax' => 'mage example [light]', 'output' => "\n" + . "Command: Example command\n" . "Syntax:\n" . " mage example [light]\n" + ], + "no_name" => [ + 'name' => '', + 'helpMessage' => 'This command does everything you want to', + 'examples' => [ + [ + 'snippet' => 'mage example', + 'description' => 'Default command' + ], + [ + 'snippet' => 'mage example light', + 'description' => 'Runs the command with lights' + ] + ], + 'syntax' => 'mage example [light]', + 'output' => "\n" + . "This command does everything you want to\n" + . "\n" + . "Syntax:\n" + . " mage example [light]\n" + . "\n" + . "Usage examples:\n" + . " * Default command:\n" + . " mage example\n" + . " * Runs the command with lights:\n" + . " mage example light\n" ] ]; } @@ -199,11 +241,13 @@ class AbstractCommandTest extends BaseTest * * @dataProvider infoMessageProvider */ - public function testGetInfoMessage($helpMessage, $examples, $syntax, $expectedMessage) + public function testGetInfoMessage($name, $helpMessage, $examples, $syntax, $expectedMessage) { /** @var AbstractCommand $command */ $command = $this->getMockForAbstractClass('Mage\Command\AbstractCommand'); + $command->setName($name); + foreach ($examples as $example) { $command->addUsageExample($example['snippet'], $example['description']); } From 08a93389c47df121a8258746dd14b677d158bdd5 Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Sun, 8 Mar 2015 12:24:21 +0100 Subject: [PATCH 11/33] Convert arrays to traditional syntax --- .../MageTest/Command/AbstractCommandTest.php | 118 +++++++++--------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/tests/MageTest/Command/AbstractCommandTest.php b/tests/MageTest/Command/AbstractCommandTest.php index 877dfae..b903f7c 100644 --- a/tests/MageTest/Command/AbstractCommandTest.php +++ b/tests/MageTest/Command/AbstractCommandTest.php @@ -47,20 +47,20 @@ class AbstractCommandTest extends BaseTest public function infoMessageProvider() { - return [ - 'happy_path' => [ + return array( + 'happy_path' => array( 'name' => 'Example command', 'helpMessage' => 'This command does everything you want to', - 'examples' => [ - [ + 'examples' => array( + array( 'snippet' => 'mage example', 'description' => 'Default command' - ], - [ + ), + array( 'snippet' => 'mage example light', 'description' => 'Runs the command with lights' - ] - ], + ) + ), 'syntax' => 'mage example [light]', 'output' => "\n" . "Command: Example command\n" @@ -74,20 +74,20 @@ class AbstractCommandTest extends BaseTest . " mage example\n" . " * Runs the command with lights:\n" . " mage example light\n" - ], - 'no_help_message' => [ + ), + 'no_help_message' => array( 'name' => 'Example command', 'helpMessage' => '', - 'examples' => [ - [ + 'examples' => array( + array( 'snippet' => 'mage example', 'description' => 'Default command' - ], - [ + ), + array( 'snippet' => 'mage example light', 'description' => 'Runs the command with lights' - ] - ], + ) + ), 'syntax' => 'mage example [light]', 'output' => "\n" . "Command: Example command\n" @@ -99,11 +99,11 @@ class AbstractCommandTest extends BaseTest . " mage example\n" . " * Runs the command with lights:\n" . " mage example light\n" - ], - 'no_examples' => [ + ), + 'no_examples' => array( 'name' => 'Example command', 'helpMessage' => 'This command does everything you want to', - 'examples' => [], + 'examples' => array(), 'syntax' => 'mage example [light]', 'output' => "\n" . "Command: Example command\n" @@ -111,20 +111,20 @@ class AbstractCommandTest extends BaseTest . "\n" . "Syntax:\n" . " mage example [light]\n" - ], - "no_syntax" => [ + ), + "no_syntax" => array( 'name' => 'Example command', 'helpMessage' => 'This command does everything you want to', - 'examples' => [ - [ + 'examples' => array( + array( 'snippet' => 'mage example', 'description' => 'Default command' - ], - [ + ), + array( 'snippet' => 'mage example light', 'description' => 'Runs the command with lights' - ] - ], + ) + ), 'syntax' => '', 'output' => "\n" . "Command: Example command\n" @@ -135,20 +135,20 @@ class AbstractCommandTest extends BaseTest . " mage example\n" . " * Runs the command with lights:\n" . " mage example light\n" - ], - "stripping_colons" => [ + ), + "stripping_colons" => array( 'name' => 'Example command', 'helpMessage' => 'This command does everything you want to', - 'examples' => [ - [ + 'examples' => array( + array( 'snippet' => 'mage example', 'description' => 'Default command : ' - ], - [ + ), + array( 'snippet' => 'mage example light', 'description' => 'Runs the command with lights: ' - ] - ], + ) + ), 'syntax' => 'mage example [light]', 'output' => "\n" . "Command: Example command\n" @@ -162,29 +162,29 @@ class AbstractCommandTest extends BaseTest . " mage example\n" . " * Runs the command with lights:\n" . " mage example light\n" - ], - "only_help" => [ + ), + "only_help" => array( 'name' => 'Example command', 'helpMessage' => 'This command does everything you want to', - 'examples' => [], + 'examples' => array(), 'syntax' => '', 'output' => "\n" . "Command: Example command\n" . "This command does everything you want to\n" - ], - "only_examples" => [ + ), + "only_examples" => array( 'name' => 'Example command', 'helpMessage' => '', - 'examples' => [ - [ + 'examples' => array( + array( 'snippet' => 'mage example', 'description' => 'Default command' - ], - [ + ), + array( 'snippet' => 'mage example light', 'description' => 'Runs the command with lights' - ] - ], + ) + ), 'syntax' => '', 'output' => "\n" . "Command: Example command\n" @@ -193,30 +193,30 @@ class AbstractCommandTest extends BaseTest . " mage example\n" . " * Runs the command with lights:\n" . " mage example light\n" - ], - "only_syntax" => [ + ), + "only_syntax" => array( 'name' => 'Example command', 'helpMessage' => '', - 'examples' => [], + 'examples' => array(), 'syntax' => 'mage example [light]', 'output' => "\n" . "Command: Example command\n" . "Syntax:\n" . " mage example [light]\n" - ], - "no_name" => [ + ), + "no_name" => array( 'name' => '', 'helpMessage' => 'This command does everything you want to', - 'examples' => [ - [ + 'examples' => array( + array( 'snippet' => 'mage example', 'description' => 'Default command' - ], - [ + ), + array( 'snippet' => 'mage example light', 'description' => 'Runs the command with lights' - ] - ], + ) + ), 'syntax' => 'mage example [light]', 'output' => "\n" . "This command does everything you want to\n" @@ -229,8 +229,8 @@ class AbstractCommandTest extends BaseTest . " mage example\n" . " * Runs the command with lights:\n" . " mage example light\n" - ] - ]; + ) + ); } /** From e4bab08d3f8098f889cc3ae45e7b34ae77480e99 Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Sun, 8 Mar 2015 12:28:22 +0100 Subject: [PATCH 12/33] Add some PHPDoc notes to AbstractCommand --- Mage/Command/AbstractCommand.php | 55 +++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/Mage/Command/AbstractCommand.php b/Mage/Command/AbstractCommand.php index 800dd09..8a0e561 100644 --- a/Mage/Command/AbstractCommand.php +++ b/Mage/Command/AbstractCommand.php @@ -26,9 +26,32 @@ abstract class AbstractCommand */ protected $config = null; + /** + * Command's help message + * + * @var string + */ private $helpMessage; - private $usageExamples = []; + + /** + * Usage examples. + * + * @var array + */ + private $usageExamples = array(); + + /** + * Command's syntax message + * + * @var string + */ private $syntaxMessage; + + /** + * Command name + * + * @var string + */ private $name; /** @@ -58,6 +81,12 @@ abstract class AbstractCommand return $this->config; } + /** + * Sets command name + * + * @param string $name Command name + * @return $this + */ public function setName($name) { $this->name = $name; @@ -65,6 +94,12 @@ abstract class AbstractCommand return $this; } + /** + * Sets command's help message + * + * @param string $message Command's help message + * @return $this + */ public function setHelpMessage($message) { $this->helpMessage = $message; @@ -72,6 +107,13 @@ abstract class AbstractCommand return $this; } + /** + * Adds command's usage example + * + * @param string $snippet Example's snippet + * @param string $description Example's description + * @return $this + */ public function addUsageExample($snippet, $description = '') { array_push($this->usageExamples, [$snippet, $description]); @@ -79,6 +121,12 @@ abstract class AbstractCommand return $this; } + /** + * Sets command's syntax message + * + * @param string $message Syntax message + * @return $this + */ public function setSyntaxMessage($message) { $this->syntaxMessage = $message; @@ -86,6 +134,11 @@ abstract class AbstractCommand return $this; } + /** + * Returns formatted command info + * + * @return string + */ public function getInfoMessage() { $indent = str_repeat(" ", 4); From 342a46821403b3b5bbe99f50e05a1acd8803ecca Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Sun, 8 Mar 2015 12:32:36 +0100 Subject: [PATCH 13/33] Add info about no help information for the command --- Mage/Command/AbstractCommand.php | 6 ++++++ tests/MageTest/Command/AbstractCommandTest.php | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/Mage/Command/AbstractCommand.php b/Mage/Command/AbstractCommand.php index 8a0e561..18d045a 100644 --- a/Mage/Command/AbstractCommand.php +++ b/Mage/Command/AbstractCommand.php @@ -180,6 +180,12 @@ abstract class AbstractCommand } } + if (empty($output)) { + $output .= "\n"; + $output .= "Sorry, there's no help for this command at the moment."; + $output .= "\n"; + } + return $output; } } diff --git a/tests/MageTest/Command/AbstractCommandTest.php b/tests/MageTest/Command/AbstractCommandTest.php index b903f7c..52b8278 100644 --- a/tests/MageTest/Command/AbstractCommandTest.php +++ b/tests/MageTest/Command/AbstractCommandTest.php @@ -229,6 +229,14 @@ class AbstractCommandTest extends BaseTest . " mage example\n" . " * Runs the command with lights:\n" . " mage example light\n" + ), + "no_info_at_all" => array( + 'name' => '', + 'helpMessage' => '', + 'examples' => array(), + 'syntax' => '', + 'output' => "\n" + . "Sorry, there's no help for this command at the moment.\n" ) ); } From fb236c1bb3d825bd767c295c8f6a1c0d1e65838f Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Sun, 8 Mar 2015 12:36:54 +0100 Subject: [PATCH 14/33] Enable running help command in Console --- Mage/Console.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Mage/Console.php b/Mage/Console.php index d9fcbb2..ef29492 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -13,6 +13,7 @@ namespace Mage; use Mage\Command\Factory; use Mage\Command\RequiresEnvironment; use Mage\Console\Colors; + use Exception; use RecursiveDirectoryIterator; use SplFileInfo; @@ -94,6 +95,7 @@ class Console try { // Load configuration $config->load($arguments); + } catch (Exception $exception) { $configError = $exception->getMessage(); } @@ -117,6 +119,7 @@ class Console if ($showGreetings) { if (!self::$logEnabled) { self::output('Starting Magallanes', 0, 2); + } else { self::output('Starting Magallanes', 0, 1); self::log("Logging enabled"); @@ -127,15 +130,20 @@ class Console // Run Command - Check if there is a Configuration Error if ($configError !== false) { self::output('' . $configError . '', 1, 2); + } else { // Run Command and check for Command Requirements try { $command = Factory::get($commandName, $config); - if ($command instanceof RequiresEnvironment) { - if ($config->getEnvironment() === false) { - throw new Exception('You must specify an environment for this command.'); - } + if ($config->getParameter('help')) { + self::output($command->getInfoMessage(), 2); + + return 0; + } + + if ($command instanceof RequiresEnvironment && $config->getEnvironment() === false) { + throw new Exception('You must specify an environment for this command.'); } // Run the Command @@ -306,4 +314,5 @@ class Console || self::$config->general('verbose_logging') || self::$config->environmentConfig('verbose_logging', false); } + } From 48fbefa61907cd1a722e7336d889356ab2eaaa0d Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Sun, 8 Mar 2015 12:39:34 +0100 Subject: [PATCH 15/33] Correct syntax for arrays --- Mage/Command/AbstractCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage/Command/AbstractCommand.php b/Mage/Command/AbstractCommand.php index 18d045a..0d45d5f 100644 --- a/Mage/Command/AbstractCommand.php +++ b/Mage/Command/AbstractCommand.php @@ -116,7 +116,7 @@ abstract class AbstractCommand */ public function addUsageExample($snippet, $description = '') { - array_push($this->usageExamples, [$snippet, $description]); + array_push($this->usageExamples, array($snippet, $description)); return $this; } From c49d36a91aa3c3074e69f78a1024298dbeccafd8 Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Sun, 8 Mar 2015 12:44:37 +0100 Subject: [PATCH 16/33] Fix coverage annotations --- tests/MageTest/Command/AbstractCommandTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/MageTest/Command/AbstractCommandTest.php b/tests/MageTest/Command/AbstractCommandTest.php index 52b8278..cd21930 100644 --- a/tests/MageTest/Command/AbstractCommandTest.php +++ b/tests/MageTest/Command/AbstractCommandTest.php @@ -246,6 +246,7 @@ class AbstractCommandTest extends BaseTest * @covers ::setHelpMessage * @covers ::addUsageExample * @covers ::setSyntaxMessage + * @covers ::setName * * @dataProvider infoMessageProvider */ From 5db9905ed49e90b762cb2d75286476e88bf9c5cc Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Sun, 8 Mar 2015 14:46:39 +0100 Subject: [PATCH 17/33] Add sample config for Magallanes' built-in commands --- Mage/Command/BuiltIn/AddCommand.php | 15 ++++++++++++ Mage/Command/BuiltIn/CompileCommand.php | 7 ++++++ Mage/Command/BuiltIn/DeployCommand.php | 16 +++++++++++++ Mage/Command/BuiltIn/InitCommand.php | 14 +++++++++++ Mage/Command/BuiltIn/InstallCommand.php | 18 ++++++++++++++ Mage/Command/BuiltIn/ListCommand.php | 11 +++++++++ Mage/Command/BuiltIn/LockCommand.php | 15 ++++++++++++ Mage/Command/BuiltIn/ReleasesCommand.php | 30 ++++++++++++++++++++++++ Mage/Command/BuiltIn/RollbackCommand.php | 18 ++++++++++++++ Mage/Command/BuiltIn/UnlockCommand.php | 11 +++++++++ Mage/Command/BuiltIn/UpdateCommand.php | 7 ++++++ Mage/Command/BuiltIn/UpgradeCommand.php | 7 ++++++ Mage/Command/BuiltIn/VersionCommand.php | 6 +++++ 13 files changed, 175 insertions(+) diff --git a/Mage/Command/BuiltIn/AddCommand.php b/Mage/Command/BuiltIn/AddCommand.php index 26d9a37..7932e5c 100644 --- a/Mage/Command/BuiltIn/AddCommand.php +++ b/Mage/Command/BuiltIn/AddCommand.php @@ -23,6 +23,21 @@ use Exception; */ class AddCommand extends AbstractCommand { + public function __construct() + { + $this->setName('Add command') + ->setHelpMessage('Generates new config for Magallanes. For now, only adding a environment is possible') + ->setSyntaxMessage('mage add [environment] [--name=env_name] [--enableReleases]') + ->addUsageExample( + 'mage add environment --name=production', + 'Add a production environment' + ) + ->addUsageExample( + 'mage add environment --name=qa --enableReleases', + 'Add a QA environment and enable releasing' + ); + } + /** * Adds new Configuration Elements * @see \Mage\Command\AbstractCommand::run() diff --git a/Mage/Command/BuiltIn/CompileCommand.php b/Mage/Command/BuiltIn/CompileCommand.php index ab92fd2..ae08ab9 100644 --- a/Mage/Command/BuiltIn/CompileCommand.php +++ b/Mage/Command/BuiltIn/CompileCommand.php @@ -21,6 +21,13 @@ use Mage\Compiler; */ class CompileCommand extends AbstractCommand { + public function __construct() + { + $this->setName('Compile command') + ->setHelpMessage('Compiles Magallanes to mage.phar file') + ->setSyntaxMessage('mage compile'); + } + /** * @var Compiler */ diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 9105792..014dea6 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -103,6 +103,22 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment */ protected static $failedTasks = 0; + public function __construct() + { + $this->setName('Deploy command') + ->setHelpMessage('Deploys the project into target environment') + ->setSyntaxMessage('mage deploy to:[environment_name]') + ->addUsageExample( + 'mage deploy to:production', + 'Deploy the project into production environment' + ) + ->addUsageExample( + 'mage deploy to:production --overrideRelease', + 'Deploy the project into production environment ' + . 'but skip SkipOnOverride aware tasks' + ); + } + /** * Returns the Status of the Deployment * diff --git a/Mage/Command/BuiltIn/InitCommand.php b/Mage/Command/BuiltIn/InitCommand.php index 326f0e9..a363583 100644 --- a/Mage/Command/BuiltIn/InitCommand.php +++ b/Mage/Command/BuiltIn/InitCommand.php @@ -20,6 +20,20 @@ use Mage\Console; */ class InitCommand extends AbstractCommand { + public function __construct() + { + $this->setName('Initialize command') + ->setHelpMessage('Initialize Magallanes project, create .mage directory with starter configs') + ->setSyntaxMessage('mage init --name=[project_name] [--email=[author_email]]') + ->addUsageExample( + 'mage init --name="My awesome project"', + 'Initialize "My awesome project" configuration' + ) + ->addUsageExample( + 'mage init --name="My project" --email="john.smith@example.com"', + 'Initialize "My project" configuration with email notification enabled for john.smith@example.com' + ); + } /** * Command for Initalize a new Configuration Proyect diff --git a/Mage/Command/BuiltIn/InstallCommand.php b/Mage/Command/BuiltIn/InstallCommand.php index 530e1d7..ffa1dbe 100644 --- a/Mage/Command/BuiltIn/InstallCommand.php +++ b/Mage/Command/BuiltIn/InstallCommand.php @@ -20,6 +20,24 @@ use Mage\Console; */ class InstallCommand extends AbstractCommand { + public function __construct() + { + $this->setName('Install command') + ->setHelpMessage( + 'Installs Magallanes system-widely.' + . ' By default, Magallanes\' going to be installed in /opt/magallanes' + ) + ->setSyntaxMessage('mage install [--installDir=[install_directory]] [--systemWide]') + ->addUsageExample( + 'mage install --installDir=/src/projects/Magellanes', + 'Install Magallanes at /src/projects/Magallanes directory' + ) + ->addUsageExample( + 'mage install --systemWide', + 'Install Magallanes at default directory and creates a symlink in /usr/bin/mage' + ); + } + /** * Installs Magallanes * @see \Mage\Command\AbstractCommand::run() diff --git a/Mage/Command/BuiltIn/ListCommand.php b/Mage/Command/BuiltIn/ListCommand.php index d7dd082..b0ff426 100644 --- a/Mage/Command/BuiltIn/ListCommand.php +++ b/Mage/Command/BuiltIn/ListCommand.php @@ -23,6 +23,17 @@ use Exception; */ class ListCommand extends AbstractCommand { + public function __construct() + { + $this->setName('List command') + ->setHelpMessage('List available configurations. For now, only environments listing available') + ->setSyntaxMessage('mage list [environments]') + ->addUsageExample( + 'mage list environments', + 'List currently configured environments' + ); + } + /** * Command for Listing Configuration Elements * @see \Mage\Command\AbstractCommand::run() diff --git a/Mage/Command/BuiltIn/LockCommand.php b/Mage/Command/BuiltIn/LockCommand.php index 09df123..9e00862 100644 --- a/Mage/Command/BuiltIn/LockCommand.php +++ b/Mage/Command/BuiltIn/LockCommand.php @@ -21,6 +21,21 @@ use Mage\Console; */ class LockCommand extends AbstractCommand implements RequiresEnvironment { + public function __construct() + { + $this->setName('Lock command') + ->setHelpMessage( + "Locks the deployment to given environment and creates a lock file " + . "with lock reason and lock performer.\n" + . "You are going to be prompted to provide this information" + ) + ->setSyntaxMessage('mage lock to:[environment_name]') + ->addUsageExample( + 'mage lock to:production', + 'Create a lock to production environment deployment' + ); + } + /** * Locks the Deployment to a Environment * @see \Mage\Command\AbstractCommand::run() diff --git a/Mage/Command/BuiltIn/ReleasesCommand.php b/Mage/Command/BuiltIn/ReleasesCommand.php index 3a40439..ddbb712 100644 --- a/Mage/Command/BuiltIn/ReleasesCommand.php +++ b/Mage/Command/BuiltIn/ReleasesCommand.php @@ -22,6 +22,36 @@ use Mage\Console; */ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment { + public function __construct() + { + $this->setName('Releases management command') + ->setHelpMessage('Manages releases') + ->setSyntaxMessage( + 'mage releases [list|rollback [--release=[release_id]]] ' + . 'to:[environment_name] [--deleteCurrent]' + ) + ->addUsageExample( + 'mage releases list to:production', + 'List releases on production environment' + ) + ->addUsageExample( + 'mage releases rollback --release=20120101172148 to:production', + 'Rollback 20120101172148 release on production environment' + ) + ->addUsageExample( + 'mage releases rollback --release=-1 to:production', + 'Rollback list release -1 release on production environment' + ) + ->addUsageExample( + 'mage releases rollback --release=0 to:production', + 'Rollback last release on production environment' + ) + ->addUsageExample( + 'mage releases rollback -1 to:production --deleteCurrent', + 'Rollbacks the last release -1 release and removes current release' + ); + } + /** * List the Releases, Rollback to a Release * @see \Mage\Command\AbstractCommand::run() diff --git a/Mage/Command/BuiltIn/RollbackCommand.php b/Mage/Command/BuiltIn/RollbackCommand.php index dea92b0..88db0f9 100644 --- a/Mage/Command/BuiltIn/RollbackCommand.php +++ b/Mage/Command/BuiltIn/RollbackCommand.php @@ -22,6 +22,24 @@ use Mage\Console; */ class RollbackCommand extends AbstractCommand implements RequiresEnvironment { + public function __construct() + { + $this->setName('Rollback command') + ->setHelpMessage('Rollbacks the release by given release id or index') + ->setSyntaxMessage('mage rollback [releaseId] to:[environment_name]') + ->addUsageExample( + 'mage rollback 20120101172148 to:production', + 'Rollbacks the 20120101172148 release on production environment' + ) + ->addUsageExample( + 'mage rollback -1 to:production', + 'Rollbacks the last release -1 release' + ) + ->addUsageExample( + 'mage rollback -1 to:production --deleteCurrent', + 'Rollbacks the last release -1 release and removes current release' + ); + } /** * Rollback a release * @see \Mage\Command\AbstractCommand::run() diff --git a/Mage/Command/BuiltIn/UnlockCommand.php b/Mage/Command/BuiltIn/UnlockCommand.php index 2c7d324..874ccef 100644 --- a/Mage/Command/BuiltIn/UnlockCommand.php +++ b/Mage/Command/BuiltIn/UnlockCommand.php @@ -21,6 +21,17 @@ use Mage\Console; */ class UnlockCommand extends AbstractCommand implements RequiresEnvironment { + public function __construct() + { + $this->setName('Unlock command') + ->setHelpMessage('Unlocks deployment for given environment') + ->setSyntaxMessage('mage unlock to:[environment_name]') + ->addUsageExample( + 'mage unlock to:production', + 'Removes the lock form production environment deployment' + ); + } + /** * Unlocks an Environment * @see \Mage\Command\AbstractCommand::run() diff --git a/Mage/Command/BuiltIn/UpdateCommand.php b/Mage/Command/BuiltIn/UpdateCommand.php index 30cff52..699c90a 100644 --- a/Mage/Command/BuiltIn/UpdateCommand.php +++ b/Mage/Command/BuiltIn/UpdateCommand.php @@ -21,6 +21,13 @@ use Mage\Console; */ class UpdateCommand extends AbstractCommand { + public function __construct() + { + $this->setName('Update command') + ->setHelpMessage('Updates the SCM base code') + ->setSyntaxMessage('mage update'); + } + /** * Updates the SCM Base Code * @see \Mage\Command\AbstractCommand::run() diff --git a/Mage/Command/BuiltIn/UpgradeCommand.php b/Mage/Command/BuiltIn/UpgradeCommand.php index a9861ac..c6083ee 100644 --- a/Mage/Command/BuiltIn/UpgradeCommand.php +++ b/Mage/Command/BuiltIn/UpgradeCommand.php @@ -20,6 +20,13 @@ use Mage\Console; */ class UpgradeCommand extends AbstractCommand { + public function __construct() + { + $this->setName('Upgrade command') + ->setHelpMessage('Upgrades Magallanes') + ->setSyntaxMessage('mage upgrade'); + } + /** * Source for downloading * @var string diff --git a/Mage/Command/BuiltIn/VersionCommand.php b/Mage/Command/BuiltIn/VersionCommand.php index 0c7938c..665e559 100644 --- a/Mage/Command/BuiltIn/VersionCommand.php +++ b/Mage/Command/BuiltIn/VersionCommand.php @@ -20,6 +20,12 @@ use Mage\Console; */ class VersionCommand extends AbstractCommand { + public function __construct() + { + $this->setName('Version command') + ->setHelpMessage('Displays the current version of Magallanes') + ->setSyntaxMessage('mage version'); + } /** * Display the Magallanes Version * @see \Mage\Command\AbstractCommand::run() From 8a5f0ee23ee26c960f0b5b57856d29de78632b26 Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Sat, 16 May 2015 20:23:48 +0200 Subject: [PATCH 18/33] Fix conflicts after merge --- Mage/Command/BuiltIn/CompileCommand.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Mage/Command/BuiltIn/CompileCommand.php b/Mage/Command/BuiltIn/CompileCommand.php index ae08ab9..38a8049 100644 --- a/Mage/Command/BuiltIn/CompileCommand.php +++ b/Mage/Command/BuiltIn/CompileCommand.php @@ -21,13 +21,6 @@ use Mage\Compiler; */ class CompileCommand extends AbstractCommand { - public function __construct() - { - $this->setName('Compile command') - ->setHelpMessage('Compiles Magallanes to mage.phar file') - ->setSyntaxMessage('mage compile'); - } - /** * @var Compiler */ @@ -40,6 +33,10 @@ class CompileCommand extends AbstractCommand } $this->compiler = $compiler; + + $this->setName('Compile command') + ->setHelpMessage('Compiles Magallanes to mage.phar file') + ->setSyntaxMessage('mage compile'); } /** From b9cf2d1058b7f511ec406a9d550c9b9a178452b8 Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Sat, 16 May 2015 22:20:20 +0200 Subject: [PATCH 19/33] Fix 'covers' annotations --- tests/MageTest/Command/BuiltIn/CompileCommandTest.php | 1 + tests/MageTest/Command/BuiltIn/ListCommandTest.php | 2 ++ tests/MageTest/Command/BuiltIn/LockCommandTest.php | 1 + tests/MageTest/Command/BuiltIn/UnlockCommandTest.php | 1 + tests/MageTest/Command/BuiltIn/VersionCommandTest.php | 6 ++++-- 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/MageTest/Command/BuiltIn/CompileCommandTest.php b/tests/MageTest/Command/BuiltIn/CompileCommandTest.php index 44b4486..77af2a3 100644 --- a/tests/MageTest/Command/BuiltIn/CompileCommandTest.php +++ b/tests/MageTest/Command/BuiltIn/CompileCommandTest.php @@ -16,6 +16,7 @@ use malkusch\phpmock\MockBuilder; * @uses malkusch\phpmock\MockBuilder * @uses Mage\Console * @uses Mage\Console\Colors + * @uses Mage\Command\AbstractCommand */ class CompileCommandTest extends BaseTest { diff --git a/tests/MageTest/Command/BuiltIn/ListCommandTest.php b/tests/MageTest/Command/BuiltIn/ListCommandTest.php index 4d193e1..36c1389 100644 --- a/tests/MageTest/Command/BuiltIn/ListCommandTest.php +++ b/tests/MageTest/Command/BuiltIn/ListCommandTest.php @@ -93,6 +93,7 @@ class ListCommandTest extends BaseTest } /** + * @covers ::__construct * @covers ::run * @covers ::listEnvironments * @dataProvider listEnvironmentsProvider @@ -109,6 +110,7 @@ class ListCommandTest extends BaseTest } /** + * @covers ::__construct * @covers ::run */ public function testRunWithInvalidCommand() diff --git a/tests/MageTest/Command/BuiltIn/LockCommandTest.php b/tests/MageTest/Command/BuiltIn/LockCommandTest.php index e56b63f..84ab390 100644 --- a/tests/MageTest/Command/BuiltIn/LockCommandTest.php +++ b/tests/MageTest/Command/BuiltIn/LockCommandTest.php @@ -173,6 +173,7 @@ class LockCommandTest extends BaseTest } /** + * @covers ::__construct * @covers ::run * @dataProvider lockCommandProvider */ diff --git a/tests/MageTest/Command/BuiltIn/UnlockCommandTest.php b/tests/MageTest/Command/BuiltIn/UnlockCommandTest.php index 1732811..be22134 100644 --- a/tests/MageTest/Command/BuiltIn/UnlockCommandTest.php +++ b/tests/MageTest/Command/BuiltIn/UnlockCommandTest.php @@ -98,6 +98,7 @@ class UnlockCommandTest extends BaseTest } /** + * @covers ::__construct * @covers ::run * @dataProvider runProvider */ diff --git a/tests/MageTest/Command/BuiltIn/VersionCommandTest.php b/tests/MageTest/Command/BuiltIn/VersionCommandTest.php index 6565510..d6a85db 100644 --- a/tests/MageTest/Command/BuiltIn/VersionCommandTest.php +++ b/tests/MageTest/Command/BuiltIn/VersionCommandTest.php @@ -8,16 +8,18 @@ use MageTest\TestHelper\BaseTest; use PHPUnit_Framework_TestCase; /** - * @coversDefaultClass Mage\Command\BuiltIn\VersionCommands + * @coversDefaultClass Mage\Command\BuiltIn\VersionCommand * @group Mage_Command_BuildIn_VersionCommand * @uses Mage\Console * @uses Mage\Console\Colors + * @uses Mage\Command\AbstractCommand */ class VersionCommandTest extends BaseTest { /** * @group 175 - * @covers Mage\Command\BuiltIn\VersionCommand::run() + * @covers ::__construct + * @covers ::run() */ public function testRun() { From 9bb17413d2d7feacef1acae1ed4d31ee8fdb9ec8 Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Tue, 19 May 2015 17:17:50 +0200 Subject: [PATCH 20/33] Fix code for PHP 5.3 --- Mage/Task/AbstractTask.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Mage/Task/AbstractTask.php b/Mage/Task/AbstractTask.php index d4bcf6c..ec1d4e0 100644 --- a/Mage/Task/AbstractTask.php +++ b/Mage/Task/AbstractTask.php @@ -318,12 +318,12 @@ abstract class AbstractTask protected function getEnvVariables() { $configVars = array_merge( - $this->getConfig()->general('env', []), - $this->getConfig()->environmentConfig('env', []), - $this->getConfig()->getParameter('env', []), - [ - 'variables' => $this->getConfig()->getParameter('env.variables', []) - ] + $this->getConfig()->general('env', array()), + $this->getConfig()->environmentConfig('env', array()), + $this->getConfig()->getParameter('env', array()), + array( + 'variables' => $this->getConfig()->getParameter('env.variables', array()) + ) ); if (isset($configVars['variables'])) { From 8c55588918e28862fb5b882102989625493e4752 Mon Sep 17 00:00:00 2001 From: AlberT Date: Thu, 28 May 2015 13:53:33 +0200 Subject: [PATCH 21/33] security fix, use escapeshellcmd() --- Mage/Console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage/Console.php b/Mage/Console.php index ef29492..3705066 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -212,7 +212,7 @@ class Console $return = 1; $log = array(); - exec($command . ' 2>&1', $log, $return); + exec(escapeshellcmd($command . ' 2>&1'), $log, $return); $log = implode(PHP_EOL, $log); if (!$return) { From 3547c03cef41622d3a12af1c87eae50f941dbe75 Mon Sep 17 00:00:00 2001 From: Jakub Turek Date: Fri, 29 May 2015 19:57:57 +0200 Subject: [PATCH 22/33] Fix array syntax for PHP 5.3 compatibility --- Mage/Task/BuiltIn/Filesystem/ApplyFaclsTask.php | 2 +- Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Mage/Task/BuiltIn/Filesystem/ApplyFaclsTask.php b/Mage/Task/BuiltIn/Filesystem/ApplyFaclsTask.php index 3f40ee7..116f826 100644 --- a/Mage/Task/BuiltIn/Filesystem/ApplyFaclsTask.php +++ b/Mage/Task/BuiltIn/Filesystem/ApplyFaclsTask.php @@ -33,7 +33,7 @@ class ApplyFaclsTask extends AbstractTask implements IsReleaseAware throw new SkipException('Parameter acl_param not set.'); } - $folders = $this->getParameter('folders', []); + $folders = $this->getParameter('folders', array()); $recursive = $this->getParameter('recursive', false) ? ' -R ' : ' '; foreach ($folders as $folder) { diff --git a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php index 2682b86..e7010cb 100644 --- a/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php +++ b/Mage/Task/BuiltIn/Filesystem/LinkSharedFilesTask.php @@ -147,6 +147,6 @@ class LinkSharedFilesTask extends AbstractTask implements IsReleaseAware $path = $linkedEntity; } - return [$path, $strategy]; + return array($path, $strategy); } } From 0b903788f3b0ffe828d752a780a6ee9960a59703 Mon Sep 17 00:00:00 2001 From: Alejandro Glejberman Date: Tue, 2 Jun 2015 09:15:35 -0300 Subject: [PATCH 23/33] Set branch revert as the last task on post deployment --- Mage/Command/BuiltIn/DeployCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 9105792..afea5a2 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -251,7 +251,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment // Change Branch Back if ($config->deployment('scm', false)) { - array_unshift($tasksToRun, 'scm/change-branch'); + array_push($tasksToRun, 'scm/change-branch'); $config->addParameter('_changeBranchRevert'); } From f6d969e99b7441e025d77e51e2376bdc8821e37c Mon Sep 17 00:00:00 2001 From: drAlberT Date: Thu, 2 Jul 2015 09:45:42 +0200 Subject: [PATCH 24/33] FIX PSR2 --- Mage/Compiler.php | 1 - Mage/Console.php | 5 ----- Mage/Task/BuiltIn/General/ManuallyTask.php | 1 - tests/MageTest/Command/AbstractCommandTest.php | 1 - 4 files changed, 8 deletions(-) diff --git a/Mage/Compiler.php b/Mage/Compiler.php index ad209fc..4792b3e 100644 --- a/Mage/Compiler.php +++ b/Mage/Compiler.php @@ -21,7 +21,6 @@ use RecursiveDirectoryIterator; */ class Compiler { - /** * Compiles the library * diff --git a/Mage/Console.php b/Mage/Console.php index 3705066..daccf00 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -13,7 +13,6 @@ namespace Mage; use Mage\Command\Factory; use Mage\Command\RequiresEnvironment; use Mage\Console\Colors; - use Exception; use RecursiveDirectoryIterator; use SplFileInfo; @@ -95,7 +94,6 @@ class Console try { // Load configuration $config->load($arguments); - } catch (Exception $exception) { $configError = $exception->getMessage(); } @@ -119,7 +117,6 @@ class Console if ($showGreetings) { if (!self::$logEnabled) { self::output('Starting Magallanes', 0, 2); - } else { self::output('Starting Magallanes', 0, 1); self::log("Logging enabled"); @@ -130,7 +127,6 @@ class Console // Run Command - Check if there is a Configuration Error if ($configError !== false) { self::output('' . $configError . '', 1, 2); - } else { // Run Command and check for Command Requirements try { @@ -314,5 +310,4 @@ class Console || self::$config->general('verbose_logging') || self::$config->environmentConfig('verbose_logging', false); } - } diff --git a/Mage/Task/BuiltIn/General/ManuallyTask.php b/Mage/Task/BuiltIn/General/ManuallyTask.php index 64870d3..a69c1a1 100644 --- a/Mage/Task/BuiltIn/General/ManuallyTask.php +++ b/Mage/Task/BuiltIn/General/ManuallyTask.php @@ -32,7 +32,6 @@ use Mage\Task\AbstractTask; */ class ManuallyTask extends AbstractTask { - /** * (non-PHPdoc) * @see \Mage\Task\AbstractTask::getName() diff --git a/tests/MageTest/Command/AbstractCommandTest.php b/tests/MageTest/Command/AbstractCommandTest.php index cd21930..c700c49 100644 --- a/tests/MageTest/Command/AbstractCommandTest.php +++ b/tests/MageTest/Command/AbstractCommandTest.php @@ -266,6 +266,5 @@ class AbstractCommandTest extends BaseTest $actualMessage = $command->getInfoMessage(); $this->assertEquals($expectedMessage, $actualMessage); - } } From 13fbe3e2dde46502cf4a2eab70ee470a3107633c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20Bl=C3=BCm?= Date: Fri, 11 Dec 2015 09:35:50 +0100 Subject: [PATCH 25/33] Fix Composer version constraint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit “~1.0.*” results in a Composer throwing an UnexpectedValueException --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9fe1b3b..ad7dfb9 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Simply add the following dependency to your project’s composer.json file: ```js "require-dev": { // ... - "andres-montanez/magallanes": "~1.0.*" + "andres-montanez/magallanes": "~1.0" // ... } ``` @@ -39,7 +39,7 @@ $ bin/mage version ### System-wide installation with composer ### ```bash -$ composer global require "andres-montanez/magallanes=~1.0.*" +$ composer global require "andres-montanez/magallanes=~1.0" ``` Make sure you have ~/.composer/vendor/bin/ in your path. From ef8a591c8c08e288544c836685293becc6fe8373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Su=C3=A1rez?= Date: Tue, 10 May 2016 17:02:11 +0200 Subject: [PATCH 26/33] Add support to Bcc and Cc in Mailer --- Mage/Mailer.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Mage/Mailer.php b/Mage/Mailer.php index 1751c85..b7bffca 100644 --- a/Mage/Mailer.php +++ b/Mage/Mailer.php @@ -14,6 +14,7 @@ namespace Mage; * Mailer Helper. * * @author Andrés Montañez + * @author César Suárez */ class Mailer { @@ -24,6 +25,8 @@ class Mailer protected $project; protected $environment; protected $logFile; + protected $cc; + protected $bcc; public function setAddress($address) { @@ -49,6 +52,18 @@ class Mailer return $this; } + public function setBcc($bcc) + { + $this->bcc = $bcc; + return $this; + } + + public function setCc($cc) + { + $this->cc = $cc; + return $this; + } + public function send($result) { $boundary = md5(date('r', time())); @@ -61,6 +76,14 @@ class Mailer . self::EOL . 'Content-Type: multipart/mixed; boundary=Mage-mixed-' . $boundary; + if ($this->cc) { + $headers .= self::EOL . 'Cc: ' . $this->cc; + } + + if ($this->bcc) { + $headers .= self::EOL . 'Bcc: ' . $this->bcc; + } + $subject = str_replace( array('{project}', '{environment}', '{result}'), array($this->project, $this->environment, $result ? 'SUCCESS' : 'FAILURE'), From 20aa01174c3e3569c6aff87238e672f65f31ed30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Su=C3=A1rez?= Date: Tue, 10 May 2016 17:22:40 +0200 Subject: [PATCH 27/33] Add support to use Cc and Bcc in the notification system --- Mage/Command/BuiltIn/DeployCommand.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 8dd6c9d..c97ae41 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -225,11 +225,11 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment if (self::$failedTasks === 0) { $exitCode = 0; } - + if (self::$deployStatus === self::FAILED) { $exitCode = 1; } - + return $exitCode; } @@ -590,6 +590,8 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment $projectName = $this->getConfig()->general('name', false); $projectEmail = $this->getConfig()->general('email', false); $notificationsEnabled = $this->getConfig()->general('notifications', false); + $ccEmail = $this->getConfig()->general('email_options.cc', null); + $bccEmail = $this->getConfig()->general('email_options.bcc', null); // We need notifications enabled, and a project name and email to send the notification if (!$projectName || !$projectEmail || !$notificationsEnabled) { @@ -600,8 +602,17 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment $mailer->setAddress($projectEmail) ->setProject($projectName) ->setLogFile(Console::getLogFile()) - ->setEnvironment($this->getConfig()->getEnvironment()) - ->send($result); + ->setEnvironment($this->getConfig()->getEnvironment()); + + if ($ccEmail) { + $mailer->setCc($ccEmail); + } + + if ($bccEmail) { + $mailer->setBcc($bccEmail); + } + + $mailer->send($result); return true; } From 3923b632de125a9ad7d675e5abc901650f732f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Su=C3=A1rez?= Date: Tue, 10 May 2016 18:15:43 +0200 Subject: [PATCH 28/33] Fix configuration management --- Mage/Command/BuiltIn/DeployCommand.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index c97ae41..3296df5 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -590,8 +590,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment $projectName = $this->getConfig()->general('name', false); $projectEmail = $this->getConfig()->general('email', false); $notificationsEnabled = $this->getConfig()->general('notifications', false); - $ccEmail = $this->getConfig()->general('email_options.cc', null); - $bccEmail = $this->getConfig()->general('email_options.bcc', null); + $emailOptions = $this->getConfig()->general('email_options', array()); // We need notifications enabled, and a project name and email to send the notification if (!$projectName || !$projectEmail || !$notificationsEnabled) { @@ -604,12 +603,12 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment ->setLogFile(Console::getLogFile()) ->setEnvironment($this->getConfig()->getEnvironment()); - if ($ccEmail) { - $mailer->setCc($ccEmail); + if (isset($emailOptions['cc'])) { + $mailer->setCc($emailOptions['cc']); } - if ($bccEmail) { - $mailer->setBcc($bccEmail); + if (isset($emailOptions['bcc'])) { + $mailer->setBcc($emailOptions['bcc']); } $mailer->send($result); From 01e6e898b46af5e7c88b51a8948dfc2b729f4be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Su=C3=A1rez?= Date: Tue, 10 May 2016 20:05:00 +0200 Subject: [PATCH 29/33] Add tests for the DeployCommand notification feature --- Mage/Command/BuiltIn/DeployCommand.php | 6 +- .../Command/BuiltIn/DeployCommandTest.php | 138 ++++++++++++++++++ tests/MageTest/TestHelper/BaseTest.php | 15 ++ 3 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 tests/MageTest/Command/BuiltIn/DeployCommandTest.php diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 3296df5..df75a08 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -215,7 +215,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment Console::output('Total time: ' . $timeText . '.', 1, 2); // Send Notifications - $this->sendNotification(self::$failedTasks > 0 ? false : true); + $this->sendNotification(self::$failedTasks > 0 ? false : true, new Mailer()); // Unlock if (file_exists(getcwd() . '/.mage/~working.lock')) { @@ -583,9 +583,10 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment /** * Send Email Notification if enabled * @param boolean $result + * @param mixed $mailer * @return boolean */ - protected function sendNotification($result) + protected function sendNotification($result, $mailer) { $projectName = $this->getConfig()->general('name', false); $projectEmail = $this->getConfig()->general('email', false); @@ -597,7 +598,6 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment return false; } - $mailer = new Mailer; $mailer->setAddress($projectEmail) ->setProject($projectName) ->setLogFile(Console::getLogFile()) diff --git a/tests/MageTest/Command/BuiltIn/DeployCommandTest.php b/tests/MageTest/Command/BuiltIn/DeployCommandTest.php new file mode 100644 index 0000000..95804d2 --- /dev/null +++ b/tests/MageTest/Command/BuiltIn/DeployCommandTest.php @@ -0,0 +1,138 @@ +getMock('Mage\Mailer'); + $mailerMock + ->method('setAddress') + ->willReturnSelf(); + + $mailerMock + ->method('setProject') + ->willReturnSelf(); + + $mailerMock + ->method('setLogFile') + ->willReturnSelf(); + + $mailerMock + ->method('setEnvironment') + ->willReturnSelf(); + + $mailerMock + ->expects($this->once()) + ->method('send'); + + $configMock = $this->getMock('Mage\Config'); + $configMock + ->method('general') + ->willReturn(true); + + $deployCommand = new DeployCommand(); + $deployCommand->setConfig($configMock); + + $this->callMethod( + $deployCommand, + 'sendNotification', + array(true, $mailerMock)); + } + + public function testIgnoreNotification() + { + $mailerMock = $this->getMock('Mage\Mailer'); + + $mailerMock + ->expects($this->never()) + ->method('send'); + + $configMock = $this->getMock('Mage\Config'); + $configMock + ->method('general') + ->willReturn(false); + + $deployCommand = new DeployCommand(); + $deployCommand->setConfig($configMock); + $this->callMethod($deployCommand, 'sendNotification', array(true, $mailerMock)); + } + + /** + * @covers ::__construct + * @covers ::sendNotification + */ + public function testSendNotificationWithEmailOptions() + { + $mailerMock = $this->getMock('Mage\Mailer'); + $mailerMock + ->method('setAddress') + ->willReturnSelf(); + + $mailerMock + ->method('setProject') + ->willReturnSelf(); + + $mailerMock + ->method('setLogFile') + ->willReturnSelf(); + + $mailerMock + ->method('setEnvironment') + ->willReturnSelf(); + + $mailerMock + ->expects($this->once()) + ->method('setCc') + ->willReturnSelf(); + + $mailerMock + ->expects($this->once()) + ->method('setBcc') + ->willReturnSelf(); + + $mailerMock + ->expects($this->once()) + ->method('send'); + + $configMock = $this->getMock('Mage\Config'); + + $configMock + ->method('general') + ->will($this->returnCallback(function($option, $default) { + if (strcmp($option, 'email_options') === 0) { + return array('bcc' => true, 'cc' => true); + } + return true; + })); + + $deployCommand = new DeployCommand(); + $deployCommand->setConfig($configMock); + + $this->callMethod( + $deployCommand, + 'sendNotification', + array(true, $mailerMock)); + } +} diff --git a/tests/MageTest/TestHelper/BaseTest.php b/tests/MageTest/TestHelper/BaseTest.php index d8db4dc..62f8680 100644 --- a/tests/MageTest/TestHelper/BaseTest.php +++ b/tests/MageTest/TestHelper/BaseTest.php @@ -11,6 +11,7 @@ namespace MageTest\TestHelper; * * @package MageTest\TestHelper * @author Jakub Turek + * @author César Suárez */ abstract class BaseTest extends \PHPUnit_Framework_TestCase { @@ -43,6 +44,20 @@ abstract class BaseTest extends \PHPUnit_Framework_TestCase $configProperty->setValue($object, $value); } + /** + * Calls a protected/private methord + * @param object $object Object instance + * @param string $methodName Name of the method + * @param array $args Arguments for the method + * @return mixed The output of the method + */ + final protected static function callMethod($object, $methodName, array $args) { + $class = new \ReflectionClass($object); + $method = $class->getMethod($methodName); + $method->setAccessible(true); + return $method->invokeArgs($object, $args); + } + /** * Disable logging to log file and turn off colors * From 905cc6596dbedbfe6f4bfdec82d0d7a3f13c9918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Su=C3=A1rez?= Date: Tue, 10 May 2016 20:06:20 +0200 Subject: [PATCH 30/33] Delete unnecessary property --- tests/MageTest/Command/BuiltIn/DeployCommandTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/MageTest/Command/BuiltIn/DeployCommandTest.php b/tests/MageTest/Command/BuiltIn/DeployCommandTest.php index 95804d2..2636dcd 100644 --- a/tests/MageTest/Command/BuiltIn/DeployCommandTest.php +++ b/tests/MageTest/Command/BuiltIn/DeployCommandTest.php @@ -15,11 +15,6 @@ use malkusch\phpmock\MockBuilder; */ class DeployCommandTest extends BaseTest { - /** - * @var DeployCommand - */ - private $deployCommand; - /** * @covers ::__construct * @covers ::sendNotification From 3f40fe14b32f41274d61a336d56cabab07dae8f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Su=C3=A1rez?= Date: Tue, 10 May 2016 20:09:46 +0200 Subject: [PATCH 31/33] Remove unnecessary use --- tests/MageTest/Command/BuiltIn/DeployCommandTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/MageTest/Command/BuiltIn/DeployCommandTest.php b/tests/MageTest/Command/BuiltIn/DeployCommandTest.php index 2636dcd..b74a304 100644 --- a/tests/MageTest/Command/BuiltIn/DeployCommandTest.php +++ b/tests/MageTest/Command/BuiltIn/DeployCommandTest.php @@ -4,14 +4,11 @@ namespace MageTest\Command\BuiltIn; use Mage\Command\BuiltIn\DeployCommand; use MageTest\TestHelper\BaseTest; -use malkusch\phpmock\MockBuilder; /** * Class DeployCommandTest * @package MageTest\Command\BuiltIn * @coversDefaultClass Mage\Command\BuiltIn\DeployCommand - * @uses malkusch\phpmock\MockBuilder - * @uses malkusch\phpmock\Mock */ class DeployCommandTest extends BaseTest { From 5c61667f93060d4e5786ead3a8eb93cc2b1e8171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Su=C3=A1rez?= Date: Tue, 10 May 2016 20:38:57 +0200 Subject: [PATCH 32/33] Add tests for Mailer --- Mage/Mailer.php | 2 +- tests/MageTest/MailerTest.php | 61 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/MageTest/MailerTest.php diff --git a/Mage/Mailer.php b/Mage/Mailer.php index b7bffca..8a9abe1 100644 --- a/Mage/Mailer.php +++ b/Mage/Mailer.php @@ -106,6 +106,6 @@ class Mailer . $attachment . self::EOL . '--Mage-mixed-' . $boundary . '--' . self::EOL; - mail($this->address, $subject, $message, $headers); + return mail($this->address, $subject, $message, $headers); } } diff --git a/tests/MageTest/MailerTest.php b/tests/MageTest/MailerTest.php new file mode 100644 index 0000000..ef37377 --- /dev/null +++ b/tests/MageTest/MailerTest.php @@ -0,0 +1,61 @@ +setNamespace('Mage') + ->setName('mail') + ->setFunction( + function () use ($mailExecuted){ + return true; + } + ) + ->build(); + + $mockFileGetContents = $builder + ->setNamespace('Mage') + ->setName('file_get_contents') + ->setFunction( + function () { + return true; + } + ) + ->build(); + + $mockMail->enable(); + $mockFileGetContents->enable(); + + $mailer = new Mailer(); + $mailer->setLogFile('test'); + $result = $mailer->send(true); + + $this->assertTrue($result); + + $mockMail->disable(); + $mockFileGetContents->disable(); + + } +} From 251f86e168f5e6a51268cf4ce9e82213c68537be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Su=C3=A1rez?= Date: Tue, 10 May 2016 20:45:16 +0200 Subject: [PATCH 33/33] Fix PHPDoc annotation in tests --- tests/MageTest/MailerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/MageTest/MailerTest.php b/tests/MageTest/MailerTest.php index ef37377..8fe4d30 100644 --- a/tests/MageTest/MailerTest.php +++ b/tests/MageTest/MailerTest.php @@ -9,7 +9,7 @@ use malkusch\phpmock\MockBuilder; /** * Class MailerTest * @package MageTest\Command\BuiltIn - * @coversDefaultClass Mage\Command\BuiltIn\DeployCommand + * @coversDefaultClass Mage\Mailer * @uses malkusch\phpmock\MockBuilder * @uses malkusch\phpmock\Mock */