From 575632d62bd97a5653a299a38e17991fe937c7ab Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Fri, 31 Oct 2014 20:06:54 +0100 Subject: [PATCH 01/19] Enable configurable verbose logging --- Mage/Console.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Mage/Console.php b/Mage/Console.php index b9dd97c..541ed4a 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -227,6 +227,10 @@ class Console $message = date('Y-m-d H:i:s -- ') . $message; fwrite(self::$log, $message . PHP_EOL); + + if (self::$config->general('verbose_logging', false)) { + echo $message . PHP_EOL; + } } } From 67e00bca59ea8776bfacbb514fd53037d2678711 Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Tue, 11 Nov 2014 20:27:33 +0100 Subject: [PATCH 02/19] Add verbose logging state variable --- Mage/Console.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Mage/Console.php b/Mage/Console.php index 541ed4a..a0819af 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -48,6 +48,12 @@ class Console */ private static $logEnabled = true; + /** + * Enables or disables verbose logging + * @var boolean + */ + private static $verboseLogEnabled = false; + /** * String Buffer for the screen output * @var string @@ -107,6 +113,8 @@ class Console self::$logEnabled = $config->general('logging', false); } + self::$verboseLogEnabled = $config->general('verbose_logging', false); + // Greetings if ($showGreetings) { if (!self::$logEnabled) { @@ -228,7 +236,7 @@ class Console $message = date('Y-m-d H:i:s -- ') . $message; fwrite(self::$log, $message . PHP_EOL); - if (self::$config->general('verbose_logging', false)) { + if (self::$verboseLogEnabled) { echo $message . PHP_EOL; } } From 654753b70fa4d3d7fa07869ff1b13830f3451a8f Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Tue, 11 Nov 2014 20:29:46 +0100 Subject: [PATCH 03/19] Avoid duplicating output when verbose option is turned on --- Mage/Console.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Mage/Console.php b/Mage/Console.php index a0819af..43f7e36 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -181,15 +181,17 @@ class Console { self::log(strip_tags($message)); - self::$screenBuffer .= str_repeat("\t", $tabs) - . strip_tags($message) - . str_repeat(PHP_EOL, $newLine); + if (!self::$verboseLogEnabled) { + self::$screenBuffer .= str_repeat("\t", $tabs) + . strip_tags($message) + . str_repeat(PHP_EOL, $newLine); - $output = str_repeat("\t", $tabs) - . Colors::color($message, self::$config) - . str_repeat(PHP_EOL, $newLine); + $output = str_repeat("\t", $tabs) + . Colors::color($message, self::$config) + . str_repeat(PHP_EOL, $newLine); - echo $output; + echo $output; + } } /** From 0734c7be0a0b8ff0263ead3532ff06a9d085d541 Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Tue, 11 Nov 2014 20:34:50 +0100 Subject: [PATCH 04/19] Check if verbose logging is enabled --- Mage/Console.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Mage/Console.php b/Mage/Console.php index 43f7e36..db378a1 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -113,7 +113,7 @@ class Console self::$logEnabled = $config->general('logging', false); } - self::$verboseLogEnabled = $config->general('verbose_logging', false); + self::$verboseLogEnabled = self::isVerboseLoggingEnabled(); // Greetings if ($showGreetings) { @@ -300,4 +300,13 @@ class Console } } + /** + * Check if verbose logging is enabled + * @return boolean + */ + protected static function isVerboseLoggingEnabled() + { + return self::$config->getParameter('verbose', false) || self::$config->general('verbose_logging'); + } + } From d63d10547128485a10edef603dc80724680f682b Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Tue, 11 Nov 2014 20:38:26 +0100 Subject: [PATCH 05/19] Add ability to set 'verbose_logging' for environment --- Mage/Console.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Mage/Console.php b/Mage/Console.php index db378a1..8dd7940 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -306,7 +306,9 @@ class Console */ protected static function isVerboseLoggingEnabled() { - return self::$config->getParameter('verbose', false) || self::$config->general('verbose_logging'); + return self::$config->getParameter('verbose', false) + || self::$config->general('verbose_logging') + || self::$config->environmentConfig('verbose_logging', false); } } From 9eb61d1d4badf9a3b60b787b7ea8a430eb6e633d Mon Sep 17 00:00:00 2001 From: Kuba Turek Date: Tue, 11 Nov 2014 20:40:58 +0100 Subject: [PATCH 06/19] Write down some example of verbose usage option --- docs/commands.txt | 4 +++- docs/example-config/.mage/config/environment/production.yml | 1 + docs/example-config/.mage/config/environment/staging.yml | 1 + docs/example-config/.mage/config/general.yml | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/commands.txt b/docs/commands.txt index b9674b4..178bad2 100644 --- a/docs/commands.txt +++ b/docs/commands.txt @@ -51,9 +51,11 @@ mage releases rollback --release=-3 to:production # Rollback to a specific Release on the Production environment # mage releases rollback --release=20120101172148 to:production +# Output logs by adding verbose option to ANY command +mage deploy to:production --verbose ### List of UPCOMING Commands ### # mage config add host s05.example.com to:[production] # mage config git git://github.com/andres-montanez/Zend-Framework-Twig-example-app.git # mage config svn svn://example.com/repo -# mage task:deployment/rsync to:production \ No newline at end of file +# mage task:deployment/rsync to:production diff --git a/docs/example-config/.mage/config/environment/production.yml b/docs/example-config/.mage/config/environment/production.yml index 5122d7d..97a3fcc 100644 --- a/docs/example-config/.mage/config/environment/production.yml +++ b/docs/example-config/.mage/config/environment/production.yml @@ -21,3 +21,4 @@ tasks: - privileges - sampleTask - sampleTaskRollbackAware +verbose_logging: true diff --git a/docs/example-config/.mage/config/environment/staging.yml b/docs/example-config/.mage/config/environment/staging.yml index 5c1c51d..51f4f06 100644 --- a/docs/example-config/.mage/config/environment/staging.yml +++ b/docs/example-config/.mage/config/environment/staging.yml @@ -29,3 +29,4 @@ tasks: # - sampleTask post-deploy: - sampleTask +verbose_logging: false diff --git a/docs/example-config/.mage/config/general.yml b/docs/example-config/.mage/config/general.yml index 3834ff3..c3a9b6d 100644 --- a/docs/example-config/.mage/config/general.yml +++ b/docs/example-config/.mage/config/general.yml @@ -3,6 +3,7 @@ name: My fantastic App email: andresmontanez@gmail.com notifications: true logging: true +verbose_logging: false scm: type: git url: git://github.com/andres-montanez/Zend-Framework-Twig-example-app.git From 8e603bd0d268d5bd4a0c412e4de8dc6aa20dd5db Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Thu, 13 Nov 2014 00:13:19 +0400 Subject: [PATCH 07/19] fixed bug with a env-configuration containing deployment description in hosts section --- Mage/Command/BuiltIn/DeployCommand.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 943a630..7ee5235 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -439,13 +439,22 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment } else { $result = true; - foreach ($hosts as $host) { - $this->getConfig()->setHost($host); + foreach ($hosts as $hostKey => $host) { + $hostConfig = null; + if (is_array($host)) { + $hostConfig = $host; + $host = $hostKey; + } + // Set Host and Host Specific Config + $this->getConfig()->setHost($host); + $this->getConfig()->setHostConfig($hostConfig); $this->getConfig()->setReleaseId(-1); + $task = Factory::get('releases/rollback', $this->getConfig()); $task->init(); $result = $task->run() && $result; + } return $result; } From db4b4299c2abac6b09e341f10321899631b6263d Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Thu, 13 Nov 2014 02:07:20 +0400 Subject: [PATCH 08/19] added rollback delete default option from yaml configs --- Mage/Task/BuiltIn/Releases/RollbackTask.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Mage/Task/BuiltIn/Releases/RollbackTask.php b/Mage/Task/BuiltIn/Releases/RollbackTask.php index 7a437fd..2d798b1 100644 --- a/Mage/Task/BuiltIn/Releases/RollbackTask.php +++ b/Mage/Task/BuiltIn/Releases/RollbackTask.php @@ -60,7 +60,11 @@ class RollbackTask extends AbstractTask implements IsReleaseAware } else { rsort($releases); - $deleteCurrent = $this->getConfig()->getParameter('deleteCurrent', false); + $deleteCurrent = $this->getConfig()->getParameter('deleteCurrent', + $this->getConfig()->deployment('delete-on-rollback', + $this->getConfig()->general('delete-on-rollback',false) + ) + ); $releaseIsAvailable = false; if ($this->getReleaseId() == '') { From 5eb26748ab182fbd00b8efd26fa55cece4b8dbdb Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Thu, 13 Nov 2014 16:40:02 +0400 Subject: [PATCH 09/19] added restriction to run the rollback. small changes at rollback output. --- Mage/Command/BuiltIn/DeployCommand.php | 34 ++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 7ee5235..e4e2a78 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -59,6 +59,15 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment */ const IN_PROGRESS = 'in_progress'; + /** + * Stage where possible throw Rollback Exception + * @var array + */ + public $acceptedStagesToRollback = array( + AbstractTask::STAGE_POST_RELEASE, + AbstractTask::STAGE_POST_DEPLOY + ); + /** * Time the Deployment has Started * @var integer @@ -430,11 +439,19 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment } } - protected function runRollbackTask(){ + protected function runRollbackTask(AbstractTask $task){ $this->getConfig()->reload(); $hosts = $this->getConfig()->getHosts(); - if (count($hosts) == 0) { + Console::output("",1,2); + Console::output("Starting the rollback",1,1); + + if(!in_array($task->getStage(), $this->acceptedStagesToRollback ) ) { + $stagesString = implode(', ',$this->acceptedStagesToRollback); + Console::output("Warning! Rollback during deployment can be called only at the stages: $stagesString ",1); + Console::output("Rollback: ABORTING",1,3); + + } elseif (count($hosts) == 0) { Console::output('Warning! No hosts defined, unable to get releases.', 1, 3); } else { @@ -451,7 +468,14 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment $this->getConfig()->setHostConfig($hostConfig); $this->getConfig()->setReleaseId(-1); - $task = Factory::get('releases/rollback', $this->getConfig()); + $task = Factory::get(array( + 'name'=>'releases/rollback', + 'parameters' => array('inDeploy'=>true) + ), + $this->getConfig(), + false, + $task->getStage() + ); $task->init(); $result = $task->run() && $result; @@ -495,8 +519,8 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment $result = false; } } catch (RollbackException $e) { - Console::output('FAIL, Rollback started [Message: ' . $e->getMessage() . ']', 0); - $this->runRollbackTask(); + Console::output('FAIL, Rollback catched [Message: ' . $e->getMessage() . ']', 0); + $this->runRollbackTask($task); $result = false; } catch (ErrorWithMessageException $e) { From a632dac80ae827caeb086d54811436dce03db26c Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Thu, 13 Nov 2014 16:47:52 +0400 Subject: [PATCH 10/19] added in-deploy flag @ rollback task. --- Mage/Task/BuiltIn/Releases/RollbackTask.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Mage/Task/BuiltIn/Releases/RollbackTask.php b/Mage/Task/BuiltIn/Releases/RollbackTask.php index 2d798b1..1de9831 100644 --- a/Mage/Task/BuiltIn/Releases/RollbackTask.php +++ b/Mage/Task/BuiltIn/Releases/RollbackTask.php @@ -55,6 +55,8 @@ class RollbackTask extends AbstractTask implements IsReleaseAware $result = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $output); $releases = ($output == '') ? array() : explode(PHP_EOL, $output); + $inDeploy = $this->getParameter('inDeploy',false); + if (count($releases) == 0) { Console::output('Release are not available for ' . $this->getConfig()->getHost() . ' ... FAIL'); From c010fc662e9e7f26d6b7d9815ed5a1ff47e741b5 Mon Sep 17 00:00:00 2001 From: samuel4x4 Date: Sun, 23 Nov 2014 23:03:31 +0200 Subject: [PATCH 11/19] Change runCommandRemote() to runCommand() Change runCommandRemote() to runCommand(), you decide if the command is running local or remote depending of the stage you put the scm/force-update task. Remove the last $result = $this->runCommandLocal($command), not necessary. --- Mage/Task/BuiltIn/Scm/ForceUpdateTask.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Mage/Task/BuiltIn/Scm/ForceUpdateTask.php b/Mage/Task/BuiltIn/Scm/ForceUpdateTask.php index 9d68e09..2b1bfe8 100644 --- a/Mage/Task/BuiltIn/Scm/ForceUpdateTask.php +++ b/Mage/Task/BuiltIn/Scm/ForceUpdateTask.php @@ -65,13 +65,13 @@ class ForceUpdateTask extends AbstractTask $remote = $this->getParameter('remote', 'origin'); $command = 'git fetch ' . $remote . ' ' . $branch; - $result = $this->runCommandRemote($command); + $result = $this->runCommand($command); $command = 'git reset --hard ' . $remote . '/' . $branch; - $result = $result && $this->runCommandRemote($command); + $result = $result && $this->runCommand($command); $command = 'git pull ' . $remote . ' ' . $branch; - $result = $result && $this->runCommandRemote($command); + $result = $result && $this->runCommand($command); break; default: @@ -79,7 +79,6 @@ class ForceUpdateTask extends AbstractTask break; } - $result = $this->runCommandLocal($command); $this->getConfig()->reload(); return $result; From 41c3e00f67f4bc3dbc9b8b0b2bb5fa149c544c26 Mon Sep 17 00:00:00 2001 From: samuel4x4 Date: Sun, 23 Nov 2014 23:34:58 +0200 Subject: [PATCH 12/19] Task for running multiple manually commands The purpose of this task is to provide a way to run multiple custom commands for your specific project, before Magallanes will have build-in tasks for your needs. Also maybe you'll just not consider you should create custom tasks for all commands you need (e.g. specific user rights for specific files and directories). --- Mage/Task/BuiltIn/General/ManuallyTask.php | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Mage/Task/BuiltIn/General/ManuallyTask.php diff --git a/Mage/Task/BuiltIn/General/ManuallyTask.php b/Mage/Task/BuiltIn/General/ManuallyTask.php new file mode 100644 index 0000000..71a681d --- /dev/null +++ b/Mage/Task/BuiltIn/General/ManuallyTask.php @@ -0,0 +1,60 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Mage\Task\BuiltIn\Scm; + +use Mage\Task\AbstractTask; + +/** + * Task for running multiple custom commands setting them manually + * + * Example of usage: + * + * tasks: + * on-deploy: + * - scm/force-update + * - general/manually: + * - find . -type d -exec chmod 755 {} \; + * - find . -type f -exec chmod 644 {} \; + * - chmod +x bin/console + * - symfony2/cache-clear + * + * @author Samuel Chiriluta + */ +class ManuallyTask extends AbstractTask { + + /** + * (non-PHPdoc) + * @see \Mage\Task\AbstractTask::getName() + */ + public function getName() + { + return 'Manually multiple custom tasks'; + } + + /** + * @see \Mage\Task\AbstractTask::run() + */ + public function run() + { + $result = true; + + $commands = $this->getParameters(); + + foreach ($commands as $command) + { + $result = $result && $this->runCommand($command); + } + + return $result; + } + +} From 94673b4af2e1d8ca2cc4942d3afc521e7e631abc Mon Sep 17 00:00:00 2001 From: samuel4x4 Date: Sun, 23 Nov 2014 23:57:00 +0200 Subject: [PATCH 13/19] manually task one more example for the manually task --- Mage/Task/BuiltIn/General/ManuallyTask.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Mage/Task/BuiltIn/General/ManuallyTask.php b/Mage/Task/BuiltIn/General/ManuallyTask.php index 71a681d..cc3bdf0 100644 --- a/Mage/Task/BuiltIn/General/ManuallyTask.php +++ b/Mage/Task/BuiltIn/General/ManuallyTask.php @@ -25,6 +25,7 @@ use Mage\Task\AbstractTask; * - find . -type d -exec chmod 755 {} \; * - find . -type f -exec chmod 644 {} \; * - chmod +x bin/console + * - find var/logs -maxdepth 1 -type f -name '*.log' -exec chown apache:apache {} \; * - symfony2/cache-clear * * @author Samuel Chiriluta From e9e5ab1d458662423a138819658278b2d7728f75 Mon Sep 17 00:00:00 2001 From: samuel4x4 Date: Mon, 24 Nov 2014 00:44:23 +0200 Subject: [PATCH 14/19] Fix ManuallyTask namespace namespace Mage\Task\BuiltIn\General --- Mage/Task/BuiltIn/General/ManuallyTask.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mage/Task/BuiltIn/General/ManuallyTask.php b/Mage/Task/BuiltIn/General/ManuallyTask.php index cc3bdf0..aec0279 100644 --- a/Mage/Task/BuiltIn/General/ManuallyTask.php +++ b/Mage/Task/BuiltIn/General/ManuallyTask.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Mage\Task\BuiltIn\Scm; +namespace Mage\Task\BuiltIn\General; use Mage\Task\AbstractTask; From 5eb771bf301ab25eea59528ffbba192d4f4f5224 Mon Sep 17 00:00:00 2001 From: samuel4x4 Date: Mon, 24 Nov 2014 01:08:52 +0200 Subject: [PATCH 15/19] Rename DoctrineMigrate to DoctrineMigrateTask I hope this is the reason it doesn't works. --- .../Symfony2/{DoctrineMigrate.php => DoctrineMigrateTask.php} | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename Mage/Task/BuiltIn/Symfony2/{DoctrineMigrate.php => DoctrineMigrateTask.php} (93%) diff --git a/Mage/Task/BuiltIn/Symfony2/DoctrineMigrate.php b/Mage/Task/BuiltIn/Symfony2/DoctrineMigrateTask.php similarity index 93% rename from Mage/Task/BuiltIn/Symfony2/DoctrineMigrate.php rename to Mage/Task/BuiltIn/Symfony2/DoctrineMigrateTask.php index b76633d..3a412e9 100644 --- a/Mage/Task/BuiltIn/Symfony2/DoctrineMigrate.php +++ b/Mage/Task/BuiltIn/Symfony2/DoctrineMigrateTask.php @@ -15,7 +15,7 @@ use Mage\Task\BuiltIn\Symfony2\SymfonyAbstractTask; /** * Task for Doctrine migrations */ -class DoctrineMigrate extends SymfonyAbstractTask +class DoctrineMigrateTask extends SymfonyAbstractTask { /** * (non-PHPdoc) @@ -34,7 +34,9 @@ class DoctrineMigrate extends SymfonyAbstractTask public function run() { $env = $this->getParameter('env', 'dev'); + $command = $this->getAppPath() . ' doctrine:migrations:migrate -n --env=' . $env; + return $this->runCommand($command); } } From 4d1048cca68cb8973dcb62cc8ba99e1bee3d7302 Mon Sep 17 00:00:00 2001 From: samuel4x4 Date: Mon, 24 Nov 2014 01:36:08 +0200 Subject: [PATCH 16/19] Add optional parameters for symfony2/cache-clear Add optional parameters for symfony2/cache-clear task like --no-warmup. --- Mage/Task/BuiltIn/Symfony2/CacheClearTask.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Mage/Task/BuiltIn/Symfony2/CacheClearTask.php b/Mage/Task/BuiltIn/Symfony2/CacheClearTask.php index 44acc46..d347138 100644 --- a/Mage/Task/BuiltIn/Symfony2/CacheClearTask.php +++ b/Mage/Task/BuiltIn/Symfony2/CacheClearTask.php @@ -14,8 +14,13 @@ use Mage\Task\BuiltIn\Symfony2\SymfonyAbstractTask; /** * Task for Clearing the Cache + * + * Example of usage: + * symfony2/cache-clear: { env: dev } + * symfony2/cache-clear: { env: dev, optional: --no-warmup } * * @author Andrés Montañez + * @author Samuel Chiriluta */ class CacheClearTask extends SymfonyAbstractTask { @@ -36,8 +41,10 @@ class CacheClearTask extends SymfonyAbstractTask { // Options $env = $this->getParameter('env', 'dev'); + $optional = $this->getParameter('optional', ''); + + $command = $this->getAppPath() . ' cache:clear --env=' . $env . ' ' . $optional; - $command = $this->getAppPath() . ' cache:clear --env=' . $env; $result = $this->runCommand($command); return $result; From b11688ea2b382edd7e2cf4327544707dae1d8f60 Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Thu, 27 Nov 2014 21:56:52 +0100 Subject: [PATCH 17/19] initial phpunit config with test example --- .gitignore | 1 + .travis.yml | 10 + composer.json | 3 + composer.lock | 762 ++++++++++++++++++++++++++ phpunit.xml.dist | 19 + tests/MageTest/Console/ColorsTest.php | 41 ++ 6 files changed, 836 insertions(+) create mode 100644 .travis.yml create mode 100644 composer.lock create mode 100644 phpunit.xml.dist create mode 100644 tests/MageTest/Console/ColorsTest.php diff --git a/.gitignore b/.gitignore index a147ed3..66f4d84 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ mage.phar ehthumbs.db Icon? Thumbs.db +nbproject \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..5d2fb0d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: php + +php: + - 5.3 + - 5.4 + - 5.5 + - 5.6 + +install: + - composer install --dev --prefer-source diff --git a/composer.json b/composer.json index 4018174..2183c74 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,9 @@ "require": { "php": ">=5.3" }, + "require-dev": { + "phpunit/phpunit": "4.3.5" + }, "autoload": { "psr-4": { "Mage\\": "./Mage", diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..c1ca3ca --- /dev/null +++ b/composer.lock @@ -0,0 +1,762 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "a19528b890d301384e45c1ed7d221e26", + "packages": [], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.0.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "2.0.*@ALPHA" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Instantiator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2014-10-13 12:58:55" + }, + { + "name": "phpunit/php-code-coverage", + "version": "2.0.11", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "53603b3c995f5aab6b59c8e08c3a663d2cc810b7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/53603b3c995f5aab6b59c8e08c3a663d2cc810b7", + "reference": "53603b3c995f5aab6b59c8e08c3a663d2cc810b7", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "~1.0", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4.1" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2014-08-31 06:33:04" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.3.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "File/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2013-10-10 15:34:57" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "Text/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2014-01-30 17:20:04" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2013-08-02 07:42:54" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "f8d5d08c56de5cfd592b3340424a81733259a876" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/f8d5d08c56de5cfd592b3340424a81733259a876", + "reference": "f8d5d08c56de5cfd592b3340424a81733259a876", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2014-08-31 06:12:13" + }, + { + "name": "phpunit/phpunit", + "version": "4.3.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "2dab9d593997db4abcf58d0daf798eb4e9cecfe1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2dab9d593997db4abcf58d0daf798eb4e9cecfe1", + "reference": "2dab9d593997db4abcf58d0daf798eb4e9cecfe1", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpunit/php-code-coverage": "~2.0", + "phpunit/php-file-iterator": "~1.3.2", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "~1.0.2", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.0", + "sebastian/diff": "~1.1", + "sebastian/environment": "~1.0", + "sebastian/exporter": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "", + "../../symfony/yaml/" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "http://www.phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2014-11-11 10:11:09" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "c63d2367247365f688544f0d500af90a11a44c65" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/c63d2367247365f688544f0d500af90a11a44c65", + "reference": "c63d2367247365f688544f0d500af90a11a44c65", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "~1.0,>=1.0.1", + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.3" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2014-10-03 05:12:11" + }, + { + "name": "sebastian/comparator", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/e54a01c0da1b87db3c5a3c4c5277ddf331da4aef", + "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.1", + "sebastian/exporter": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2014-05-11 23:00:21" + }, + { + "name": "sebastian/diff", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "5843509fed39dee4b356a306401e9dd1a931fec7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/5843509fed39dee4b356a306401e9dd1a931fec7", + "reference": "5843509fed39dee4b356a306401e9dd1a931fec7", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "http://www.github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2014-08-15 10:29:00" + }, + { + "name": "sebastian/environment", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "0d9bf79554d2a999da194a60416c15cf461eb67d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/0d9bf79554d2a999da194a60416c15cf461eb67d", + "reference": "0d9bf79554d2a999da194a60416c15cf461eb67d", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2014-10-22 06:38:05" + }, + { + "name": "sebastian/exporter", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/c7d59948d6e82818e1bdff7cadb6c34710eb7dc0", + "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2014-09-10 00:51:36" + }, + { + "name": "sebastian/version", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43", + "reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43", + "shasum": "" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2014-03-07 15:35:33" + }, + { + "name": "symfony/yaml", + "version": "v2.5.7", + "target-dir": "Symfony/Component/Yaml", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "900d38bc8f74a50343ce65dd1c1e9819658ee56b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/900d38bc8f74a50343ce65dd1c1e9819658ee56b", + "reference": "900d38bc8f74a50343ce65dd1c1e9819658ee56b", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.5-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony Yaml Component", + "homepage": "http://symfony.com", + "time": "2014-11-20 13:22:25" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "platform": { + "php": ">=5.3" + }, + "platform-dev": [] +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..a5e1c3b --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,19 @@ + + + + tests + + + + + src + + + + diff --git a/tests/MageTest/Console/ColorsTest.php b/tests/MageTest/Console/ColorsTest.php new file mode 100644 index 0000000..81ebee1 --- /dev/null +++ b/tests/MageTest/Console/ColorsTest.php @@ -0,0 +1,41 @@ +getMock('Mage\Config'); + $config->expects($this->once()) + ->method('getParameter') + ->will($this->returnValue(false)); + + $string = 'FooBar'; + + // Method need to be non static in the future + $result = Colors::color($string, $config); + $expected = "\033[0;32mFooBar\033[0m"; + + $this->assertSame($expected, $result); + } + + public function testColorNoColor() + { + $config = $this->getMock('Mage\Config'); + $config->expects($this->once()) + ->method('getParameter') + ->will($this->returnValue(true)); + + $string = 'FooBar'; + + // Method need to be non static in the future + $result = Colors::color($string, $config); + $expected = 'FooBar'; + + $this->assertSame($expected, $result); + } +} From 6e1a4d248d0a94f70cb7bd85d737011929faa3dc Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Sat, 29 Nov 2014 20:54:12 +0100 Subject: [PATCH 18/19] group annotation added --- tests/MageTest/Console/ColorsTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/MageTest/Console/ColorsTest.php b/tests/MageTest/Console/ColorsTest.php index 81ebee1..4e1304a 100644 --- a/tests/MageTest/Console/ColorsTest.php +++ b/tests/MageTest/Console/ColorsTest.php @@ -5,8 +5,14 @@ namespace MageTest\Console; use Mage\Console\Colors; use PHPUnit_Framework_TestCase; +/** + * @group Mage_Console_Colors + */ class ColorsTest extends PHPUnit_Framework_TestCase { + /** + * @group 159 + */ public function testColor() { $config = $this->getMock('Mage\Config'); @@ -23,6 +29,9 @@ class ColorsTest extends PHPUnit_Framework_TestCase $this->assertSame($expected, $result); } + /** + * @group 159 + */ public function testColorNoColor() { $config = $this->getMock('Mage\Config'); From d53b8fd8b8a9fa1a2088746953e753d11169663d Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Sat, 29 Nov 2014 20:56:22 +0100 Subject: [PATCH 19/19] new test added for unknown color names --- tests/MageTest/Console/ColorsTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/MageTest/Console/ColorsTest.php b/tests/MageTest/Console/ColorsTest.php index 4e1304a..2655409 100644 --- a/tests/MageTest/Console/ColorsTest.php +++ b/tests/MageTest/Console/ColorsTest.php @@ -47,4 +47,22 @@ class ColorsTest extends PHPUnit_Framework_TestCase $this->assertSame($expected, $result); } + + /** + * @group 159 + */ + public function testColorUnknownColorName() + { + $config = $this->getMock('Mage\Config'); + $config->expects($this->once()) + ->method('getParameter') + ->will($this->returnValue(false)); + + $string = 'FooBar'; + + // Method need to be non static in the future + $result = Colors::color($string, $config); + + $this->assertSame($string, $result); + } }