Deployer: Tests before deploy

Created on 23 May 2015  路  7Comments  路  Source: deployphp/deployer

I use in my application, Is there any way for run this tests before deploy?

Currently, i run manually this tests with following script

$app = new Application('Codeception', Codecept::VERSION);
$app->setAutoExit(false);
$app->add(new Build('build'));
$app->add(new Run('run'));
$app->run(new ArrayInput( array('build') ));

$test = (isset($opts['t'])) ? $opts['t'] : '';
$coverage = (isset($opts['c'])) ? ' --coverage-html --coverage-xml' : '';

$app->run(new StringInput( 'run unit ' . $test . ' ' . $coverage) );

Most helpful comment

You can run tests locally too:

task('test', function () {
    runLocally('cd project_dir && php vendor/bin/phpunit');
});

before('deploy', 'test');

All 7 comments

Another problem is that composer execute with param --no-dev

https://github.com/deployphp/deployer/blob/master/recipe/common.php#L235

@leandrogehlen , I think you can override this task for your case.
Add this code to deploy.php file, after line require 'recipe/common.php';

/**
 * Installing vendors tasks.
 */
task('deploy:vendors', function () {
    if (commandExist('composer')) {
        $composer = 'composer';
    } else {
        run("cd {{release_path}} && curl -sS https://getcomposer.org/installer | php");
        $composer = 'php composer.phar';
    }
    run("cd {{release_path}} && {{env_vars}} $composer install --dev --verbose --prefer-dist --optimize-autoloader --no-progress --no-interaction");
})->desc('Installing vendors');

You can run tests locally too:

task('test', function () {
    runLocally('cd project_dir && php vendor/bin/phpunit');
});

before('deploy', 'test');

i made what @oanhnn suggested,

I think it could be created stage dependencies.
This means, the production stage occurs after the test stage, but if test fail does not will run production

The problem of the tests run locally, that is, will not be replicated deploy routine.
thus, it is necessary, update sources and composer manually

I added deploy:vendors-dev task. Why don't you add a task like this to common.php?

task('deploy:vendors-dev', function () {
    if (commandExist('composer')) {
        $composer = 'composer';
    } else {
        run("cd {{release_path}} && curl -sS https://getcomposer.org/installer | php");
        $composer = 'php composer.phar';
    }

    run("cd {{release_path}} && $composer install --verbose --prefer-dist --no-progress --no-interaction");
})->desc('Installing vendors including require-dev');

@kenjis i think that should be used is a param like set('composer_args', '--no-dev');
@elfet what do you think?

@lasselehtinen We run the task (composer install) twice. One is for testing, the other is for deployment. So, I think two tasks, deploy:vendors-dev and deploy:vendors are easy to understand.

Is it possible to use set()?

Was this page helpful?
0 / 5 - 0 ratings