mirror of
https://github.com/hauke68/Magallanes.git
synced 2025-08-25 04:40:17 +02:00
Compare commits
No commits in common. "master" and "3.0.1" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
/vendor/
|
||||
/build
|
||||
composer.lock
|
||||
.mage.yml
|
||||
|
12
.travis.yml
12
.travis.yml
@ -1,13 +1,9 @@
|
||||
language: php
|
||||
php:
|
||||
- '7.2'
|
||||
- '7.3'
|
||||
- '7.4'
|
||||
|
||||
jobs:
|
||||
fast_finish: true
|
||||
allow_failures:
|
||||
- php: 7.1
|
||||
- '5.5'
|
||||
- '5.6'
|
||||
- '7.0'
|
||||
- '7.1'
|
||||
|
||||
install:
|
||||
- composer install
|
||||
|
13
CHANGELOG.md
13
CHANGELOG.md
@ -1,9 +1,8 @@
|
||||
CHANGELOG for 4.X
|
||||
CHANGELOG for 3.x
|
||||
=================
|
||||
|
||||
* 4.0.0 (2018-04-02)
|
||||
* v4 series release
|
||||
* Refactored for Symfony 4 and PHP 7.1
|
||||
* Symfony Pool Clear task added
|
||||
* Symfony Pool Prune task added
|
||||
* Symfony Assetic task removed
|
||||
* 3.0.1 (2017-01-10)
|
||||
* [BUGFIX] [#350] [#353] Fix escape issue when commands are sent through SSH
|
||||
|
||||
* 3.0.0 (2017-01-31)
|
||||
* v3 series release
|
||||
|
19
README.md
19
README.md
@ -1,5 +1,5 @@
|
||||
# Magallanes
|
||||
[](https://insight.sensiolabs.com/projects/ed0de53a-a12e-459b-9464-34def5907b56)
|
||||
# Magallanes #
|
||||
[](https://insight.sensiolabs.com/projects/ed0de53a-a12e-459b-9464-34def5907b56)
|
||||
[](https://travis-ci.org/andres-montanez/Magallanes)
|
||||
[](https://coveralls.io/github/andres-montanez/Magallanes?branch=master)
|
||||
[](https://scrutinizer-ci.com/g/andres-montanez/Magallanes/)
|
||||
@ -8,15 +8,15 @@
|
||||
[](https://packagist.org/packages/andres-montanez/magallanes)
|
||||
[](https://packagist.org/packages/andres-montanez/magallanes)
|
||||
|
||||
### What's Magallanes?
|
||||
**Magallanes** is a deployment tool for made with PHP for PHP applications; it's quite simple to use and manage. For more information and documentation please visit https://magephp.com
|
||||
### What's Magallanes? ###
|
||||
**Magallanes** is a deployment tool for made with PHP for PHP applications; it's quite simple to use and manage. For more information and documentation please visit http://magephp.com
|
||||
|
||||
### Installing
|
||||
### Installing ###
|
||||
Simply add the following dependency to your project’s composer.json file:
|
||||
|
||||
```json
|
||||
"require": {
|
||||
"andres-montanez/magallanes": "^4.0"
|
||||
"andres-montanez/magallanes": "^3.0"
|
||||
}
|
||||
```
|
||||
Finally you can use **Magallanes** from the vendor's bin:
|
||||
@ -25,5 +25,8 @@ Finally you can use **Magallanes** from the vendor's bin:
|
||||
$ vendor/bin/mage version
|
||||
```
|
||||
|
||||
### Codename Discovery One
|
||||
Each new mayor version of **Magallanes** will have a codename (like Ubuntu), version 3 was _Nostromo_, and in the current version it is **_Discovery One_**, in homage to the spaceship from the ground breaking film *2001: A Space Odyssey (1968)*.
|
||||
### What happend to version 2? ###
|
||||
There is no version 2. I've skipped it and jumpped stright from v1 to v3. This new version of **Magallanes** is quite radical and different from it's successor. The whole application has been rewritten using **_Symfony3 Components_**, so naming it v3 makes a lot of sense.
|
||||
|
||||
### Codename Nostromo ###
|
||||
Each new mayor version of **Magallanes** will have a codename (like Ubuntu), and in the current version it is **_Nostromo_**, like the spaceship from the movie *Alien (1979)*.
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "hauke68/magallanes",
|
||||
"name": "andres-montanez/magallanes",
|
||||
"description": "The Deployment Tool for PHP Applications",
|
||||
"homepage": "https://magephp.com",
|
||||
"homepage": "http://magephp.com",
|
||||
"license": "MIT",
|
||||
"type": "library",
|
||||
"keywords": ["deployment"],
|
||||
@ -9,25 +9,21 @@
|
||||
{
|
||||
"name": "Andrés Montañez",
|
||||
"email": "andresmontanez@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Hauke Zühl",
|
||||
"email": "hzuehl@web.de"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.2.5",
|
||||
"monolog/monolog": "~1.11||^2.0",
|
||||
"symfony/console": "^5.0",
|
||||
"symfony/filesystem": "^5.0",
|
||||
"symfony/event-dispatcher": "^5.0",
|
||||
"symfony/finder": "^5.0",
|
||||
"symfony/yaml": "^5.0",
|
||||
"symfony/process": "^5.0"
|
||||
"php": ">=5.5.9",
|
||||
"monolog/monolog": "^1.0",
|
||||
"symfony/console": "^3.0",
|
||||
"symfony/filesystem": "^3.0",
|
||||
"symfony/event-dispatcher": "^3.0",
|
||||
"symfony/finder": "^3.0",
|
||||
"symfony/yaml": "^3.0",
|
||||
"symfony/process": "^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^7.0",
|
||||
"satooshi/php-coveralls": "^2.0"
|
||||
"phpunit/phpunit": "4.8.*",
|
||||
"satooshi/php-coveralls": "~1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@ -42,8 +38,8 @@
|
||||
"bin": ["bin/mage"],
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.0.x-dev",
|
||||
"dev-discovery-one": "4.x-dev"
|
||||
"dev-master": "3.0.x-dev",
|
||||
"dev-nostromo": "3.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
version: '2'
|
||||
services:
|
||||
php5:
|
||||
container_name: mage-php5
|
||||
build: ./php5
|
||||
volumes:
|
||||
- ../../:/home/magephp
|
||||
|
||||
php7.0:
|
||||
container_name: mage-php7.0
|
||||
build: ./php7.0
|
||||
volumes:
|
||||
- ../../:/home/magephp
|
||||
|
||||
php7.1:
|
||||
container_name: mage-php7.1
|
||||
build: ./php7.1
|
||||
volumes:
|
||||
- ../../:/home/magephp
|
@ -1,9 +0,0 @@
|
||||
FROM ubuntu:14.04
|
||||
|
||||
RUN apt-get update && apt-get upgrade -y
|
||||
RUN apt-get install -y vim curl git unzip
|
||||
RUN apt-get install -y php5-cli php5-curl
|
||||
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
|
||||
|
||||
WORKDIR /home/magephp
|
@ -1,9 +0,0 @@
|
||||
FROM ubuntu:16.04
|
||||
|
||||
RUN apt-get update && apt-get upgrade -y
|
||||
RUN apt-get install -y vim curl git unzip
|
||||
RUN apt-get install -y php7.0-cli php-zip php7.0-curl php7.0-xml
|
||||
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
|
||||
|
||||
WORKDIR /home/magephp
|
@ -1,9 +0,0 @@
|
||||
FROM ubuntu:17.10
|
||||
|
||||
RUN apt-get update && apt-get upgrade -y
|
||||
RUN apt-get install -y vim curl git unzip
|
||||
RUN apt-get install -y php7.1-cli php-zip php7.1-curl php7.1-xml php7.1-mbstring
|
||||
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
|
||||
|
||||
WORKDIR /home/magephp
|
@ -3,7 +3,6 @@ magephp:
|
||||
production:
|
||||
user: app
|
||||
branch: test
|
||||
from: ./
|
||||
host_path: /var/www/test
|
||||
releases: 4
|
||||
exclude:
|
||||
@ -20,12 +19,9 @@ magephp:
|
||||
- composer/install
|
||||
- composer/generate-autoload
|
||||
on-deploy:
|
||||
- symfony/cache-warmup: { env: 'prod' }
|
||||
- symfony/assets-install: { env: 'prod' }
|
||||
- symfony/assetic-dump: { env: 'prod' }
|
||||
- symfony/cache-warmup: { env: 'dev' }
|
||||
- symfony/assets-install: { env: 'dev' }
|
||||
- symfony/assetic-dump: { env: 'dev' }
|
||||
on-release:
|
||||
post-release:
|
||||
post-deploy:
|
||||
- magic
|
||||
custom_tasks:
|
||||
- App\Deployment\MagicTask
|
||||
|
@ -143,9 +143,6 @@ class DeployCommand extends AbstractCommand
|
||||
protected function runOnHosts(OutputInterface $output, $tasks)
|
||||
{
|
||||
$hosts = $this->runtime->getEnvOption('hosts');
|
||||
if (!is_array($hosts) && !$hosts instanceof \Countable) {
|
||||
$hosts = [];
|
||||
}
|
||||
if (count($hosts) == 0) {
|
||||
$output->writeln(sprintf(' No hosts defined, skipping %s tasks', $this->getStageName()));
|
||||
$output->writeln('');
|
||||
@ -178,8 +175,8 @@ class DeployCommand extends AbstractCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->runtime->getHostName() !== null) {
|
||||
$output->writeln(sprintf(' Starting <fg=black;options=bold>%s</> tasks on host <fg=black;options=bold>%s</>:', $this->getStageName(), $this->runtime->getHostName()));
|
||||
if ($this->runtime->getWorkingHost() !== null) {
|
||||
$output->writeln(sprintf(' Starting <fg=black;options=bold>%s</> tasks on host <fg=black;options=bold>%s</>:', $this->getStageName(), $this->runtime->getWorkingHost()));
|
||||
} else {
|
||||
$output->writeln(sprintf(' Starting <fg=black;options=bold>%s</> tasks:', $this->getStageName()));
|
||||
}
|
||||
|
@ -74,9 +74,6 @@ class ListCommand extends AbstractCommand
|
||||
$output->writeln('');
|
||||
|
||||
$hosts = $this->runtime->getEnvOption('hosts');
|
||||
if (!is_array($hosts) && !$hosts instanceof \Countable) {
|
||||
$hosts = [];
|
||||
}
|
||||
if (count($hosts) == 0) {
|
||||
$output->writeln('No hosts defined');
|
||||
$output->writeln('');
|
||||
|
@ -17,6 +17,6 @@ namespace Mage;
|
||||
*/
|
||||
class Mage
|
||||
{
|
||||
const VERSION = '4.0.0';
|
||||
const CODENAME = 'Discovery One';
|
||||
const VERSION = '3.0.1';
|
||||
const CODENAME = 'Nostromo';
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ use Symfony\Component\Finder\SplFileInfo;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\Console\Event\ConsoleErrorEvent;
|
||||
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
|
||||
use Symfony\Component\Console\ConsoleEvents;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Yaml\Parser;
|
||||
@ -46,12 +46,12 @@ class MageApplication extends Application
|
||||
$dispatcher = new EventDispatcher();
|
||||
$this->setDispatcher($dispatcher);
|
||||
|
||||
$dispatcher->addListener(ConsoleEvents::ERROR, function (ConsoleErrorEvent $event) {
|
||||
$dispatcher->addListener(ConsoleEvents::EXCEPTION, function (ConsoleExceptionEvent $event) {
|
||||
$output = $event->getOutput();
|
||||
$command = $event->getCommand();
|
||||
$output->writeln(sprintf('Oops, exception thrown while running command <info>%s</info>', $command->getName()));
|
||||
$exitCode = $event->getExitCode();
|
||||
$event->setError(new \LogicException('Caught exception', $exitCode, $event->getError()));
|
||||
$event->setException(new \LogicException('Caught exception', $exitCode, $event->getException()));
|
||||
});
|
||||
|
||||
$this->runtime = $this->instantiateRuntime();
|
||||
@ -77,6 +77,7 @@ class MageApplication extends Application
|
||||
}
|
||||
|
||||
if (array_key_exists('magephp', $config) && is_array($config['magephp'])) {
|
||||
|
||||
$logger = null;
|
||||
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'));
|
||||
@ -84,9 +85,6 @@ class MageApplication extends Application
|
||||
|
||||
$logger = new Logger('magephp');
|
||||
$logger->pushHandler(new StreamHandler($logfile));
|
||||
|
||||
} elseif (array_key_exists('log_dir', $config['magephp']) && !is_dir($config['magephp']['log_dir'])) {
|
||||
throw new RuntimeException(sprintf('The configured log_dir "%s" does not exists or is not a directory.', $config['magephp']['log_dir']));
|
||||
}
|
||||
|
||||
$this->runtime->setConfiguration($config['magephp']);
|
||||
|
@ -229,26 +229,6 @@ class Runtime
|
||||
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
|
||||
*
|
||||
@ -405,7 +385,7 @@ class Runtime
|
||||
{
|
||||
$this->log($cmd, LogLevel::INFO);
|
||||
|
||||
$process = Process::fromShellCommandline($cmd);
|
||||
$process = new Process($cmd);
|
||||
$process->setTimeout($timeout);
|
||||
$process->run();
|
||||
|
||||
@ -429,7 +409,7 @@ class Runtime
|
||||
{
|
||||
$user = $this->getEnvOption('user', $this->getCurrentUser());
|
||||
$sudo = $this->getEnvOption('sudo', false);
|
||||
$host = $this->getHostName();
|
||||
$host = $this->getWorkingHost();
|
||||
$sshConfig = $this->getSSHConfig();
|
||||
|
||||
$cmdDelegate = $cmd;
|
||||
@ -457,11 +437,7 @@ class Runtime
|
||||
*/
|
||||
public function getSSHConfig()
|
||||
{
|
||||
$sshConfig = $this->getEnvOption('ssh', ['port' => 22, 'flags' => '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no']);
|
||||
|
||||
if ($this->getHostPort() !== null) {
|
||||
$sshConfig['port'] = $this->getHostPort();
|
||||
}
|
||||
$sshConfig = $this->getEnvOption('ssh', ['port' => '22', 'flags' => '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no']);
|
||||
|
||||
if (!array_key_exists('port', $sshConfig)) {
|
||||
$sshConfig['port'] = '22';
|
||||
@ -474,32 +450,6 @@ class Runtime
|
||||
return $sshConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current Host Port or default ssh port
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getHostPort()
|
||||
{
|
||||
$info = explode(':', $this->getWorkingHost());
|
||||
return isset($info[1]) ? $info[1] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current Host Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHostName()
|
||||
{
|
||||
if (strpos($this->getWorkingHost(), ':') === false) {
|
||||
return $this->getWorkingHost();
|
||||
}
|
||||
|
||||
$info = explode(':', $this->getWorkingHost());
|
||||
return $info[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Temporal File name
|
||||
*
|
||||
|
@ -61,8 +61,7 @@ abstract class AbstractTask
|
||||
if (!is_array($options)) {
|
||||
$options = [];
|
||||
}
|
||||
|
||||
$this->options = array_merge($this->getDefaults(), $options);
|
||||
$this->options = $options;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -77,13 +76,4 @@ abstract class AbstractTask
|
||||
$this->runtime = $runtime;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Default options
|
||||
* @return array
|
||||
*/
|
||||
public function getDefaults()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +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\Task\BuiltIn\Composer;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
/**
|
||||
* Abstract Composer Task
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
abstract class AbstractComposerTask extends AbstractTask
|
||||
{
|
||||
protected function getOptions()
|
||||
{
|
||||
$options = array_merge(
|
||||
['path' => 'composer'],
|
||||
$this->getComposerOptions(),
|
||||
$this->runtime->getMergedOption('composer'),
|
||||
$this->options
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
protected function getComposerOptions()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
@ -11,13 +11,14 @@
|
||||
namespace Mage\Task\BuiltIn\Composer;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
/**
|
||||
* Composer Task - Generate Autoload
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
class DumpAutoloadTask extends AbstractComposerTask
|
||||
class DumpAutoloadTask extends AbstractTask
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
@ -32,16 +33,23 @@ class DumpAutoloadTask extends AbstractComposerTask
|
||||
public function execute()
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
$cmd = sprintf('%s dump-autoload %s', $options['path'], $options['flags']);
|
||||
$command = sprintf('%s dump-autoload %s', $options['path'], $options['flags']);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand(trim($cmd));
|
||||
$process = $this->runtime->runCommand(trim($command));
|
||||
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
|
||||
protected function getComposerOptions()
|
||||
protected function getOptions()
|
||||
{
|
||||
return ['flags' => '--optimize'];
|
||||
$userOptions = $this->runtime->getConfigOption('composer', []);
|
||||
$options = array_merge(
|
||||
['path' => 'composer', 'flags' => '--optimize'],
|
||||
(is_array($userOptions) ? $userOptions : []),
|
||||
$this->options
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
@ -11,13 +11,14 @@
|
||||
namespace Mage\Task\BuiltIn\Composer;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
/**
|
||||
* Composer Task - Install Vendors
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
class InstallTask extends AbstractComposerTask
|
||||
class InstallTask extends AbstractTask
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
@ -32,16 +33,23 @@ class InstallTask extends AbstractComposerTask
|
||||
public function execute()
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
$cmd = sprintf('%s install %s', $options['path'], $options['flags']);
|
||||
$command = sprintf('%s install %s', $options['path'], $options['flags']);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand(trim($cmd), $options['timeout']);
|
||||
$process = $this->runtime->runCommand(trim($command));
|
||||
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
|
||||
protected function getComposerOptions()
|
||||
protected function getOptions()
|
||||
{
|
||||
return ['flags' => '--optimize-autoloader', 'timeout' => 120];
|
||||
$userOptions = $this->runtime->getConfigOption('composer', []);
|
||||
$options = array_merge(
|
||||
['path' => 'composer', 'flags' => '--optimize-autoloader'],
|
||||
(is_array($userOptions) ? $userOptions : []),
|
||||
$this->options
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
@ -1,86 +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\Task\BuiltIn\Composer;
|
||||
|
||||
use Mage\Task\Exception\SkipException;
|
||||
use Symfony\Component\Process\Process;
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* Composer Task - Self update
|
||||
*
|
||||
* @author Yanick Witschi <https://github.com/Toflar>
|
||||
*/
|
||||
class SelfUpdateTask extends AbstractComposerTask
|
||||
{
|
||||
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 getComposerOptions()
|
||||
{
|
||||
return ['days' => 60];
|
||||
}
|
||||
}
|
@ -44,7 +44,7 @@ class ReleaseTask extends AbstractTask implements ExecuteOnRollbackInterface
|
||||
$cmdLinkRelease = sprintf('cd %s && ln -snf releases/%s current', $hostPath, $releaseId);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runRemoteCommand($cmdLinkRelease, false, null);
|
||||
$process = $this->runtime->runRemoteCommand($cmdLinkRelease, false);
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class RsyncTask extends AbstractTask
|
||||
$flags = $this->runtime->getEnvOption('rsync', '-avz');
|
||||
$sshConfig = $this->runtime->getSSHConfig();
|
||||
$user = $this->runtime->getEnvOption('user', $this->runtime->getCurrentUser());
|
||||
$host = $this->runtime->getHostName();
|
||||
$host = $this->runtime->getWorkingHost();
|
||||
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||
$targetDir = rtrim($hostPath, '/');
|
||||
|
||||
@ -45,18 +45,17 @@ class RsyncTask extends AbstractTask
|
||||
}
|
||||
|
||||
$excludes = $this->getExcludes();
|
||||
$from = $this->runtime->getEnvOption('from', './');
|
||||
$cmdRsync = sprintf('rsync -e "ssh -p %d %s" %s %s %s %s@%s:%s', $sshConfig['port'], $sshConfig['flags'], $flags, $excludes, $from, $user, $host, $targetDir);
|
||||
$cmdRsync = sprintf('rsync -e "ssh -p %d %s" %s %s ./ %s@%s:%s', $sshConfig['port'], $sshConfig['flags'], $flags, $excludes, $user, $host, $targetDir);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runLocalCommand($cmdRsync, null);
|
||||
$process = $this->runtime->runLocalCommand($cmdRsync, 600);
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
|
||||
protected function getExcludes()
|
||||
{
|
||||
$excludes = $this->runtime->getMergedOption('exclude', []);
|
||||
$excludes = array_merge(['.git'], array_filter($excludes));
|
||||
$excludes = $this->runtime->getEnvOption('exclude', []);
|
||||
$excludes = array_merge(['.git'], $excludes);
|
||||
|
||||
foreach ($excludes as &$exclude) {
|
||||
$exclude = '--exclude=' . $exclude;
|
||||
|
@ -38,12 +38,11 @@ class CopyTask extends AbstractTask
|
||||
}
|
||||
|
||||
$user = $this->runtime->getEnvOption('user', $this->runtime->getCurrentUser());
|
||||
$host = $this->runtime->getHostName();
|
||||
$host = $this->runtime->getWorkingHost();
|
||||
$sshConfig = $sshConfig = $this->runtime->getSSHConfig();
|
||||
$hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
|
||||
$currentReleaseId = $this->runtime->getReleaseId();
|
||||
|
||||
$tarPath = $this->runtime->getEnvOption('tar_extract_path', 'tar');
|
||||
$flags = $this->runtime->getEnvOption('tar_extract', 'xfzop');
|
||||
$targetDir = sprintf('%s/releases/%s', $hostPath, $currentReleaseId);
|
||||
|
||||
@ -55,7 +54,7 @@ class CopyTask extends AbstractTask
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runLocalCommand($cmdCopy, 300);
|
||||
if ($process->isSuccessful()) {
|
||||
$cmdUnTar = sprintf('cd %s && %s %s %s', $targetDir, $tarPath, $flags, $tarRemote);
|
||||
$cmdUnTar = sprintf('cd %s && tar %s %s', $targetDir, $flags, $tarRemote);
|
||||
$process = $this->runtime->runRemoteCommand($cmdUnTar, false, 600);
|
||||
if ($process->isSuccessful()) {
|
||||
$cmdDelete = sprintf('rm %s/%s', $targetDir, $tarRemote);
|
||||
|
@ -41,10 +41,8 @@ class PrepareTask extends AbstractTask
|
||||
$this->runtime->setVar('tar_local', $tarLocal);
|
||||
|
||||
$excludes = $this->getExcludes();
|
||||
$tarPath = $this->runtime->getEnvOption('tar_create_path', 'tar');
|
||||
$flags = $this->runtime->getEnvOption('tar_create', 'cfzp');
|
||||
$from = $this->runtime->getEnvOption('from', './');
|
||||
$cmdTar = sprintf('%s %s %s %s %s', $tarPath, $flags, $tarLocal, $excludes, $from);
|
||||
$cmdTar = sprintf('tar %s %s %s ./', $flags, $tarLocal, $excludes);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runLocalCommand($cmdTar, 300);
|
||||
@ -53,8 +51,8 @@ class PrepareTask extends AbstractTask
|
||||
|
||||
protected function getExcludes()
|
||||
{
|
||||
$excludes = $this->runtime->getMergedOption('exclude', []);
|
||||
$excludes = array_merge(['.git'], array_filter($excludes));
|
||||
$excludes = $this->runtime->getEnvOption('exclude', []);
|
||||
$excludes = array_merge(['.git'], $excludes);
|
||||
|
||||
foreach ($excludes as &$exclude) {
|
||||
$exclude = '--exclude="' . $exclude . '"';
|
||||
|
@ -1,76 +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\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,10 +29,8 @@ abstract class AbstractFileTask extends AbstractTask
|
||||
protected function getOptions()
|
||||
{
|
||||
$mandatory = $this->getParameters();
|
||||
$defaults = array_keys($this->getDefaults());
|
||||
$missing = array_diff($mandatory, $defaults);
|
||||
|
||||
foreach ($missing as $parameter) {
|
||||
foreach ($mandatory as $parameter) {
|
||||
if (!array_key_exists($parameter, $this->options)) {
|
||||
throw new ErrorException(sprintf('Parameter "%s" is not defined', $parameter));
|
||||
}
|
||||
@ -61,8 +59,8 @@ abstract class AbstractFileTask extends AbstractTask
|
||||
'%environment%' => $this->runtime->getEnvironment(),
|
||||
];
|
||||
|
||||
if ($this->runtime->getHostName() !== null) {
|
||||
$mapping['%host%'] = $this->runtime->getHostName();
|
||||
if ($this->runtime->getWorkingHost() !== null) {
|
||||
$mapping['%host%'] = $this->runtime->getWorkingHost();
|
||||
}
|
||||
|
||||
if ($this->runtime->getReleaseId() !== null) {
|
||||
|
@ -1,60 +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\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,9 +38,8 @@ class CopyTask extends AbstractFileTask
|
||||
{
|
||||
$copyFrom = $this->getFile('from');
|
||||
$copyTo = $this->getFile('to');
|
||||
$flags = $this->options['flags'];
|
||||
|
||||
$cmd = sprintf('cp %s "%s" "%s"', $flags, $copyFrom, $copyTo);
|
||||
$cmd = sprintf('cp -p %s %s', $copyFrom, $copyTo);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand($cmd);
|
||||
@ -50,11 +49,6 @@ class CopyTask extends AbstractFileTask
|
||||
|
||||
protected function getParameters()
|
||||
{
|
||||
return ['from', 'to', 'flags'];
|
||||
}
|
||||
|
||||
public function getDefaults()
|
||||
{
|
||||
return ['flags' => '-p'];
|
||||
return ['from', 'to'];
|
||||
}
|
||||
}
|
||||
|
@ -38,9 +38,8 @@ class LinkTask extends AbstractFileTask
|
||||
{
|
||||
$linkFrom = $this->getFile('from');
|
||||
$linkTo = $this->getFile('to');
|
||||
$flags = $this->options['flags'];
|
||||
|
||||
$cmd = sprintf('ln %s "%s" "%s"', $flags, $linkFrom, $linkTo);
|
||||
$cmd = sprintf('ln -snf %s %s', $linkFrom, $linkTo);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand($cmd);
|
||||
@ -50,11 +49,6 @@ class LinkTask extends AbstractFileTask
|
||||
|
||||
protected function getParameters()
|
||||
{
|
||||
return ['from', 'to', 'flags'];
|
||||
}
|
||||
|
||||
public function getDefaults()
|
||||
{
|
||||
return ['flags' => '-snf'];
|
||||
return ['from', 'to'];
|
||||
}
|
||||
}
|
||||
|
@ -38,9 +38,8 @@ class MoveTask extends AbstractFileTask
|
||||
{
|
||||
$moveFrom = $this->getFile('from');
|
||||
$moveTo = $this->getFile('to');
|
||||
$flags = $this->options['flags'];
|
||||
|
||||
$cmd = sprintf('mv %s "%s" "%s"', $flags, $moveFrom, $moveTo);
|
||||
$cmd = sprintf('mv %s %s', $moveFrom, $moveTo);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand($cmd);
|
||||
@ -50,11 +49,6 @@ class MoveTask extends AbstractFileTask
|
||||
|
||||
protected function getParameters()
|
||||
{
|
||||
return ['from', 'to', 'flags'];
|
||||
}
|
||||
|
||||
public function getDefaults()
|
||||
{
|
||||
return ['flags' => null];
|
||||
return ['from', 'to'];
|
||||
}
|
||||
}
|
||||
|
@ -37,9 +37,8 @@ class RemoveTask extends AbstractFileTask
|
||||
public function execute()
|
||||
{
|
||||
$file = $this->getFile('file');
|
||||
$flags = $this->options['flags'];
|
||||
|
||||
$cmd = sprintf('rm %s "%s"', $flags, $file);
|
||||
$cmd = sprintf('rm %s', $file);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand($cmd);
|
||||
@ -49,11 +48,6 @@ class RemoveTask extends AbstractFileTask
|
||||
|
||||
protected function getParameters()
|
||||
{
|
||||
return ['file', 'flags'];
|
||||
}
|
||||
|
||||
public function getDefaults()
|
||||
{
|
||||
return ['flags' => null];
|
||||
return ['file'];
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +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\Task\BuiltIn\Symfony;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
/**
|
||||
* Abstract Symfony Task
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
abstract class AbstractSymfonyTask extends AbstractTask
|
||||
{
|
||||
protected function getOptions()
|
||||
{
|
||||
$options = array_merge(
|
||||
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
||||
$this->getSymfonyOptions(),
|
||||
$this->runtime->getMergedOption('symfony'),
|
||||
$this->options
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
protected function getSymfonyOptions()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
57
src/Task/BuiltIn/Symfony/AsseticDumpTask.php
Normal file
57
src/Task/BuiltIn/Symfony/AsseticDumpTask.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?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\Symfony;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
/**
|
||||
* Symfony Task - Dump Assetics
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
class AsseticDumpTask extends AbstractTask
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'symfony/assetic-dump';
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return '[Symfony] Assetic Dump';
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
$command = sprintf('%s assetic:dump --env=%s %s', $options['console'], $options['env'], $options['flags']);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand(trim($command));
|
||||
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
|
||||
protected function getOptions()
|
||||
{
|
||||
$userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
|
||||
$userEnvOptions = $this->runtime->getEnvOption('symfony', []);
|
||||
$options = array_merge(
|
||||
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
||||
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
||||
(is_array($userEnvOptions) ? $userEnvOptions : []),
|
||||
$this->options
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
@ -11,13 +11,14 @@
|
||||
namespace Mage\Task\BuiltIn\Symfony;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
/**
|
||||
* Symfony Task - Install Assets
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
class AssetsInstallTask extends AbstractSymfonyTask
|
||||
class AssetsInstallTask extends AbstractTask
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
@ -40,8 +41,17 @@ class AssetsInstallTask extends AbstractSymfonyTask
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
|
||||
protected function getSymfonyOptions()
|
||||
protected function getOptions()
|
||||
{
|
||||
return ['target' => 'web', 'flags' => '--symlink --relative'];
|
||||
$userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
|
||||
$userEnvOptions = $this->runtime->getEnvOption('symfony', []);
|
||||
$options = array_merge(
|
||||
['console' => 'bin/console', 'env' => 'dev', 'target' => 'web', 'flags' => '--symlink --relative'],
|
||||
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
||||
(is_array($userEnvOptions) ? $userEnvOptions : []),
|
||||
$this->options
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
@ -11,13 +11,14 @@
|
||||
namespace Mage\Task\BuiltIn\Symfony;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
/**
|
||||
* Symfony Task - Clear Cache
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
class CacheClearTask extends AbstractSymfonyTask
|
||||
class CacheClearTask extends AbstractTask
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
@ -39,4 +40,18 @@ class CacheClearTask extends AbstractSymfonyTask
|
||||
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
|
||||
protected function getOptions()
|
||||
{
|
||||
$userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
|
||||
$userEnvOptions = $this->runtime->getEnvOption('symfony', []);
|
||||
$options = array_merge(
|
||||
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
||||
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
||||
(is_array($userEnvOptions) ? $userEnvOptions : []),
|
||||
$this->options
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
@ -1,53 +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\Task\BuiltIn\Symfony;
|
||||
|
||||
use Mage\Task\Exception\ErrorException;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* Symfony Task - Cache Pool Clear
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
class CachePoolClearTask extends AbstractSymfonyTask
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'symfony/cache-pool-clear';
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return '[Symfony] Cache Pool Clear';
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
|
||||
if (!$options['pools']) {
|
||||
throw new ErrorException('Parameter "pools" is not defined');
|
||||
}
|
||||
|
||||
$command = $options['console'] . ' cache:pool:clear ' . $options['pools'] . ' --env=' . $options['env'] . ' ' . $options['flags'];
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand(trim($command));
|
||||
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
|
||||
protected function getSymfonyOptions()
|
||||
{
|
||||
return ['pools' => null];
|
||||
}
|
||||
}
|
@ -1,42 +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\Task\BuiltIn\Symfony;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* Symfony Task - Cache Pool Prune
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
class CachePoolPruneTask extends AbstractSymfonyTask
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'symfony/cache-pool-prune';
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return '[Symfony] Cache Pool Prune';
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
$command = $options['console'] . ' cache:pool:prune --env=' . $options['env'] . ' ' . $options['flags'];
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand(trim($command));
|
||||
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
}
|
@ -11,13 +11,14 @@
|
||||
namespace Mage\Task\BuiltIn\Symfony;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Mage\Task\AbstractTask;
|
||||
|
||||
/**
|
||||
* Symfony Task - Cache Warmup
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
class CacheWarmupTask extends AbstractSymfonyTask
|
||||
class CacheWarmupTask extends AbstractTask
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
@ -39,4 +40,18 @@ class CacheWarmupTask extends AbstractSymfonyTask
|
||||
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
|
||||
protected function getOptions()
|
||||
{
|
||||
$userGlobalOptions = $this->runtime->getConfigOption('symfony', []);
|
||||
$userEnvOptions = $this->runtime->getEnvOption('symfony', []);
|
||||
$options = array_merge(
|
||||
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
||||
(is_array($userGlobalOptions) ? $userGlobalOptions : []),
|
||||
(is_array($userEnvOptions) ? $userEnvOptions : []),
|
||||
$this->options
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,6 @@ class TaskFactory
|
||||
{
|
||||
$this->runtime = $runtime;
|
||||
$this->loadBuiltInTasks();
|
||||
$this->loadCustomTasks($runtime->getConfigOption('custom_tasks', []));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,11 +102,11 @@ class TaskFactory
|
||||
|
||||
/** @var SplFileInfo $file */
|
||||
foreach ($finder as $file) {
|
||||
$taskClass = substr('\\Mage\\Task\\BuiltIn\\' . str_replace('/', '\\', $file->getRelativePathname()), 0, -4);
|
||||
if (class_exists($taskClass)) {
|
||||
$reflex = new ReflectionClass($taskClass);
|
||||
$class = substr('\\Mage\\Task\\BuiltIn\\' . str_replace('/', '\\', $file->getRelativePathname()), 0, -4);
|
||||
if (class_exists($class)) {
|
||||
$reflex = new ReflectionClass($class);
|
||||
if ($reflex->isInstantiable()) {
|
||||
$task = new $taskClass();
|
||||
$task = new $class();
|
||||
if ($task instanceof AbstractTask) {
|
||||
$this->add($task);
|
||||
}
|
||||
@ -115,31 +114,4 @@ class TaskFactory
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Custom Tasks
|
||||
* @param array $tasksToLoad PreRegistered Tasks
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function loadCustomTasks($tasksToLoad)
|
||||
{
|
||||
foreach ($tasksToLoad as $taskClass) {
|
||||
if (!class_exists($taskClass)) {
|
||||
throw new RuntimeException(sprintf('Custom Task "%s" does not exists.', $taskClass));
|
||||
}
|
||||
|
||||
$reflex = new ReflectionClass($taskClass);
|
||||
if (!$reflex->isInstantiable()) {
|
||||
throw new RuntimeException(sprintf('Custom Task "%s" can not be instantiated.', $taskClass));
|
||||
}
|
||||
|
||||
$task = new $taskClass();
|
||||
if (!$task instanceof AbstractTask) {
|
||||
throw new RuntimeException(sprintf('Custom Task "%s" must inherit "Mage\\Task\\AbstractTask".', $taskClass));
|
||||
}
|
||||
|
||||
// Add Task
|
||||
$this->add($task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\Config\DumpCommand;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class DumpCommandTest extends TestCase
|
||||
{
|
||||
|
@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\Config\EnvironmentsCommand;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class EnvironmentsCommandTest extends TestCase
|
||||
{
|
||||
|
@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\DeployCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class DeployCommandMiscTasksTest extends TestCase
|
||||
{
|
||||
@ -35,10 +35,8 @@ class DeployCommandMiscTasksTest extends TestCase
|
||||
0 => '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',
|
||||
1 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:warmup --env=testenv"',
|
||||
2 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assets:install web --env=testenv --symlink --relative"',
|
||||
3 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:prune --env=testenv"',
|
||||
4 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:prune --env=prod"',
|
||||
5 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:clear main --env=testenv"',
|
||||
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:clear main --env=prod"',
|
||||
3 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assetic:dump --env=testenv"',
|
||||
4 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assetic:dump --env=prod"',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
@ -82,66 +80,6 @@ class DeployCommandMiscTasksTest extends TestCase
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testGlobalExcludeFlags()
|
||||
{
|
||||
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/global-exclude.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/bin/composer.phar install --prefer-source',
|
||||
1 => '/usr/bin/composer.phar 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 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()
|
||||
{
|
||||
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/invalid-task.yml');
|
||||
|
@ -11,11 +11,10 @@
|
||||
namespace Mage\Tests\Command\BuiltIn;
|
||||
|
||||
use Mage\Command\BuiltIn\DeployCommand;
|
||||
use Mage\Runtime\Exception\RuntimeException;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class DeployCommandMiscTest extends TestCase
|
||||
{
|
||||
@ -37,24 +36,6 @@ class DeployCommandMiscTest extends TestCase
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testInvalidLog()
|
||||
{
|
||||
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/invalid-log.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
try {
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
} catch (RuntimeException $exception) {
|
||||
$this->assertEquals('The configured log_dir "/no-temp" does not exists or is not a directory.', $exception->getMessage());
|
||||
} catch (\Exception $exception) {
|
||||
$this->assertFalse(true, sprintf('Exception "%s" catched, message: "%s"', get_class($exception), $exception->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public function testDeploymentWithSudo()
|
||||
{
|
||||
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-sudo.yml');
|
||||
@ -78,7 +59,7 @@ class DeployCommandMiscTest extends TestCase
|
||||
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && sudo bin/console cache:clear --env=dev"',
|
||||
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && sudo bin/console cache:warmup --env=dev"',
|
||||
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && sudo bin/console assets:install web --env=dev --symlink --relative"',
|
||||
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && sudo bin/console cache:pool:prune --env=dev"',
|
||||
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && sudo bin/console assetic:dump --env=dev"',
|
||||
10 => 'git checkout master',
|
||||
);
|
||||
|
||||
@ -115,7 +96,7 @@ class DeployCommandMiscTest extends TestCase
|
||||
5 => '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',
|
||||
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:warmup --env=dev"',
|
||||
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assets:install web --env=dev --symlink --relative"',
|
||||
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:prune --env=dev"',
|
||||
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assetic:dump --env=dev"',
|
||||
9 => 'git checkout master',
|
||||
);
|
||||
|
||||
@ -259,7 +240,7 @@ class DeployCommandMiscTest extends TestCase
|
||||
4 => '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',
|
||||
5 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:warmup --env=dev"',
|
||||
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assets:install web --env=dev --symlink --relative"',
|
||||
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:prune --env=dev"',
|
||||
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assetic:dump --env=dev"',
|
||||
8 => 'git branch | grep "*"',
|
||||
);
|
||||
|
||||
|
@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\DeployCommand;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class DeployCommandWithReleasesTest extends TestCase
|
||||
{
|
||||
@ -46,107 +46,7 @@ class DeployCommandWithReleasesTest extends TestCase
|
||||
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
|
||||
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
|
||||
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
|
||||
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
|
||||
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
|
||||
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
|
||||
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
|
||||
16 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015111"',
|
||||
17 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015112"',
|
||||
18 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015113"',
|
||||
19 => 'rm /tmp/mageXYZ',
|
||||
20 => 'git checkout master',
|
||||
);
|
||||
|
||||
// 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 testDeploymentWithReleasesWithPortCommands()
|
||||
{
|
||||
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-with-port.yml');
|
||||
|
||||
$application->getRuntime()->setReleaseId('20170101015120');
|
||||
|
||||
/** @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 => 'git branch | grep "*"',
|
||||
1 => 'git checkout test',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
|
||||
6 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "mkdir -p /var/www/test/releases/1234567890"',
|
||||
7 => 'scp -P 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
|
||||
8 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
|
||||
9 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
|
||||
10 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=prod"',
|
||||
11 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=prod --symlink --relative"',
|
||||
12 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=prod"',
|
||||
13 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
|
||||
14 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
|
||||
15 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
|
||||
16 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015111"',
|
||||
17 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015112"',
|
||||
18 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015113"',
|
||||
19 => 'rm /tmp/mageXYZ',
|
||||
20 => 'git checkout master',
|
||||
);
|
||||
|
||||
// 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 testDeploymentWithReleasesWithFromCommands()
|
||||
{
|
||||
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-with-from.yml');
|
||||
|
||||
$application->getRuntime()->setReleaseId('20170101015120');
|
||||
|
||||
/** @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 => 'git branch | grep "*"',
|
||||
1 => 'git checkout test',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./dist',
|
||||
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "mkdir -p /var/www/test/releases/1234567890"',
|
||||
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
|
||||
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && tar xfzop mageXYZ"',
|
||||
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
|
||||
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
|
||||
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
|
||||
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
|
||||
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assetic:dump --env=dev"',
|
||||
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
|
||||
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
|
||||
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
|
||||
@ -356,7 +256,7 @@ class DeployCommandWithReleasesTest extends TestCase
|
||||
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
|
||||
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
|
||||
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
|
||||
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
|
||||
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assetic:dump --env=dev"',
|
||||
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
|
||||
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
|
||||
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm -rf /var/www/test/releases/20170101015110"',
|
||||
@ -409,7 +309,7 @@ class DeployCommandWithReleasesTest extends TestCase
|
||||
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "rm /var/www/test/releases/1234567890/mageXYZ"',
|
||||
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:warmup --env=dev"',
|
||||
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assets:install web --env=dev --symlink --relative"',
|
||||
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console cache:pool:prune --env=dev"',
|
||||
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test/releases/1234567890 && bin/console assetic:dump --env=dev"',
|
||||
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && ln -snf releases/1234567890 current"',
|
||||
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "ls -1 /var/www/test/releases"',
|
||||
);
|
||||
|
@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\DeployCommand;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class DeployCommandWithoutReleasesTest extends TestCase
|
||||
{
|
||||
@ -40,81 +40,7 @@ class DeployCommandWithoutReleasesTest extends TestCase
|
||||
5 => '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',
|
||||
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:warmup --env=dev"',
|
||||
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assets:install web --env=dev --symlink --relative"',
|
||||
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:prune --env=dev"',
|
||||
9 => 'git checkout master',
|
||||
);
|
||||
|
||||
// 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 testDeploymentWithoutReleasesWithPortCommands()
|
||||
{
|
||||
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-without-releases-with-port.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 => 'git branch | grep "*"',
|
||||
1 => 'git checkout test',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => 'rsync -e "ssh -p 202 -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',
|
||||
6 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:warmup --env=dev"',
|
||||
7 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assets:install web --env=dev --symlink --relative"',
|
||||
8 => 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:prune --env=dev"',
|
||||
9 => 'git checkout master',
|
||||
);
|
||||
|
||||
// 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 testDeploymentWithoutReleasesWithFromCommands()
|
||||
{
|
||||
$application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-without-releases-with-from.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 => 'git branch | grep "*"',
|
||||
1 => 'git checkout test',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => '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 ./dist tester@testhost:/var/www/test',
|
||||
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:warmup --env=dev"',
|
||||
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assets:install web --env=dev --symlink --relative"',
|
||||
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console cache:pool:prune --env=dev"',
|
||||
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "cd /var/www/test && bin/console assetic:dump --env=dev"',
|
||||
9 => 'git checkout master',
|
||||
);
|
||||
|
||||
|
@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\Releases\ListCommand;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class ListCommandTest extends TestCase
|
||||
{
|
||||
|
@ -14,7 +14,7 @@ use Mage\Command\BuiltIn\Releases\RollbackCommand;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class RollbackCommandTest extends TestCase
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ use Mage\Command\BuiltIn\VersionCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Mage\Mage;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class VersionCommandTest extends TestCase
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ use Mage\Deploy\Strategy\RsyncStrategy;
|
||||
use Mage\Runtime\Exception\RuntimeException;
|
||||
use Mage\Runtime\Runtime;
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class StrategyTest extends TestCase
|
||||
{
|
||||
|
@ -14,7 +14,7 @@ use Mage\MageApplication;
|
||||
use Mage\Runtime\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Tester\ApplicationTester;
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class MageApplicationTest extends TestCase
|
||||
{
|
||||
|
@ -21,7 +21,7 @@ magephp:
|
||||
on-deploy:
|
||||
- symfony/cache-warmup: { env: 'dev' }
|
||||
- symfony/assets-install: { env: 'dev' }
|
||||
- symfony/cache-pool-prune: { env: 'dev' }
|
||||
- symfony/assetic-dump: { env: 'dev' }
|
||||
on-release:
|
||||
post-release:
|
||||
post-deploy:
|
@ -1,19 +0,0 @@
|
||||
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' }
|
@ -1,13 +0,0 @@
|
||||
magephp:
|
||||
environments:
|
||||
production:
|
||||
user: app
|
||||
host_path: /var/www/myapp
|
||||
hosts:
|
||||
- webserver
|
||||
pre-deploy:
|
||||
on-deploy:
|
||||
- custom-invalid-class
|
||||
post-deploy:
|
||||
custom_tasks:
|
||||
- Mage\Tests\Task\Custom\InvalidClass
|
@ -1,13 +0,0 @@
|
||||
magephp:
|
||||
environments:
|
||||
production:
|
||||
user: app
|
||||
host_path: /var/www/myapp
|
||||
hosts:
|
||||
- webserver
|
||||
pre-deploy:
|
||||
on-deploy:
|
||||
- custom-invalid-inheritance
|
||||
post-deploy:
|
||||
custom_tasks:
|
||||
- Mage\Tests\Task\Custom\InvalidInheritanceTask
|
@ -1,13 +0,0 @@
|
||||
magephp:
|
||||
environments:
|
||||
production:
|
||||
user: app
|
||||
host_path: /var/www/myapp
|
||||
hosts:
|
||||
- webserver
|
||||
pre-deploy:
|
||||
on-deploy:
|
||||
- custom-not-instantiable
|
||||
post-deploy:
|
||||
custom_tasks:
|
||||
- Mage\Tests\Task\Custom\NotInstantiableTask
|
@ -1,13 +0,0 @@
|
||||
magephp:
|
||||
environments:
|
||||
production:
|
||||
user: app
|
||||
host_path: /var/www/myapp
|
||||
hosts:
|
||||
- webserver
|
||||
pre-deploy:
|
||||
on-deploy:
|
||||
- custom-valid
|
||||
post-deploy:
|
||||
custom_tasks:
|
||||
- Mage\Tests\Task\Custom\ValidTask
|
@ -1,17 +0,0 @@
|
||||
magephp:
|
||||
log_dir: /tmp
|
||||
composer:
|
||||
path: /usr/bin/composer.phar
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
environments:
|
||||
test:
|
||||
user: tester
|
||||
host_path: /var/www/test
|
||||
hosts:
|
||||
- testhost
|
||||
pre-deploy:
|
||||
- composer/install: { flags: '--prefer-source' }
|
||||
- composer/dump-autoload: { flags: '--no-scripts' }
|
@ -1,27 +0,0 @@
|
||||
magephp:
|
||||
log_dir: /no-temp
|
||||
environments:
|
||||
production:
|
||||
user: app
|
||||
branch: master
|
||||
host_path: /var/www/myapp
|
||||
releases: 4
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
hosts:
|
||||
- webserver1
|
||||
- webserver2
|
||||
- webserver3
|
||||
pre-deploy:
|
||||
- git/update
|
||||
- composer/install
|
||||
- composer/dump-autoload
|
||||
on-deploy:
|
||||
- symfony/cache-warmup: { env: 'dev' }
|
||||
- symfony/assets-install: { env: 'dev' }
|
||||
- symfony/cache-pool-prune: { env: 'dev' }
|
||||
on-release:
|
||||
post-release:
|
||||
post-deploy:
|
@ -17,7 +17,7 @@ magephp:
|
||||
on-deploy:
|
||||
- symfony/cache-warmup: { env: 'dev' }
|
||||
- symfony/assets-install: { env: 'dev' }
|
||||
- symfony/cache-pool-prune: { env: 'dev' }
|
||||
- symfony/assetic-dump: { env: 'dev' }
|
||||
on-release:
|
||||
post-release:
|
||||
post-deploy:
|
@ -14,7 +14,5 @@ magephp:
|
||||
on-deploy:
|
||||
- symfony/cache-warmup
|
||||
- symfony/assets-install
|
||||
- symfony/cache-pool-prune
|
||||
- symfony/cache-pool-prune: { env: 'prod' }
|
||||
- symfony/cache-pool-clear: { pools: 'main' }
|
||||
- symfony/cache-pool-clear: { env: 'prod', pools: 'main' }
|
||||
- symfony/assetic-dump
|
||||
- symfony/assetic-dump: { env: 'prod' }
|
||||
|
@ -18,7 +18,7 @@ magephp:
|
||||
on-deploy:
|
||||
- symfony/cache-warmup: { env: 'dev' }
|
||||
- symfony/assets-install: { env: 'dev' }
|
||||
- symfony/cache-pool-prune: { env: 'dev' }
|
||||
- symfony/assetic-dump: { env: 'dev' }
|
||||
on-release:
|
||||
post-release:
|
||||
post-deploy:
|
@ -20,7 +20,7 @@ magephp:
|
||||
- symfony/cache-clear: { env: 'dev' }
|
||||
- symfony/cache-warmup: { env: 'dev' }
|
||||
- symfony/assets-install: { env: 'dev' }
|
||||
- symfony/cache-pool-prune: { env: 'dev' }
|
||||
- symfony/assetic-dump: { env: 'dev' }
|
||||
on-release:
|
||||
post-release:
|
||||
post-deploy:
|
@ -1,28 +0,0 @@
|
||||
magephp:
|
||||
log_dir: /tmp
|
||||
environments:
|
||||
test:
|
||||
user: tester
|
||||
branch: test
|
||||
from: ./dist
|
||||
host_path: /var/www/test
|
||||
releases: 4
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
-
|
||||
-
|
||||
hosts:
|
||||
- testhost
|
||||
pre-deploy:
|
||||
- git/update
|
||||
- composer/install
|
||||
- composer/dump-autoload
|
||||
on-deploy:
|
||||
- symfony/cache-warmup: { env: 'dev' }
|
||||
- symfony/assets-install: { env: 'dev' }
|
||||
- symfony/cache-pool-prune: { env: 'dev' }
|
||||
on-release:
|
||||
post-release:
|
||||
post-deploy:
|
@ -1,27 +0,0 @@
|
||||
magephp:
|
||||
log_dir: /tmp
|
||||
environments:
|
||||
test:
|
||||
user: tester
|
||||
branch: test
|
||||
host_path: /var/www/test
|
||||
releases: 4
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
-
|
||||
-
|
||||
hosts:
|
||||
- testhost:202
|
||||
pre-deploy:
|
||||
- git/update
|
||||
- composer/install
|
||||
- composer/dump-autoload
|
||||
on-deploy:
|
||||
- symfony/cache-warmup: { env: 'prod' }
|
||||
- symfony/assets-install: { env: 'prod' }
|
||||
- symfony/cache-pool-prune: { env: 'prod' }
|
||||
on-release:
|
||||
post-release:
|
||||
post-deploy:
|
@ -1,25 +0,0 @@
|
||||
magephp:
|
||||
log_dir: /tmp
|
||||
environments:
|
||||
test:
|
||||
user: tester
|
||||
branch: test
|
||||
from: ./dist
|
||||
host_path: /var/www/test
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
hosts:
|
||||
- testhost
|
||||
pre-deploy:
|
||||
- git/update
|
||||
- composer/install
|
||||
- composer/dump-autoload
|
||||
on-deploy:
|
||||
- symfony/cache-warmup: { env: 'dev' }
|
||||
- symfony/assets-install: { env: 'dev' }
|
||||
- symfony/cache-pool-prune: { env: 'dev' }
|
||||
on-release:
|
||||
post-release:
|
||||
post-deploy:
|
@ -1,24 +0,0 @@
|
||||
magephp:
|
||||
log_dir: /tmp
|
||||
environments:
|
||||
test:
|
||||
user: tester
|
||||
branch: test
|
||||
host_path: /var/www/test
|
||||
exclude:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
hosts:
|
||||
- testhost:202
|
||||
pre-deploy:
|
||||
- git/update
|
||||
- composer/install
|
||||
- composer/dump-autoload
|
||||
on-deploy:
|
||||
- symfony/cache-warmup: { env: 'dev' }
|
||||
- symfony/assets-install: { env: 'dev' }
|
||||
- symfony/cache-pool-prune: { env: 'dev' }
|
||||
on-release:
|
||||
post-release:
|
||||
post-deploy:
|
@ -18,7 +18,7 @@ magephp:
|
||||
on-deploy:
|
||||
- symfony/cache-warmup: { env: 'dev' }
|
||||
- symfony/assets-install: { env: 'dev' }
|
||||
- symfony/cache-pool-prune: { env: 'dev' }
|
||||
- symfony/assetic-dump: { env: 'dev' }
|
||||
on-release:
|
||||
post-release:
|
||||
post-deploy:
|
@ -10,8 +10,6 @@ magephp:
|
||||
- ./var/cache/*
|
||||
- ./var/log/*
|
||||
- ./web/app_dev.php
|
||||
-
|
||||
-
|
||||
hosts:
|
||||
- testhost
|
||||
pre-deploy:
|
||||
@ -21,7 +19,7 @@ magephp:
|
||||
on-deploy:
|
||||
- symfony/cache-warmup: { env: 'dev' }
|
||||
- symfony/assets-install: { env: 'dev' }
|
||||
- symfony/cache-pool-prune: { env: 'dev' }
|
||||
- symfony/assetic-dump: { env: 'dev' }
|
||||
on-release:
|
||||
post-release:
|
||||
post-deploy:
|
@ -19,7 +19,7 @@ class ProcessMockup extends Process
|
||||
protected $timeout;
|
||||
protected $success = true;
|
||||
|
||||
public function __construct($commandline, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60)
|
||||
public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array())
|
||||
{
|
||||
$this->commandline = $commandline;
|
||||
}
|
||||
@ -29,7 +29,7 @@ class ProcessMockup extends Process
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
|
||||
public function run(callable $callback = null, array $env = array()): int
|
||||
public function run($callback = null)
|
||||
{
|
||||
if (in_array($this->commandline, $this->forceFail)) {
|
||||
$this->success = false;
|
||||
@ -50,12 +50,6 @@ class ProcessMockup extends Process
|
||||
if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@hostdemo2 "ls -1 /var/www/test/releases"') {
|
||||
$this->success = false;
|
||||
}
|
||||
|
||||
if (!$this->success) {
|
||||
return 10;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function isSuccessful()
|
||||
@ -74,29 +68,6 @@ class ProcessMockup extends Process
|
||||
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"') {
|
||||
return implode(PHP_EOL, ['20170101015110', '20170101015111', '20170101015112', '20170101015113', '20170101015114', '20170101015115', '20170101015116', '20170101015117']);
|
||||
}
|
||||
@ -105,14 +76,6 @@ class ProcessMockup extends Process
|
||||
return '/var/www/test/releases/20170101015117';
|
||||
}
|
||||
|
||||
if ($this->commandline == 'ssh -p 202 -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']);
|
||||
}
|
||||
|
||||
if ($this->commandline == 'ssh -p 202 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "readlink -f /var/www/test/current"') {
|
||||
return '/var/www/test/releases/20170101015117';
|
||||
}
|
||||
|
||||
if ($this->commandline == 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@host1 "ls -1 /var/www/test/releases"') {
|
||||
return implode(PHP_EOL, ['20170101015110', '20170101015111', '20170101015112', '20170101015113', '20170101015114', '20170101015115', '20170101015116', '20170101015117']);
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ use Symfony\Component\Process\Process;
|
||||
class RuntimeMockup extends Runtime
|
||||
{
|
||||
protected $ranCommands = [];
|
||||
protected $ranCommandTimeouts = [];
|
||||
protected $forceFail = [];
|
||||
|
||||
public function getRanCommands()
|
||||
@ -24,11 +23,6 @@ class RuntimeMockup extends Runtime
|
||||
return $this->ranCommands;
|
||||
}
|
||||
|
||||
public function getRanCommandTimeoutFor($cmd)
|
||||
{
|
||||
return isset($this->ranCommandTimeouts[$cmd]) ? $this->ranCommandTimeouts[$cmd] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the Release ID
|
||||
*
|
||||
@ -50,7 +44,6 @@ class RuntimeMockup extends Runtime
|
||||
public function runLocalCommand($cmd, $timeout = 120)
|
||||
{
|
||||
$this->ranCommands[] = $cmd;
|
||||
$this->ranCommandTimeouts[$cmd] = $timeout;
|
||||
|
||||
$process = new ProcessMockup($cmd);
|
||||
$process->forceFail = $this->forceFail;
|
||||
|
@ -15,7 +15,7 @@ use Mage\Runtime\Runtime;
|
||||
use Exception;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Handler\TestHandler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
use Psr\Log\LogLevel;
|
||||
use Symfony\Component\Process\Process;
|
||||
use DateTime;
|
||||
@ -119,20 +119,6 @@ class RuntimeTest extends TestCase
|
||||
$this->assertEquals('-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no', $sshConfig['flags']);
|
||||
}
|
||||
|
||||
public function testSSHConfigPortDefinedInHostNotation()
|
||||
{
|
||||
$runtime = new Runtime();
|
||||
$runtime->setWorkingHost('223.12.24.64:1056');
|
||||
$sshConfig = $runtime->getSSHConfig();
|
||||
|
||||
$this->assertEquals('1056', $sshConfig['port']);
|
||||
|
||||
$runtime->setWorkingHost('223.12.24.64');
|
||||
$sshConfig = $runtime->getSSHConfig();
|
||||
|
||||
$this->assertEquals('22', $sshConfig['port']);
|
||||
}
|
||||
|
||||
public function testSSHConfigEmptyOptions()
|
||||
{
|
||||
$runtime = new Runtime();
|
||||
|
@ -12,7 +12,7 @@ namespace Mage\Tests\Task;
|
||||
|
||||
use Mage\Task\Exception\ErrorException;
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class AbstractTaskTest extends TestCase
|
||||
{
|
||||
|
@ -1,43 +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\Composer;
|
||||
|
||||
use Mage\Task\BuiltIn\Composer\AbstractComposerTask;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* Basic Composer Task
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
class BasicComposerTask extends AbstractComposerTask
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'composer/help';
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return '[Composer] Help';
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
$cmd = sprintf('%s help', $options['path']);
|
||||
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand(trim($cmd));
|
||||
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Mage\Tests\Task\BuiltIn\Composer;
|
||||
|
||||
use Mage\Tests\Runtime\RuntimeMockup;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BasicComposerTaskTest extends TestCase
|
||||
{
|
||||
public function testBasicTask()
|
||||
{
|
||||
$runtime = new RuntimeMockup();
|
||||
$runtime->setConfiguration(['environments' => ['test' => []]]);
|
||||
$runtime->setEnvironment('test');
|
||||
|
||||
$task = new BasicComposerTask();
|
||||
$task->setRuntime($runtime);
|
||||
$this->assertEquals('[Composer] Help', $task->getDescription());
|
||||
|
||||
$task->execute();
|
||||
|
||||
$ranCommands = $runtime->getRanCommands();
|
||||
$testCase = array(
|
||||
0 => 'composer help',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,174 +0,0 @@
|
||||
<?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;
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,97 +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\ExecTask;
|
||||
use Exception;
|
||||
use Mage\Tests\Runtime\RuntimeMockup;
|
||||
use PHPUnit\Framework\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());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,127 +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\FileSystem;
|
||||
|
||||
use Mage\Task\Exception\ErrorException;
|
||||
use Mage\Task\BuiltIn\FS\ChangeModeTask;
|
||||
use Exception;
|
||||
use Mage\Tests\Runtime\RuntimeMockup;
|
||||
use PHPUnit\Framework\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());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,158 +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\FileSystem;
|
||||
|
||||
use Mage\Task\Exception\ErrorException;
|
||||
use Mage\Task\BuiltIn\FS\CopyTask;
|
||||
use Exception;
|
||||
use Mage\Tests\Runtime\RuntimeMockup;
|
||||
use PHPUnit\Framework\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());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,127 +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\FileSystem;
|
||||
|
||||
use Mage\Task\Exception\ErrorException;
|
||||
use Mage\Task\BuiltIn\FS\LinkTask;
|
||||
use Exception;
|
||||
use Mage\Tests\Runtime\RuntimeMockup;
|
||||
use PHPUnit\Framework\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());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,127 +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\FileSystem;
|
||||
|
||||
use Mage\Task\Exception\ErrorException;
|
||||
use Mage\Task\BuiltIn\FS\MoveTask;
|
||||
use Exception;
|
||||
use Mage\Tests\Runtime\RuntimeMockup;
|
||||
use PHPUnit\Framework\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());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,124 +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\FileSystem;
|
||||
|
||||
use Mage\Task\Exception\ErrorException;
|
||||
use Mage\Task\BuiltIn\FS\RemoveTask;
|
||||
use Exception;
|
||||
use Mage\Tests\Runtime\RuntimeMockup;
|
||||
use PHPUnit\Framework\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());
|
||||
}
|
||||
}
|
||||
}
|
364
tests/Task/BuiltIn/FileSystemTaskTest.php
Normal file
364
tests/Task/BuiltIn/FileSystemTaskTest.php
Normal file
@ -0,0 +1,364 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Mage\tests\Task\BuiltIn\Symfony;
|
||||
|
||||
|
||||
use Mage\Task\BuiltIn\Symfony\CachePoolClearTask;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Mage\Tests\Runtime\RuntimeMockup;
|
||||
use Mage\Task\Exception\ErrorException;
|
||||
|
||||
class CachePoolClearTaskTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var RuntimeMockup
|
||||
*/
|
||||
private $runtime;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->runtime = new RuntimeMockup();
|
||||
$this->runtime->setConfiguration(['environments' => ['test' => []]]);
|
||||
$this->runtime->setEnvironment('test');
|
||||
}
|
||||
|
||||
public function testAsseticDumpTask()
|
||||
{
|
||||
$task = new CachePoolClearTask();
|
||||
$task->setOptions(['env' => 'test']);
|
||||
$task->setRuntime($this->runtime);
|
||||
$this->assertEquals('[Symfony] Cache Pool Clear', $task->getDescription());
|
||||
|
||||
try {
|
||||
$task->execute();
|
||||
} catch (ErrorException $exception) {
|
||||
$this->assertEquals('Parameter "pools" is not defined', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,47 +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\Custom;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* Custom PreRegistered Task for Testing
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
class InvalidInheritanceTask
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'custom-invalid-inheritance';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return '[Custom] Invalid Inheritance*';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand('echo "custom-invalid-inheritance"');
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
}
|
@ -1,48 +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\Custom;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* Custom PreRegistered Task for Testing
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
abstract class NotInstantiableTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'custom-not-instantiable';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return '[Custom] Not Instantiable*';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand('echo "custom-not-instantiable"');
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
}
|
@ -1,48 +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\Custom;
|
||||
|
||||
use Mage\Task\AbstractTask;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* Custom PreRegistered Task for Testing
|
||||
*
|
||||
* @author Andrés Montañez <andresmontanez@gmail.com>
|
||||
*/
|
||||
class ValidTask extends AbstractTask
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'custom-valid';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return '[Custom] Valid*';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Process $process */
|
||||
$process = $this->runtime->runCommand('echo "custom-valid"');
|
||||
return $process->isSuccessful();
|
||||
}
|
||||
}
|
@ -10,15 +10,11 @@
|
||||
|
||||
namespace Mage\Tests\Task;
|
||||
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Command\BuiltIn\DeployCommand;
|
||||
use Mage\Task\TaskFactory;
|
||||
use Mage\Runtime\Runtime;
|
||||
use Mage\Runtime\Exception\RuntimeException;
|
||||
use Exception;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class TaskFactoryTest extends TestCase
|
||||
{
|
||||
@ -47,83 +43,4 @@ class TaskFactoryTest extends TestCase
|
||||
$this->assertEquals('Invalid task name "stdClass"', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testPreRegisteredCustomTask()
|
||||
{
|
||||
$application = new MageApplicationMockup(__DIR__ . '/../Resources/custom-task.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'production']);
|
||||
|
||||
$this->assertContains('[Custom] Valid*', $tester->getDisplay());
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git ./ app@webserver:/var/www/myapp',
|
||||
1 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no app@webserver "cd /var/www/myapp && echo \"custom-valid\""',
|
||||
);
|
||||
|
||||
// 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 testPreRegisteredCustomTaskInvalidClass()
|
||||
{
|
||||
$application = new MageApplicationMockup(__DIR__ . '/../Resources/custom-task-invalid-class.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'production']);
|
||||
|
||||
$this->assertContains('Custom Task "Mage\Tests\Task\Custom\InvalidClass" does not exists.', $tester->getDisplay());
|
||||
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testPreRegisteredCustomTaskNonInstantiable()
|
||||
{
|
||||
$application = new MageApplicationMockup(__DIR__ . '/../Resources/custom-task-not-instantiable.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'production']);
|
||||
|
||||
$this->assertContains('Custom Task "Mage\Tests\Task\Custom\NotInstantiableTask" can not be instantiated.', $tester->getDisplay());
|
||||
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testPreRegisteredCustomTaskInvalidInheritance()
|
||||
{
|
||||
$application = new MageApplicationMockup(__DIR__ . '/../Resources/custom-task-invalid-inheritance.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'production']);
|
||||
|
||||
$this->assertContains('Custom Task "Mage\Tests\Task\Custom\InvalidInheritanceTask" must inherit "Mage\Task\AbstractTask".', $tester->getDisplay());
|
||||
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace Mage\Tests;
|
||||
use Mage\Utils;
|
||||
use Mage\Runtime\Runtime;
|
||||
use DateTime;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class UtilsTest extends TestCase
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user