mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 09:00:18 +01:00 
			
		
		
		
	
						commit
						f603adfb64
					
				
							
								
								
									
										12
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								CHANGELOG.md
									
									
									
									
									
								
							@ -1,6 +1,16 @@
 | 
				
			|||||||
CHANGELOG for 3.x
 | 
					CHANGELOG for 3.X
 | 
				
			||||||
=================
 | 
					=================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* 3.1.0 (2017-02-25)
 | 
				
			||||||
 | 
					 * Add new Exec task to execute arbitrary shell commands
 | 
				
			||||||
 | 
					 * Add new Composer task, to update phar (composer/self-update)
 | 
				
			||||||
 | 
					 * [#344] Allow to flag Filesystem tasks
 | 
				
			||||||
 | 
					 * [PR#346] Add new File System task, to change file's modes (fs/chmod)
 | 
				
			||||||
 | 
					 * [BUGFIX] [PR#342] Ignore empty exclude lines
 | 
				
			||||||
 | 
					 * [PR#330] Allow Composer task options to be overwritten at environment level
 | 
				
			||||||
 | 
					 * [PR#330] Add new method Runtime::getMergedOption to merge ConfigOption and EnvOption
 | 
				
			||||||
 | 
					 * [Documentation] [PR#333] Improve example config file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* 3.0.1 (2017-01-10)
 | 
					* 3.0.1 (2017-01-10)
 | 
				
			||||||
 * [BUGFIX] [#350] [#353] Fix escape issue when commands are sent through SSH
 | 
					 * [BUGFIX] [#350] [#353] Fix escape issue when commands are sent through SSH
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -19,9 +19,9 @@ magephp:
 | 
				
			|||||||
                - composer/install
 | 
					                - composer/install
 | 
				
			||||||
                - composer/generate-autoload
 | 
					                - composer/generate-autoload
 | 
				
			||||||
            on-deploy:
 | 
					            on-deploy:
 | 
				
			||||||
                - symfony/cache-warmup: { env: 'dev' }
 | 
					                - symfony/cache-warmup: { env: 'prod' }
 | 
				
			||||||
                - symfony/assets-install: { env: 'dev' }
 | 
					                - symfony/assets-install: { env: 'prod' }
 | 
				
			||||||
                - symfony/assetic-dump: { env: 'dev' }
 | 
					                - symfony/assetic-dump: { env: 'prod' }
 | 
				
			||||||
            on-release:
 | 
					            on-release:
 | 
				
			||||||
            post-release:
 | 
					            post-release:
 | 
				
			||||||
            post-deploy:
 | 
					            post-deploy:
 | 
				
			||||||
 | 
				
			|||||||
@ -17,6 +17,6 @@ namespace Mage;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class Mage
 | 
					class Mage
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    const VERSION = '3.0.1';
 | 
					    const VERSION = '3.x-dev';
 | 
				
			||||||
    const CODENAME = 'Nostromo';
 | 
					    const CODENAME = 'Nostromo';
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -77,7 +77,6 @@ class MageApplication extends Application
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (array_key_exists('magephp', $config) && is_array($config['magephp'])) {
 | 
					        if (array_key_exists('magephp', $config) && is_array($config['magephp'])) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
            $logger = null;
 | 
					            $logger = null;
 | 
				
			||||||
            if (array_key_exists('log_dir', $config['magephp']) && file_exists($config['magephp']['log_dir']) && is_dir($config['magephp']['log_dir'])) {
 | 
					            if (array_key_exists('log_dir', $config['magephp']) && file_exists($config['magephp']['log_dir']) && is_dir($config['magephp']['log_dir'])) {
 | 
				
			||||||
                $logfile = sprintf('%s/%s.log', $config['magephp']['log_dir'], date('Ymd_His'));
 | 
					                $logfile = sprintf('%s/%s.log', $config['magephp']['log_dir'], date('Ymd_His'));
 | 
				
			||||||
 | 
				
			|||||||
@ -229,6 +229,26 @@ class Runtime
 | 
				
			|||||||
        return $default;
 | 
					        return $default;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Shortcut to get the the configuration option for a specific environment and merge it with
 | 
				
			||||||
 | 
					     * the global one (environment specific overrides the global one if present).
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param       $key
 | 
				
			||||||
 | 
					     * @param array $defaultEnv
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return array
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function getMergedOption($key, $defaultEnv = [])
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $userGlobalOptions = $this->getConfigOption($key, $defaultEnv);
 | 
				
			||||||
 | 
					        $userEnvOptions = $this->getEnvOption($key, $defaultEnv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return array_merge(
 | 
				
			||||||
 | 
					            (is_array($userGlobalOptions) ? $userGlobalOptions : []),
 | 
				
			||||||
 | 
					            (is_array($userEnvOptions) ? $userEnvOptions : [])
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Overwrites an Environment Configuration Option
 | 
					     * Overwrites an Environment Configuration Option
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
 | 
				
			|||||||
@ -61,7 +61,8 @@ abstract class AbstractTask
 | 
				
			|||||||
        if (!is_array($options)) {
 | 
					        if (!is_array($options)) {
 | 
				
			||||||
            $options = [];
 | 
					            $options = [];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        $this->options = $options;
 | 
					
 | 
				
			||||||
 | 
					        $this->options = array_merge($this->getDefaults(), $options);
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -76,4 +77,13 @@ abstract class AbstractTask
 | 
				
			|||||||
        $this->runtime = $runtime;
 | 
					        $this->runtime = $runtime;
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Return Default options
 | 
				
			||||||
 | 
					     * @return array
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function getDefaults()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return [];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -33,20 +33,19 @@ class DumpAutoloadTask extends AbstractTask
 | 
				
			|||||||
    public function execute()
 | 
					    public function execute()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $options = $this->getOptions();
 | 
					        $options = $this->getOptions();
 | 
				
			||||||
        $command = sprintf('%s dump-autoload %s', $options['path'], $options['flags']);
 | 
					        $cmd = sprintf('%s dump-autoload %s', $options['path'], $options['flags']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /** @var Process $process */
 | 
					        /** @var Process $process */
 | 
				
			||||||
        $process = $this->runtime->runCommand(trim($command));
 | 
					        $process = $this->runtime->runCommand(trim($cmd));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $process->isSuccessful();
 | 
					        return $process->isSuccessful();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $userOptions = $this->runtime->getConfigOption('composer', []);
 | 
					 | 
				
			||||||
        $options = array_merge(
 | 
					        $options = array_merge(
 | 
				
			||||||
            ['path' => 'composer', 'flags' => '--optimize'],
 | 
					            ['path' => 'composer', 'flags' => '--optimize'],
 | 
				
			||||||
            (is_array($userOptions) ? $userOptions : []),
 | 
					            $this->runtime->getMergedOption('composer'),
 | 
				
			||||||
            $this->options
 | 
					            $this->options
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -33,20 +33,19 @@ class InstallTask extends AbstractTask
 | 
				
			|||||||
    public function execute()
 | 
					    public function execute()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $options = $this->getOptions();
 | 
					        $options = $this->getOptions();
 | 
				
			||||||
        $command = sprintf('%s install %s', $options['path'], $options['flags']);
 | 
					        $cmd = sprintf('%s install %s', $options['path'], $options['flags']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /** @var Process $process */
 | 
					        /** @var Process $process */
 | 
				
			||||||
        $process = $this->runtime->runCommand(trim($command));
 | 
					        $process = $this->runtime->runCommand(trim($cmd));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $process->isSuccessful();
 | 
					        return $process->isSuccessful();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $userOptions = $this->runtime->getConfigOption('composer', []);
 | 
					 | 
				
			||||||
        $options = array_merge(
 | 
					        $options = array_merge(
 | 
				
			||||||
            ['path' => 'composer', 'flags' => '--optimize-autoloader'],
 | 
					            ['path' => 'composer', 'flags' => '--optimize-autoloader'],
 | 
				
			||||||
            (is_array($userOptions) ? $userOptions : []),
 | 
					            $this->runtime->getMergedOption('composer'),
 | 
				
			||||||
            $this->options
 | 
					            $this->options
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										93
									
								
								src/Task/BuiltIn/Composer/SelfUpdateTask.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								src/Task/BuiltIn/Composer/SelfUpdateTask.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,93 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This file is part of the Magallanes package.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * (c) Andrés Montañez <andres@andresmontanez.com>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * For the full copyright and license information, please view the LICENSE
 | 
				
			||||||
 | 
					 * file that was distributed with this source code.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Mage\Task\BuiltIn\Composer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Mage\Task\Exception\SkipException;
 | 
				
			||||||
 | 
					use Symfony\Component\Process\Process;
 | 
				
			||||||
 | 
					use Mage\Task\AbstractTask;
 | 
				
			||||||
 | 
					use DateTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Composer Task - Self update
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author Yanick Witschi <https://github.com/Toflar>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class SelfUpdateTask extends AbstractTask
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public function getName()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return 'composer/self-update';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getDescription()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return '[Composer] Self Update';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function execute()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $options = $this->getOptions();
 | 
				
			||||||
 | 
					        $cmdVersion = sprintf('%s --version', $options['path']);
 | 
				
			||||||
 | 
					        /** @var Process $process */
 | 
				
			||||||
 | 
					        $process = $this->runtime->runCommand(trim($cmdVersion));
 | 
				
			||||||
 | 
					        if (!$process->isSuccessful()) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $buildDate = $this->getBuildDate($process->getOutput());
 | 
				
			||||||
 | 
					        if (!$buildDate instanceof DateTime) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $compareDate = $this->getCompareDate();
 | 
				
			||||||
 | 
					        if ($buildDate >= $compareDate) {
 | 
				
			||||||
 | 
					            throw new SkipException();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $cmdUpdate = sprintf('%s self-update', $options['path']);
 | 
				
			||||||
 | 
					        /** @var Process $process */
 | 
				
			||||||
 | 
					        $process = $this->runtime->runCommand(trim($cmdUpdate));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $process->isSuccessful();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected function getBuildDate($output)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $buildDate = null;
 | 
				
			||||||
 | 
					        $output = explode(PHP_EOL, $output);
 | 
				
			||||||
 | 
					        foreach ($output as $row) {
 | 
				
			||||||
 | 
					            if (strpos($row, 'Composer version ') === 0) {
 | 
				
			||||||
 | 
					                $buildDate = DateTime::createFromFormat('Y-m-d H:i:s', substr(trim($row), -19));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $buildDate;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected function getCompareDate()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $options = $this->getOptions();
 | 
				
			||||||
 | 
					        $compareDate = new DateTime();
 | 
				
			||||||
 | 
					        $compareDate->modify(sprintf('now -%d days', $options['days']));
 | 
				
			||||||
 | 
					        return $compareDate;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected function getOptions()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $options = array_merge(
 | 
				
			||||||
 | 
					            ['path' => 'composer', 'days' => 60],
 | 
				
			||||||
 | 
					            $this->runtime->getMergedOption('composer'),
 | 
				
			||||||
 | 
					            $this->options
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $options;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -55,7 +55,7 @@ class RsyncTask extends AbstractTask
 | 
				
			|||||||
    protected function getExcludes()
 | 
					    protected function getExcludes()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $excludes = $this->runtime->getEnvOption('exclude', []);
 | 
					        $excludes = $this->runtime->getEnvOption('exclude', []);
 | 
				
			||||||
        $excludes = array_merge(['.git'], $excludes);
 | 
					        $excludes = array_merge(['.git'], array_filter($excludes));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foreach ($excludes as &$exclude) {
 | 
					        foreach ($excludes as &$exclude) {
 | 
				
			||||||
            $exclude = '--exclude=' . $exclude;
 | 
					            $exclude = '--exclude=' . $exclude;
 | 
				
			||||||
 | 
				
			|||||||
@ -52,7 +52,7 @@ class PrepareTask extends AbstractTask
 | 
				
			|||||||
    protected function getExcludes()
 | 
					    protected function getExcludes()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $excludes = $this->runtime->getEnvOption('exclude', []);
 | 
					        $excludes = $this->runtime->getEnvOption('exclude', []);
 | 
				
			||||||
        $excludes = array_merge(['.git'], $excludes);
 | 
					        $excludes = array_merge(['.git'], array_filter($excludes));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foreach ($excludes as &$exclude) {
 | 
					        foreach ($excludes as &$exclude) {
 | 
				
			||||||
            $exclude = '--exclude="' . $exclude . '"';
 | 
					            $exclude = '--exclude="' . $exclude . '"';
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										76
									
								
								src/Task/BuiltIn/ExecTask.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								src/Task/BuiltIn/ExecTask.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,76 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This file is part of the Magallanes package.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * (c) Andrés Montañez <andres@andresmontanez.com>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * For the full copyright and license information, please view the LICENSE
 | 
				
			||||||
 | 
					 * file that was distributed with this source code.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Mage\Task\BuiltIn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Mage\Task\Exception\ErrorException;
 | 
				
			||||||
 | 
					use Mage\Task\AbstractTask;
 | 
				
			||||||
 | 
					use Symfony\Component\Process\Process;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Exec task. Allows you to execute arbitrary commands.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author Yanick Witschi <https://github.com/Toflar>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class ExecTask extends AbstractTask
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @return string
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function getName()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return 'exec';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @return string
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function getDescription()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $options = $this->getOptions();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ($options['desc']) {
 | 
				
			||||||
 | 
					            return '[Exec] ' . $options['desc'];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return '[Exec] Custom command';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @return bool
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @throws ErrorException
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function execute()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $options = $this->getOptions();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!$options['cmd']) {
 | 
				
			||||||
 | 
					            throw new ErrorException('Parameter "cmd" is not defined');
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @var Process $process */
 | 
				
			||||||
 | 
					        $process = $this->runtime->runCommand($options['cmd'], $options['timeout']);
 | 
				
			||||||
 | 
					        return $process->isSuccessful();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @return array
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    protected function getOptions()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $options = array_merge(
 | 
				
			||||||
 | 
					            ['cmd' => '', 'desc' => '', 'timeout' => 120],
 | 
				
			||||||
 | 
					            $this->options
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $options;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -29,8 +29,10 @@ abstract class AbstractFileTask extends AbstractTask
 | 
				
			|||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $mandatory = $this->getParameters();
 | 
					        $mandatory = $this->getParameters();
 | 
				
			||||||
 | 
					        $defaults = array_keys($this->getDefaults());
 | 
				
			||||||
 | 
					        $missing = array_diff($mandatory, $defaults);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foreach ($mandatory as $parameter) {
 | 
					        foreach ($missing as $parameter) {
 | 
				
			||||||
            if (!array_key_exists($parameter, $this->options)) {
 | 
					            if (!array_key_exists($parameter, $this->options)) {
 | 
				
			||||||
                throw new ErrorException(sprintf('Parameter "%s" is not defined', $parameter));
 | 
					                throw new ErrorException(sprintf('Parameter "%s" is not defined', $parameter));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										60
									
								
								src/Task/BuiltIn/FS/ChangeModeTask.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								src/Task/BuiltIn/FS/ChangeModeTask.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,60 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This file is part of the Magallanes package.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * (c) Andrés Montañez <andres@andresmontanez.com>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * For the full copyright and license information, please view the LICENSE
 | 
				
			||||||
 | 
					 * file that was distributed with this source code.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Mage\Task\BuiltIn\FS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Symfony\Component\Process\Process;
 | 
				
			||||||
 | 
					use Exception;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * File System Task - Copy a File
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author Marian Bäuerle
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					class ChangeModeTask extends AbstractFileTask
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public function getName()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return 'fs/chmod';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getDescription()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            return sprintf('[FS] Change mode of "%s" to "%s"', $this->getFile('file'), $this->options['mode']);
 | 
				
			||||||
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
 | 
					            return '[FS] Chmod [missing parameters]';
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function execute()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $file = $this->getFile('file');
 | 
				
			||||||
 | 
					        $mode = $this->options['mode'];
 | 
				
			||||||
 | 
					        $flags = $this->options['flags'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $cmd = sprintf('chmod %s %s "%s"', $flags, $mode, $file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @var Process $process */
 | 
				
			||||||
 | 
					        $process = $this->runtime->runCommand($cmd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $process->isSuccessful();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected function getParameters()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return ['file', 'mode', 'flags'];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getDefaults()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return ['flags' => null];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -38,8 +38,9 @@ class CopyTask extends AbstractFileTask
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        $copyFrom = $this->getFile('from');
 | 
					        $copyFrom = $this->getFile('from');
 | 
				
			||||||
        $copyTo = $this->getFile('to');
 | 
					        $copyTo = $this->getFile('to');
 | 
				
			||||||
 | 
					        $flags = $this->options['flags'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $cmd = sprintf('cp -p %s %s', $copyFrom, $copyTo);
 | 
					        $cmd = sprintf('cp %s "%s" "%s"', $flags, $copyFrom, $copyTo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /** @var Process $process */
 | 
					        /** @var Process $process */
 | 
				
			||||||
        $process = $this->runtime->runCommand($cmd);
 | 
					        $process = $this->runtime->runCommand($cmd);
 | 
				
			||||||
@ -49,6 +50,11 @@ class CopyTask extends AbstractFileTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function getParameters()
 | 
					    protected function getParameters()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return ['from', 'to'];
 | 
					        return ['from', 'to', 'flags'];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getDefaults()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return ['flags' => '-p'];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -38,8 +38,9 @@ class LinkTask extends AbstractFileTask
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        $linkFrom = $this->getFile('from');
 | 
					        $linkFrom = $this->getFile('from');
 | 
				
			||||||
        $linkTo = $this->getFile('to');
 | 
					        $linkTo = $this->getFile('to');
 | 
				
			||||||
 | 
					        $flags = $this->options['flags'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $cmd = sprintf('ln -snf %s %s', $linkFrom, $linkTo);
 | 
					        $cmd = sprintf('ln %s "%s" "%s"', $flags, $linkFrom, $linkTo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /** @var Process $process */
 | 
					        /** @var Process $process */
 | 
				
			||||||
        $process = $this->runtime->runCommand($cmd);
 | 
					        $process = $this->runtime->runCommand($cmd);
 | 
				
			||||||
@ -49,6 +50,11 @@ class LinkTask extends AbstractFileTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function getParameters()
 | 
					    protected function getParameters()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return ['from', 'to'];
 | 
					        return ['from', 'to', 'flags'];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getDefaults()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return ['flags' => '-snf'];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -38,8 +38,9 @@ class MoveTask extends AbstractFileTask
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        $moveFrom = $this->getFile('from');
 | 
					        $moveFrom = $this->getFile('from');
 | 
				
			||||||
        $moveTo = $this->getFile('to');
 | 
					        $moveTo = $this->getFile('to');
 | 
				
			||||||
 | 
					        $flags = $this->options['flags'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $cmd = sprintf('mv %s %s', $moveFrom, $moveTo);
 | 
					        $cmd = sprintf('mv %s "%s" "%s"', $flags, $moveFrom, $moveTo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /** @var Process $process */
 | 
					        /** @var Process $process */
 | 
				
			||||||
        $process = $this->runtime->runCommand($cmd);
 | 
					        $process = $this->runtime->runCommand($cmd);
 | 
				
			||||||
@ -49,6 +50,11 @@ class MoveTask extends AbstractFileTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function getParameters()
 | 
					    protected function getParameters()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return ['from', 'to'];
 | 
					        return ['from', 'to', 'flags'];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getDefaults()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return ['flags' => null];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -37,8 +37,9 @@ class RemoveTask extends AbstractFileTask
 | 
				
			|||||||
    public function execute()
 | 
					    public function execute()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $file = $this->getFile('file');
 | 
					        $file = $this->getFile('file');
 | 
				
			||||||
 | 
					        $flags = $this->options['flags'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $cmd = sprintf('rm %s', $file);
 | 
					        $cmd = sprintf('rm %s "%s"', $flags, $file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /** @var Process $process */
 | 
					        /** @var Process $process */
 | 
				
			||||||
        $process = $this->runtime->runCommand($cmd);
 | 
					        $process = $this->runtime->runCommand($cmd);
 | 
				
			||||||
@ -48,6 +49,11 @@ class RemoveTask extends AbstractFileTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function getParameters()
 | 
					    protected function getParameters()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return ['file'];
 | 
					        return ['file', 'flags'];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getDefaults()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return ['flags' => null];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -43,12 +43,9 @@ class AsseticDumpTask extends AbstractTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
 | 
					 | 
				
			||||||
        $userEnvOptions = $this->runtime->getEnvOption('symfony', []);
 | 
					 | 
				
			||||||
        $options = array_merge(
 | 
					        $options = array_merge(
 | 
				
			||||||
            ['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
 | 
					            ['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
 | 
				
			||||||
            (is_array($userGlobalOptions) ? $userGlobalOptions : []),
 | 
					            $this->runtime->getMergedOption('symfony'),
 | 
				
			||||||
            (is_array($userEnvOptions) ? $userEnvOptions : []),
 | 
					 | 
				
			||||||
            $this->options
 | 
					            $this->options
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -43,12 +43,9 @@ class AssetsInstallTask extends AbstractTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
 | 
					 | 
				
			||||||
        $userEnvOptions = $this->runtime->getEnvOption('symfony', []);
 | 
					 | 
				
			||||||
        $options = array_merge(
 | 
					        $options = array_merge(
 | 
				
			||||||
            ['console' => 'bin/console', 'env' => 'dev', 'target' => 'web', 'flags' => '--symlink --relative'],
 | 
					            ['console' => 'bin/console', 'env' => 'dev', 'target' => 'web', 'flags' => '--symlink --relative'],
 | 
				
			||||||
            (is_array($userGlobalOptions) ? $userGlobalOptions : []),
 | 
					            $this->runtime->getMergedOption('symfony'),
 | 
				
			||||||
            (is_array($userEnvOptions) ? $userEnvOptions : []),
 | 
					 | 
				
			||||||
            $this->options
 | 
					            $this->options
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -43,12 +43,9 @@ class CacheClearTask extends AbstractTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
 | 
					 | 
				
			||||||
        $userEnvOptions = $this->runtime->getEnvOption('symfony', []);
 | 
					 | 
				
			||||||
        $options = array_merge(
 | 
					        $options = array_merge(
 | 
				
			||||||
            ['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
 | 
					            ['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
 | 
				
			||||||
            (is_array($userGlobalOptions) ? $userGlobalOptions : []),
 | 
					            $this->runtime->getMergedOption('symfony'),
 | 
				
			||||||
            (is_array($userEnvOptions) ? $userEnvOptions : []),
 | 
					 | 
				
			||||||
            $this->options
 | 
					            $this->options
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -43,12 +43,9 @@ class CacheWarmupTask extends AbstractTask
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function getOptions()
 | 
					    protected function getOptions()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
 | 
					 | 
				
			||||||
        $userEnvOptions = $this->runtime->getEnvOption('symfony', []);
 | 
					 | 
				
			||||||
        $options = array_merge(
 | 
					        $options = array_merge(
 | 
				
			||||||
            ['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
 | 
					            ['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
 | 
				
			||||||
            (is_array($userGlobalOptions) ? $userGlobalOptions : []),
 | 
					            $this->runtime->getMergedOption('symfony'),
 | 
				
			||||||
            (is_array($userEnvOptions) ? $userEnvOptions : []),
 | 
					 | 
				
			||||||
            $this->options
 | 
					            $this->options
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -80,6 +80,36 @@ class DeployCommandMiscTasksTest extends TestCase
 | 
				
			|||||||
        $this->assertEquals(0, $tester->getStatusCode());
 | 
					        $this->assertEquals(0, $tester->getStatusCode());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testComposerEnvFlags()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $application = new MageApplicationMockup(__DIR__ . '/../../Resources/composer-env.yml');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /** @var AbstractCommand $command */
 | 
				
			||||||
 | 
					        $command = $application->find('deploy');
 | 
				
			||||||
 | 
					        $this->assertTrue($command instanceof DeployCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $tester = new CommandTester($command);
 | 
				
			||||||
 | 
					        $tester->execute(['command' => $command->getName(), 'environment' => 'test']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $application->getRuntime()->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => '/usr/foobar/composer install --prefer-source',
 | 
				
			||||||
 | 
					            1 => '/usr/foobar/composer dump-autoload --no-scripts',
 | 
				
			||||||
 | 
					            2 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertEquals(0, $tester->getStatusCode());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function testInvalidTaskName()
 | 
					    public function testInvalidTaskName()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $application = new MageApplicationMockup(__DIR__ . '/../../Resources/invalid-task.yml');
 | 
					        $application = new MageApplicationMockup(__DIR__ . '/../../Resources/invalid-task.yml');
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										19
									
								
								tests/Resources/composer-env.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								tests/Resources/composer-env.yml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					magephp:
 | 
				
			||||||
 | 
					    log_dir: /tmp
 | 
				
			||||||
 | 
					    composer:
 | 
				
			||||||
 | 
					        path: /usr/bin/composer.phar
 | 
				
			||||||
 | 
					    environments:
 | 
				
			||||||
 | 
					        test:
 | 
				
			||||||
 | 
					            composer:
 | 
				
			||||||
 | 
					                path: /usr/foobar/composer
 | 
				
			||||||
 | 
					            user: tester
 | 
				
			||||||
 | 
					            host_path: /var/www/test
 | 
				
			||||||
 | 
					            exclude:
 | 
				
			||||||
 | 
					                - ./var/cache/*
 | 
				
			||||||
 | 
					                - ./var/log/*
 | 
				
			||||||
 | 
					                - ./web/app_dev.php
 | 
				
			||||||
 | 
					            hosts:
 | 
				
			||||||
 | 
					                - testhost
 | 
				
			||||||
 | 
					            pre-deploy:
 | 
				
			||||||
 | 
					                - composer/install: { flags: '--prefer-source' }
 | 
				
			||||||
 | 
					                - composer/dump-autoload: { flags: '--no-scripts' }
 | 
				
			||||||
@ -10,6 +10,8 @@ magephp:
 | 
				
			|||||||
                - ./var/cache/*
 | 
					                - ./var/cache/*
 | 
				
			||||||
                - ./var/log/*
 | 
					                - ./var/log/*
 | 
				
			||||||
                - ./web/app_dev.php
 | 
					                - ./web/app_dev.php
 | 
				
			||||||
 | 
					                -
 | 
				
			||||||
 | 
					                -
 | 
				
			||||||
            hosts:
 | 
					            hosts:
 | 
				
			||||||
                - testhost
 | 
					                - testhost
 | 
				
			||||||
            pre-deploy:
 | 
					            pre-deploy:
 | 
				
			||||||
 | 
				
			|||||||
@ -68,6 +68,29 @@ class ProcessMockup extends Process
 | 
				
			|||||||
            return '* master';
 | 
					            return '* master';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Make composer build 20 days old
 | 
				
			||||||
 | 
					        if ($this->commandline == 'composer --version') {
 | 
				
			||||||
 | 
					            $date = date('Y-m-d H:i:s', strtotime('now -20 days'));
 | 
				
			||||||
 | 
					            return 'Composer version 1.3.0 ' . $date;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Make ./composer build 20 days old
 | 
				
			||||||
 | 
					        if ($this->commandline == './composer --version') {
 | 
				
			||||||
 | 
					            $date = date('Y-m-d H:i:s', strtotime('now -20 days'));
 | 
				
			||||||
 | 
					            return 'Do not run Composer as root/super user! See https://getcomposer.org/root for details' . PHP_EOL . 'Composer version 1.3.0 ' . $date;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Make composer.phar build 90 days old
 | 
				
			||||||
 | 
					        if ($this->commandline == 'composer.phar --version') {
 | 
				
			||||||
 | 
					            $date = date('Y-m-d H:i:s', strtotime('now -90 days'));
 | 
				
			||||||
 | 
					            return 'Composer version 1.3.0 ' . $date;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Make php composer has wrong output
 | 
				
			||||||
 | 
					        if ($this->commandline == 'php composer --version') {
 | 
				
			||||||
 | 
					            return 'Composer version 1.3.0 no build';
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"') {
 | 
					        if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"') {
 | 
				
			||||||
            return implode(PHP_EOL, ['20170101015110', '20170101015111', '20170101015112', '20170101015113', '20170101015114', '20170101015115', '20170101015116', '20170101015117']);
 | 
					            return implode(PHP_EOL, ['20170101015110', '20170101015111', '20170101015112', '20170101015113', '20170101015114', '20170101015115', '20170101015116', '20170101015117']);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										174
									
								
								tests/Task/BuiltIn/Composer/SelfUpdateTaskTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										174
									
								
								tests/Task/BuiltIn/Composer/SelfUpdateTaskTest.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,174 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Mage\Tests\Task\BuiltIn\Composer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Mage\Tests\Runtime\RuntimeMockup;
 | 
				
			||||||
 | 
					use Mage\Task\BuiltIn\Composer\SelfUpdateTask;
 | 
				
			||||||
 | 
					use Mage\Task\Exception\SkipException;
 | 
				
			||||||
 | 
					use Exception;
 | 
				
			||||||
 | 
					use PHPUnit_Framework_TestCase as TestCase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class SelfUpdateTaskTest extends TestCase
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public function testSelfUpdateTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new SelfUpdateTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['path' => 'composer']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					        $this->assertEquals('[Composer] Self Update', $task->getDescription());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            $task->execute();
 | 
				
			||||||
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
 | 
					            $this->assertTrue($exception instanceof SkipException, 'Update should been skipped');
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'composer --version',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testSelfUpdateAsRootTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new SelfUpdateTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['path' => './composer']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            $task->execute();
 | 
				
			||||||
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
 | 
					            $this->assertTrue($exception instanceof SkipException, 'Update should been skipped');
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => './composer --version',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testSelfUpdateMustUpdateTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new SelfUpdateTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['path' => 'composer.phar']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            $result = $task->execute();
 | 
				
			||||||
 | 
					            $this->assertTrue($result, 'Result should be successful');
 | 
				
			||||||
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
 | 
					            if ($exception instanceof SkipException) {
 | 
				
			||||||
 | 
					                $this->assertTrue(false, 'Update should not have been skipped');
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'composer.phar --version',
 | 
				
			||||||
 | 
					            1 => 'composer.phar self-update',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testSelfUpdateWrongOutputTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new SelfUpdateTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['path' => 'php composer']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            $result = $task->execute();
 | 
				
			||||||
 | 
					            $this->assertFalse($result, 'Result should be failure');
 | 
				
			||||||
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
 | 
					            if ($exception instanceof SkipException) {
 | 
				
			||||||
 | 
					                $this->assertTrue(false, 'Update should not have been skipped');
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'php composer --version',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testSelfUpdateFailExecTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new SelfUpdateTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['path' => 'composer']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					        $runtime->forceFail('composer --version');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            $result = $task->execute();
 | 
				
			||||||
 | 
					            $this->assertFalse($result, 'Result should be failure');
 | 
				
			||||||
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
 | 
					            if ($exception instanceof SkipException) {
 | 
				
			||||||
 | 
					                $this->assertTrue(false, 'Update should not have been skipped');
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'composer --version',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										97
									
								
								tests/Task/BuiltIn/ExecTaskTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								tests/Task/BuiltIn/ExecTaskTest.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,97 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This file is part of the Magallanes package.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * (c) Andrés Montañez <andres@andresmontanez.com>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * For the full copyright and license information, please view the LICENSE
 | 
				
			||||||
 | 
					 * file that was distributed with this source code.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Mage\Tests\Task\BuiltIn;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Mage\Task\Exception\ErrorException;
 | 
				
			||||||
 | 
					use Mage\Task\BuiltIn\ExecTask;
 | 
				
			||||||
 | 
					use Exception;
 | 
				
			||||||
 | 
					use Mage\Tests\Runtime\RuntimeMockup;
 | 
				
			||||||
 | 
					use PHPUnit_Framework_TestCase as TestCase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ExecTest extends TestCase
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public function testSimpleCommand()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new ExecTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['cmd' => 'ls -l', 'desc' => 'Loading docker']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('[Exec] Loading docker', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'ls -l',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testCommandWithoutDescription()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new ExecTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['cmd' => 'ls -la']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('[Exec] Custom command', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'ls -la',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testWithoutCommand()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new ExecTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['desc' => 'Loading docker']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('[Exec] Loading docker', $task->getDescription());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            $task->execute();
 | 
				
			||||||
 | 
					            $this->assertTrue(false, 'Task did not failed');
 | 
				
			||||||
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
 | 
					            $this->assertTrue($exception instanceof ErrorException);
 | 
				
			||||||
 | 
					            $this->assertEquals('Parameter "cmd" is not defined', $exception->getMessage());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										127
									
								
								tests/Task/BuiltIn/FileSystem/ChangeModeTaskTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										127
									
								
								tests/Task/BuiltIn/FileSystem/ChangeModeTaskTest.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,127 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This file is part of the Magallanes package.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * (c) Andrés Montañez <andres@andresmontanez.com>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * For the full copyright and license information, please view the LICENSE
 | 
				
			||||||
 | 
					 * file that was distributed with this source code.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Mage\Tests\Task\BuiltIn\FileSystem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Mage\Task\Exception\ErrorException;
 | 
				
			||||||
 | 
					use Mage\Task\BuiltIn\FS\ChangeModeTask;
 | 
				
			||||||
 | 
					use Exception;
 | 
				
			||||||
 | 
					use Mage\Tests\Runtime\RuntimeMockup;
 | 
				
			||||||
 | 
					use PHPUnit_Framework_TestCase as TestCase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ChangeModeTest extends TestCase
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public function testChangeModeTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new ChangeModeTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['file' => 'a.txt', 'flags' => '-R', 'mode' => 'o+w']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('a.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $this->assertContains('o+w', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'chmod -R o+w "a.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testChangeModeTaskWithoutFlags()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new ChangeModeTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['file' => 'a.txt', 'mode' => 'o+w']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('a.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $this->assertContains('o+w', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'chmod  o+w "a.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testChangeModeReplaceTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new ChangeModeTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['file' => '%environment%.txt', 'flags' => '-R', 'mode' => 'o+w']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('test.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $this->assertContains('o+w', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'chmod -R o+w "test.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testChangeModeBadOptionsTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new ChangeModeTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['from' => 'a.txt', 'flags' => '-R', 'mode' => 'o+w']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            $this->assertContains('[missing parameters]', $task->getDescription());
 | 
				
			||||||
 | 
					            $task->execute();
 | 
				
			||||||
 | 
					            $this->assertTrue(false, 'Task should have raised an exception');
 | 
				
			||||||
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
 | 
					            $this->assertTrue($exception instanceof ErrorException);
 | 
				
			||||||
 | 
					            $this->assertEquals('Parameter "file" is not defined', $exception->getMessage());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										158
									
								
								tests/Task/BuiltIn/FileSystem/CopyTaskTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										158
									
								
								tests/Task/BuiltIn/FileSystem/CopyTaskTest.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,158 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This file is part of the Magallanes package.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * (c) Andrés Montañez <andres@andresmontanez.com>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * For the full copyright and license information, please view the LICENSE
 | 
				
			||||||
 | 
					 * file that was distributed with this source code.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Mage\Tests\Task\BuiltIn\FileSystem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Mage\Task\Exception\ErrorException;
 | 
				
			||||||
 | 
					use Mage\Task\BuiltIn\FS\CopyTask;
 | 
				
			||||||
 | 
					use Exception;
 | 
				
			||||||
 | 
					use Mage\Tests\Runtime\RuntimeMockup;
 | 
				
			||||||
 | 
					use PHPUnit_Framework_TestCase as TestCase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class CopyTaskTest extends TestCase
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public function testCopyTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new CopyTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['from' => 'a.txt', 'to' => 'b.txt']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('a.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $this->assertContains('b.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'cp -p "a.txt" "b.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testCopyTaskWithFlags()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new CopyTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['from' => 'a.txt', 'to' => 'b.txt', 'flags' => '-rp']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('a.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $this->assertContains('b.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'cp -rp "a.txt" "b.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testCopyReplaceTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new CopyTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['from' => '%environment%.txt', 'to' => 'b.txt']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('test.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $this->assertContains('b.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'cp -p "test.txt" "b.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testCopyMultipleReplaceTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					        $runtime->setReleaseId('1234');
 | 
				
			||||||
 | 
					        $runtime->setWorkingHost('localhost');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new CopyTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['from' => '%host%.txt', 'to' => '%release%.yml']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('localhost.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $this->assertContains('1234.yml', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'cp -p "localhost.txt" "1234.yml"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testCopyBadOptionsTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new CopyTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['form' => 'a.txt', 'to' => 'b.txt']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            $this->assertContains('[missing parameters]', $task->getDescription());
 | 
				
			||||||
 | 
					            $task->execute();
 | 
				
			||||||
 | 
					            $this->assertTrue(false, 'Task did not failed');
 | 
				
			||||||
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
 | 
					            $this->assertTrue($exception instanceof ErrorException);
 | 
				
			||||||
 | 
					            $this->assertEquals('Parameter "from" is not defined', $exception->getMessage());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										127
									
								
								tests/Task/BuiltIn/FileSystem/LinkTaskTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										127
									
								
								tests/Task/BuiltIn/FileSystem/LinkTaskTest.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,127 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This file is part of the Magallanes package.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * (c) Andrés Montañez <andres@andresmontanez.com>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * For the full copyright and license information, please view the LICENSE
 | 
				
			||||||
 | 
					 * file that was distributed with this source code.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Mage\Tests\Task\BuiltIn\FileSystem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Mage\Task\Exception\ErrorException;
 | 
				
			||||||
 | 
					use Mage\Task\BuiltIn\FS\LinkTask;
 | 
				
			||||||
 | 
					use Exception;
 | 
				
			||||||
 | 
					use Mage\Tests\Runtime\RuntimeMockup;
 | 
				
			||||||
 | 
					use PHPUnit_Framework_TestCase as TestCase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class LinkTaskTest extends TestCase
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public function testLinkTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new LinkTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['from' => 'a.txt', 'to' => 'b.txt']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('a.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $this->assertContains('b.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'ln -snf "a.txt" "b.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testLinkTaskWithFlags()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new LinkTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['from' => 'a.txt', 'to' => 'b.txt', 'flags' => '-P']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('a.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $this->assertContains('b.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'ln -P "a.txt" "b.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testLinkReplaceTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new LinkTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['from' => '%environment%.txt', 'to' => 'b.txt']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('test.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $this->assertContains('b.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'ln -snf "test.txt" "b.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testLinkBadOptionsTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new LinkTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['form' => 'a.txt', 'to' => 'b.txt']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            $this->assertContains('[missing parameters]', $task->getDescription());
 | 
				
			||||||
 | 
					            $task->execute();
 | 
				
			||||||
 | 
					            $this->assertTrue(false, 'Task did not failed');
 | 
				
			||||||
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
 | 
					            $this->assertTrue($exception instanceof ErrorException);
 | 
				
			||||||
 | 
					            $this->assertEquals('Parameter "from" is not defined', $exception->getMessage());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										127
									
								
								tests/Task/BuiltIn/FileSystem/MoveTaskTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										127
									
								
								tests/Task/BuiltIn/FileSystem/MoveTaskTest.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,127 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This file is part of the Magallanes package.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * (c) Andrés Montañez <andres@andresmontanez.com>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * For the full copyright and license information, please view the LICENSE
 | 
				
			||||||
 | 
					 * file that was distributed with this source code.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Mage\Tests\Task\BuiltIn\FileSystem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Mage\Task\Exception\ErrorException;
 | 
				
			||||||
 | 
					use Mage\Task\BuiltIn\FS\MoveTask;
 | 
				
			||||||
 | 
					use Exception;
 | 
				
			||||||
 | 
					use Mage\Tests\Runtime\RuntimeMockup;
 | 
				
			||||||
 | 
					use PHPUnit_Framework_TestCase as TestCase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class MoveTaskTest extends TestCase
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public function testMoveTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new MoveTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['from' => 'a.txt', 'to' => 'b.txt']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('a.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $this->assertContains('b.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'mv  "a.txt" "b.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testMoveWithFlagsTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new MoveTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['from' => 'a.txt', 'to' => 'b.txt', 'flags' => '-n']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('a.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $this->assertContains('b.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'mv -n "a.txt" "b.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testMoveReplaceTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new MoveTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['from' => '%environment%.txt', 'to' => 'b.txt']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('test.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $this->assertContains('b.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'mv  "test.txt" "b.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testMoveBadOptionsTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new MoveTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['form' => 'a.txt', 'to' => 'b.txt']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            $this->assertContains('[missing parameters]', $task->getDescription());
 | 
				
			||||||
 | 
					            $task->execute();
 | 
				
			||||||
 | 
					            $this->assertTrue(false, 'Task did not failed');
 | 
				
			||||||
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
 | 
					            $this->assertTrue($exception instanceof ErrorException);
 | 
				
			||||||
 | 
					            $this->assertEquals('Parameter "from" is not defined', $exception->getMessage());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										124
									
								
								tests/Task/BuiltIn/FileSystem/RemoveTaskTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								tests/Task/BuiltIn/FileSystem/RemoveTaskTest.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,124 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * This file is part of the Magallanes package.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * (c) Andrés Montañez <andres@andresmontanez.com>
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * For the full copyright and license information, please view the LICENSE
 | 
				
			||||||
 | 
					 * file that was distributed with this source code.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Mage\Tests\Task\BuiltIn\FileSystem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Mage\Task\Exception\ErrorException;
 | 
				
			||||||
 | 
					use Mage\Task\BuiltIn\FS\RemoveTask;
 | 
				
			||||||
 | 
					use Exception;
 | 
				
			||||||
 | 
					use Mage\Tests\Runtime\RuntimeMockup;
 | 
				
			||||||
 | 
					use PHPUnit_Framework_TestCase as TestCase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class RemoveTaskTest extends TestCase
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public function testRemoveTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new RemoveTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['file' => 'a.txt']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('a.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'rm  "a.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testRemoveWithFlagsTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new RemoveTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['file' => 'a.txt', 'flags' => '-fr']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('a.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'rm -fr "a.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testRemoveReplaceTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new RemoveTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['file' => '%environment%.txt']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->assertContains('test.txt', $task->getDescription());
 | 
				
			||||||
 | 
					        $task->execute();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $ranCommands = $runtime->getRanCommands();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $testCase = array(
 | 
				
			||||||
 | 
					            0 => 'rm  "test.txt"',
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check total of Executed Commands
 | 
				
			||||||
 | 
					        $this->assertEquals(count($testCase), count($ranCommands));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Check Generated Commands
 | 
				
			||||||
 | 
					        foreach ($testCase as $index => $command) {
 | 
				
			||||||
 | 
					            $this->assertEquals($command, $ranCommands[$index]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function testRemoveBadOptionsTask()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $runtime = new RuntimeMockup();
 | 
				
			||||||
 | 
					        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
				
			||||||
 | 
					        $runtime->setEnvironment('test');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $task = new RemoveTask();
 | 
				
			||||||
 | 
					        $task->setOptions(['from' => 'a.txt']);
 | 
				
			||||||
 | 
					        $task->setRuntime($runtime);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            $this->assertContains('[missing parameters]', $task->getDescription());
 | 
				
			||||||
 | 
					            $task->execute();
 | 
				
			||||||
 | 
					            $this->assertTrue(false, 'Task did not failed');
 | 
				
			||||||
 | 
					        } catch (Exception $exception) {
 | 
				
			||||||
 | 
					            $this->assertTrue($exception instanceof ErrorException);
 | 
				
			||||||
 | 
					            $this->assertEquals('Parameter "file" is not defined', $exception->getMessage());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,364 +0,0 @@
 | 
				
			|||||||
<?php
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * This file is part of the Magallanes package.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * (c) Andrés Montañez <andres@andresmontanez.com>
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * For the full copyright and license information, please view the LICENSE
 | 
					 | 
				
			||||||
 * file that was distributed with this source code.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace Mage\Tests\Task\BuiltIn;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
use Mage\Task\Exception\ErrorException;
 | 
					 | 
				
			||||||
use Mage\Task\BuiltIn\FS\CopyTask;
 | 
					 | 
				
			||||||
use Mage\Task\BuiltIn\FS\LinkTask;
 | 
					 | 
				
			||||||
use Mage\Task\BuiltIn\FS\MoveTask;
 | 
					 | 
				
			||||||
use Mage\Task\BuiltIn\FS\RemoveTask;
 | 
					 | 
				
			||||||
use Exception;
 | 
					 | 
				
			||||||
use Mage\Tests\Runtime\RuntimeMockup;
 | 
					 | 
				
			||||||
use PHPUnit_Framework_TestCase as TestCase;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class FileSystemTaskTest extends TestCase
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    public function testCopyTask()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					 | 
				
			||||||
        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
					 | 
				
			||||||
        $runtime->setEnvironment('test');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $task = new CopyTask();
 | 
					 | 
				
			||||||
        $task->setOptions(['from' => 'a.txt', 'to' => 'b.txt']);
 | 
					 | 
				
			||||||
        $task->setRuntime($runtime);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $this->assertContains('a.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $this->assertContains('b.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $task->execute();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $ranCommands = $runtime->getRanCommands();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $testCase = array(
 | 
					 | 
				
			||||||
            0 => 'cp -p a.txt b.txt',
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check total of Executed Commands
 | 
					 | 
				
			||||||
        $this->assertEquals(count($testCase), count($ranCommands));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check Generated Commands
 | 
					 | 
				
			||||||
        foreach ($testCase as $index => $command) {
 | 
					 | 
				
			||||||
            $this->assertEquals($command, $ranCommands[$index]);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function testCopyReplaceTask()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					 | 
				
			||||||
        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
					 | 
				
			||||||
        $runtime->setEnvironment('test');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $task = new CopyTask();
 | 
					 | 
				
			||||||
        $task->setOptions(['from' => '%environment%.txt', 'to' => 'b.txt']);
 | 
					 | 
				
			||||||
        $task->setRuntime($runtime);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $this->assertContains('test.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $this->assertContains('b.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $task->execute();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $ranCommands = $runtime->getRanCommands();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $testCase = array(
 | 
					 | 
				
			||||||
            0 => 'cp -p test.txt b.txt',
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check total of Executed Commands
 | 
					 | 
				
			||||||
        $this->assertEquals(count($testCase), count($ranCommands));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check Generated Commands
 | 
					 | 
				
			||||||
        foreach ($testCase as $index => $command) {
 | 
					 | 
				
			||||||
            $this->assertEquals($command, $ranCommands[$index]);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function testCopyMultipleReplaceTask()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					 | 
				
			||||||
        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
					 | 
				
			||||||
        $runtime->setEnvironment('test');
 | 
					 | 
				
			||||||
        $runtime->setReleaseId('1234');
 | 
					 | 
				
			||||||
        $runtime->setWorkingHost('localhost');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $task = new CopyTask();
 | 
					 | 
				
			||||||
        $task->setOptions(['from' => '%host%.txt', 'to' => '%release%.yml']);
 | 
					 | 
				
			||||||
        $task->setRuntime($runtime);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $this->assertContains('localhost.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $this->assertContains('1234.yml', $task->getDescription());
 | 
					 | 
				
			||||||
        $task->execute();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $ranCommands = $runtime->getRanCommands();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $testCase = array(
 | 
					 | 
				
			||||||
            0 => 'cp -p localhost.txt 1234.yml',
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check total of Executed Commands
 | 
					 | 
				
			||||||
        $this->assertEquals(count($testCase), count($ranCommands));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check Generated Commands
 | 
					 | 
				
			||||||
        foreach ($testCase as $index => $command) {
 | 
					 | 
				
			||||||
            $this->assertEquals($command, $ranCommands[$index]);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function testCopyBadOptionsTask()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					 | 
				
			||||||
        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
					 | 
				
			||||||
        $runtime->setEnvironment('test');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $task = new CopyTask();
 | 
					 | 
				
			||||||
        $task->setOptions(['form' => 'a.txt', 'to' => 'b.txt']);
 | 
					 | 
				
			||||||
        $task->setRuntime($runtime);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            $this->assertContains('[missing parameters]', $task->getDescription());
 | 
					 | 
				
			||||||
            $task->execute();
 | 
					 | 
				
			||||||
            $this->assertTrue(false, 'Task did not failed');
 | 
					 | 
				
			||||||
        } catch (Exception $exception) {
 | 
					 | 
				
			||||||
            $this->assertTrue($exception instanceof ErrorException);
 | 
					 | 
				
			||||||
            $this->assertEquals('Parameter "from" is not defined', $exception->getMessage());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function testMoveTask()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					 | 
				
			||||||
        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
					 | 
				
			||||||
        $runtime->setEnvironment('test');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $task = new MoveTask();
 | 
					 | 
				
			||||||
        $task->setOptions(['from' => 'a.txt', 'to' => 'b.txt']);
 | 
					 | 
				
			||||||
        $task->setRuntime($runtime);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $this->assertContains('a.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $this->assertContains('b.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $task->execute();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $ranCommands = $runtime->getRanCommands();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $testCase = array(
 | 
					 | 
				
			||||||
            0 => 'mv a.txt b.txt',
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check total of Executed Commands
 | 
					 | 
				
			||||||
        $this->assertEquals(count($testCase), count($ranCommands));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check Generated Commands
 | 
					 | 
				
			||||||
        foreach ($testCase as $index => $command) {
 | 
					 | 
				
			||||||
            $this->assertEquals($command, $ranCommands[$index]);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function testMoveReplaceTask()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					 | 
				
			||||||
        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
					 | 
				
			||||||
        $runtime->setEnvironment('test');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $task = new MoveTask();
 | 
					 | 
				
			||||||
        $task->setOptions(['from' => '%environment%.txt', 'to' => 'b.txt']);
 | 
					 | 
				
			||||||
        $task->setRuntime($runtime);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $this->assertContains('test.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $this->assertContains('b.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $task->execute();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $ranCommands = $runtime->getRanCommands();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $testCase = array(
 | 
					 | 
				
			||||||
            0 => 'mv test.txt b.txt',
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check total of Executed Commands
 | 
					 | 
				
			||||||
        $this->assertEquals(count($testCase), count($ranCommands));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check Generated Commands
 | 
					 | 
				
			||||||
        foreach ($testCase as $index => $command) {
 | 
					 | 
				
			||||||
            $this->assertEquals($command, $ranCommands[$index]);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function testMoveBadOptionsTask()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					 | 
				
			||||||
        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
					 | 
				
			||||||
        $runtime->setEnvironment('test');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $task = new MoveTask();
 | 
					 | 
				
			||||||
        $task->setOptions(['form' => 'a.txt', 'to' => 'b.txt']);
 | 
					 | 
				
			||||||
        $task->setRuntime($runtime);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            $this->assertContains('[missing parameters]', $task->getDescription());
 | 
					 | 
				
			||||||
            $task->execute();
 | 
					 | 
				
			||||||
            $this->assertTrue(false, 'Task did not failed');
 | 
					 | 
				
			||||||
        } catch (Exception $exception) {
 | 
					 | 
				
			||||||
            $this->assertTrue($exception instanceof ErrorException);
 | 
					 | 
				
			||||||
            $this->assertEquals('Parameter "from" is not defined', $exception->getMessage());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function testRemoveTask()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					 | 
				
			||||||
        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
					 | 
				
			||||||
        $runtime->setEnvironment('test');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $task = new RemoveTask();
 | 
					 | 
				
			||||||
        $task->setOptions(['file' => 'a.txt']);
 | 
					 | 
				
			||||||
        $task->setRuntime($runtime);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $this->assertContains('a.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $task->execute();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $ranCommands = $runtime->getRanCommands();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $testCase = array(
 | 
					 | 
				
			||||||
            0 => 'rm a.txt',
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check total of Executed Commands
 | 
					 | 
				
			||||||
        $this->assertEquals(count($testCase), count($ranCommands));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check Generated Commands
 | 
					 | 
				
			||||||
        foreach ($testCase as $index => $command) {
 | 
					 | 
				
			||||||
            $this->assertEquals($command, $ranCommands[$index]);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function testRemoveReplaceTask()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					 | 
				
			||||||
        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
					 | 
				
			||||||
        $runtime->setEnvironment('test');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $task = new RemoveTask();
 | 
					 | 
				
			||||||
        $task->setOptions(['file' => '%environment%.txt']);
 | 
					 | 
				
			||||||
        $task->setRuntime($runtime);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $this->assertContains('test.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $task->execute();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $ranCommands = $runtime->getRanCommands();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $testCase = array(
 | 
					 | 
				
			||||||
            0 => 'rm test.txt',
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check total of Executed Commands
 | 
					 | 
				
			||||||
        $this->assertEquals(count($testCase), count($ranCommands));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check Generated Commands
 | 
					 | 
				
			||||||
        foreach ($testCase as $index => $command) {
 | 
					 | 
				
			||||||
            $this->assertEquals($command, $ranCommands[$index]);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function testRemoveBadOptionsTask()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					 | 
				
			||||||
        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
					 | 
				
			||||||
        $runtime->setEnvironment('test');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $task = new RemoveTask();
 | 
					 | 
				
			||||||
        $task->setOptions(['from' => 'a.txt']);
 | 
					 | 
				
			||||||
        $task->setRuntime($runtime);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            $this->assertContains('[missing parameters]', $task->getDescription());
 | 
					 | 
				
			||||||
            $task->execute();
 | 
					 | 
				
			||||||
            $this->assertTrue(false, 'Task did not failed');
 | 
					 | 
				
			||||||
        } catch (Exception $exception) {
 | 
					 | 
				
			||||||
            $this->assertTrue($exception instanceof ErrorException);
 | 
					 | 
				
			||||||
            $this->assertEquals('Parameter "file" is not defined', $exception->getMessage());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function testLinkTask()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					 | 
				
			||||||
        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
					 | 
				
			||||||
        $runtime->setEnvironment('test');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $task = new LinkTask();
 | 
					 | 
				
			||||||
        $task->setOptions(['from' => 'a.txt', 'to' => 'b.txt']);
 | 
					 | 
				
			||||||
        $task->setRuntime($runtime);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $this->assertContains('a.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $this->assertContains('b.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $task->execute();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $ranCommands = $runtime->getRanCommands();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $testCase = array(
 | 
					 | 
				
			||||||
            0 => 'ln -snf a.txt b.txt',
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check total of Executed Commands
 | 
					 | 
				
			||||||
        $this->assertEquals(count($testCase), count($ranCommands));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check Generated Commands
 | 
					 | 
				
			||||||
        foreach ($testCase as $index => $command) {
 | 
					 | 
				
			||||||
            $this->assertEquals($command, $ranCommands[$index]);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function testLinkReplaceTask()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					 | 
				
			||||||
        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
					 | 
				
			||||||
        $runtime->setEnvironment('test');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $task = new LinkTask();
 | 
					 | 
				
			||||||
        $task->setOptions(['from' => '%environment%.txt', 'to' => 'b.txt']);
 | 
					 | 
				
			||||||
        $task->setRuntime($runtime);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $this->assertContains('test.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $this->assertContains('b.txt', $task->getDescription());
 | 
					 | 
				
			||||||
        $task->execute();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $ranCommands = $runtime->getRanCommands();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $testCase = array(
 | 
					 | 
				
			||||||
            0 => 'ln -snf test.txt b.txt',
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check total of Executed Commands
 | 
					 | 
				
			||||||
        $this->assertEquals(count($testCase), count($ranCommands));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // Check Generated Commands
 | 
					 | 
				
			||||||
        foreach ($testCase as $index => $command) {
 | 
					 | 
				
			||||||
            $this->assertEquals($command, $ranCommands[$index]);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function testLinkBadOptionsTask()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        $runtime = new RuntimeMockup();
 | 
					 | 
				
			||||||
        $runtime->setConfiguration(['environments' => ['test' => []]]);
 | 
					 | 
				
			||||||
        $runtime->setEnvironment('test');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $task = new LinkTask();
 | 
					 | 
				
			||||||
        $task->setOptions(['form' => 'a.txt', 'to' => 'b.txt']);
 | 
					 | 
				
			||||||
        $task->setRuntime($runtime);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try {
 | 
					 | 
				
			||||||
            $this->assertContains('[missing parameters]', $task->getDescription());
 | 
					 | 
				
			||||||
            $task->execute();
 | 
					 | 
				
			||||||
            $this->assertTrue(false, 'Task did not failed');
 | 
					 | 
				
			||||||
        } catch (Exception $exception) {
 | 
					 | 
				
			||||||
            $this->assertTrue($exception instanceof ErrorException);
 | 
					 | 
				
			||||||
            $this->assertEquals('Parameter "from" is not defined', $exception->getMessage());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user