From 3695fdd651e302e5f1f6f3bbc171bcd3c9b89d3d Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Wed, 10 Jul 2013 20:41:02 +0200 Subject: [PATCH 1/5] Add check for SCM --- src/Rocketeer/Scm/Git.php | 27 ++++++++++++++++++++++----- src/Rocketeer/Scm/Scm.php | 6 ++++++ src/Rocketeer/Tasks/Check.php | 18 ++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/Rocketeer/Scm/Git.php b/src/Rocketeer/Scm/Git.php index 37d0f08ae..4ecfd3326 100644 --- a/src/Rocketeer/Scm/Git.php +++ b/src/Rocketeer/Scm/Git.php @@ -16,6 +16,13 @@ class Git implements Scm */ protected $app; + /** + * The core binary + * + * @var string + */ + public $binary = 'git'; + /** * Build a new Git instance * @@ -30,6 +37,16 @@ public function __construct($app) ///////////////////////////// INFORMATIONS ///////////////////////// //////////////////////////////////////////////////////////////////// + /** + * Check if the SCM is available + * + * @return string + */ + public function check() + { + return $this->binary. ' --version'; + } + /** * Get the current state * @@ -37,7 +54,7 @@ public function __construct($app) */ public function currentState() { - return 'git rev-parse HEAD'; + return $this->binary. ' rev-parse HEAD'; } /** @@ -47,7 +64,7 @@ public function currentState() */ public function currentBranch() { - return 'git rev-parse --abbrev-ref HEAD'; + return $this->binary. ' rev-parse --abbrev-ref HEAD'; } //////////////////////////////////////////////////////////////////// @@ -66,7 +83,7 @@ public function checkout($destination) $branch = $this->app['rocketeer.rocketeer']->getRepositoryBranch(); $repository = $this->app['rocketeer.rocketeer']->getRepository(); - return sprintf('git clone -b %s %s %s', $branch, $repository, $destination); + return sprintf($this->binary. ' clone -b %s %s %s', $branch, $repository, $destination); } /** @@ -76,7 +93,7 @@ public function checkout($destination) */ public function reset() { - return 'git reset --hard'; + return $this->binary. ' reset --hard'; } /** @@ -86,6 +103,6 @@ public function reset() */ public function update() { - return 'git pull'; + return $this->binary. ' pull'; } } diff --git a/src/Rocketeer/Scm/Scm.php b/src/Rocketeer/Scm/Scm.php index 46983233f..1076e3b43 100644 --- a/src/Rocketeer/Scm/Scm.php +++ b/src/Rocketeer/Scm/Scm.php @@ -6,6 +6,12 @@ */ interface Scm { + /** + * Check if the SCM is available + * + * @return string + */ + public function check(); /** * Get the current state diff --git a/src/Rocketeer/Tasks/Check.php b/src/Rocketeer/Tasks/Check.php index dae449bfc..3f933a17c 100644 --- a/src/Rocketeer/Tasks/Check.php +++ b/src/Rocketeer/Tasks/Check.php @@ -33,6 +33,11 @@ public function execute() $errors = array(); $extension = 'The %s extension does not seem to be loaded on the server'; + // Check SCM + if (!$this->checkScm()) { + $errors[] = $this->command->error($this->scm->binary . ' could not be found on the server'); + } + // Check PHP if (!$this->checkPhpVersion()) { $errors[] = $this->command->error('The version of PHP on the server does not match Laravel\'s requirements'); @@ -76,6 +81,19 @@ public function execute() /////////////////////////////// HELPERS //////////////////////////// //////////////////////////////////////////////////////////////////// + /** + * Check the presence of an SCM on the server + * + * @return boolean + */ + public function checkScm() + { + $this->command->comment('Checking presence of '.$this->scm->binary); + $this->run($this->scm->check()); + + return $this->remote->status() == 0; + } + /** * Check if Composer is on the server * From 100d52d635f44b8fdb77a78a9b532d69a2e3411e Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Wed, 10 Jul 2013 20:44:58 +0200 Subject: [PATCH 2/5] Fix wrong use of composer.phar --- src/Rocketeer/Tasks/Abstracts/Task.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rocketeer/Tasks/Abstracts/Task.php b/src/Rocketeer/Tasks/Abstracts/Task.php index adf0caf5b..6a0b8b559 100644 --- a/src/Rocketeer/Tasks/Abstracts/Task.php +++ b/src/Rocketeer/Tasks/Abstracts/Task.php @@ -238,7 +238,7 @@ public function getComposer() { $composer = $this->which('composer'); if (!$composer and file_exists($this->app['path.base'].'/composer.phar')) { - $composer = 'composer.phar'; + $composer = 'php composer.phar'; } return $composer; From 69f976689821f3736aa3fa402b21f32e6de9293d Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Thu, 11 Jul 2013 00:41:40 +0200 Subject: [PATCH 3/5] Move Traits to a Traits folder --- CHANGELOG.md | 7 +++- composer.lock | 8 ++-- src/Rocketeer/Commands/BaseTaskCommand.php | 2 +- src/Rocketeer/Facades/Rocketeer.php | 1 - src/Rocketeer/Scm/Git.php | 33 ++++----------- .../Scm/{Scm.php => ScmInterface.php} | 2 +- src/Rocketeer/Tasks/Check.php | 2 +- src/Rocketeer/Tasks/Cleanup.php | 2 +- src/Rocketeer/Tasks/Closure.php | 2 +- src/Rocketeer/Tasks/CurrentRelease.php | 2 +- src/Rocketeer/Tasks/Deploy.php | 2 +- src/Rocketeer/Tasks/Rollback.php | 2 +- src/Rocketeer/Tasks/Setup.php | 2 +- src/Rocketeer/Tasks/Teardown.php | 2 +- src/Rocketeer/Tasks/Test.php | 2 +- src/Rocketeer/Tasks/Update.php | 2 +- src/Rocketeer/TasksQueue.php | 2 +- src/Rocketeer/Traits/Scm.php | 41 +++++++++++++++++++ .../{Tasks/Abstracts => Traits}/Task.php | 2 +- src/config/config.php | 2 +- tests/TasksQueueTest.php | 2 +- tests/meta/coverage.txt | 38 +++++------------ 22 files changed, 86 insertions(+), 74 deletions(-) rename src/Rocketeer/Scm/{Scm.php => ScmInterface.php} (96%) create mode 100644 src/Rocketeer/Traits/Scm.php rename src/Rocketeer/{Tasks/Abstracts => Traits}/Task.php (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index de233e7f7..fb17124c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,12 @@ - Ability to select which severs a Task executes on, on a per-task basis -### 0.6.1 (stable) +### 0.6.2 (stable) + +- Make the Check task check for the remote presence of the configured SCM +- Fix Rocketeer not being able to use a `composer.phar` on the server + +### 0.6.1 - Fix a bug where the configured user would not have the rights to set permissions diff --git a/composer.lock b/composer.lock index e0cf068e5..2edded12d 100644 --- a/composer.lock +++ b/composer.lock @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/illuminate/support.git", - "reference": "1613f0fecd258a5fab083d0570ff360fcfd4ca0c" + "reference": "c5175eabb5e992096d8853d438aed072fca1e7bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/illuminate/support/zipball/1613f0fecd258a5fab083d0570ff360fcfd4ca0c", - "reference": "1613f0fecd258a5fab083d0570ff360fcfd4ca0c", + "url": "https://api.github.com/repos/illuminate/support/zipball/c5175eabb5e992096d8853d438aed072fca1e7bb", + "reference": "c5175eabb5e992096d8853d438aed072fca1e7bb", "shasum": "" }, "require": { @@ -52,7 +52,7 @@ "email": "taylorotwell@gmail.com" } ], - "time": "2013-07-09 02:35:44" + "time": "2013-07-09 13:05:22" } ], "packages-dev": [ diff --git a/src/Rocketeer/Commands/BaseTaskCommand.php b/src/Rocketeer/Commands/BaseTaskCommand.php index d2f96447e..acf35a1d7 100644 --- a/src/Rocketeer/Commands/BaseTaskCommand.php +++ b/src/Rocketeer/Commands/BaseTaskCommand.php @@ -2,7 +2,7 @@ namespace Rocketeer\Commands; use Rocketeer\Rocketeer; -use Rocketeer\Tasks\Abstracts\Task; +use Rocketeer\Traits\Task; /** * A basic command that only runs one Task diff --git a/src/Rocketeer/Facades/Rocketeer.php b/src/Rocketeer/Facades/Rocketeer.php index d32a9c82f..c5a23c2bc 100644 --- a/src/Rocketeer/Facades/Rocketeer.php +++ b/src/Rocketeer/Facades/Rocketeer.php @@ -8,7 +8,6 @@ */ class Rocketeer extends Facade { - /** * Get the registered name of the component. * diff --git a/src/Rocketeer/Scm/Git.php b/src/Rocketeer/Scm/Git.php index 4ecfd3326..dd7df2ed7 100644 --- a/src/Rocketeer/Scm/Git.php +++ b/src/Rocketeer/Scm/Git.php @@ -2,20 +2,13 @@ namespace Rocketeer\Scm; use Illuminate\Container\Container; +use Rocketeer\Traits\Scm; /** * The Git SCM */ -class Git implements Scm +class Git extends Scm implements ScmInterface { - - /** - * The IoC Container - * - * @var Container - */ - protected $app; - /** * The core binary * @@ -23,16 +16,6 @@ class Git implements Scm */ public $binary = 'git'; - /** - * Build a new Git instance - * - * @param Container $app - */ - public function __construct($app) - { - $this->app = $app; - } - //////////////////////////////////////////////////////////////////// ///////////////////////////// INFORMATIONS ///////////////////////// //////////////////////////////////////////////////////////////////// @@ -44,7 +27,7 @@ public function __construct($app) */ public function check() { - return $this->binary. ' --version'; + return $this->getCommand('--version'); } /** @@ -54,7 +37,7 @@ public function check() */ public function currentState() { - return $this->binary. ' rev-parse HEAD'; + return $this->getCommand('rev-parse HEAD'); } /** @@ -64,7 +47,7 @@ public function currentState() */ public function currentBranch() { - return $this->binary. ' rev-parse --abbrev-ref HEAD'; + return $this->getCommand('rev-parse --abbrev-ref HEAD'); } //////////////////////////////////////////////////////////////////// @@ -83,7 +66,7 @@ public function checkout($destination) $branch = $this->app['rocketeer.rocketeer']->getRepositoryBranch(); $repository = $this->app['rocketeer.rocketeer']->getRepository(); - return sprintf($this->binary. ' clone -b %s %s %s', $branch, $repository, $destination); + return sprintf($this->getCommand('clone -b %s %s %s'), $branch, $repository, $destination); } /** @@ -93,7 +76,7 @@ public function checkout($destination) */ public function reset() { - return $this->binary. ' reset --hard'; + return $this->getCommand('reset --hard'); } /** @@ -103,6 +86,6 @@ public function reset() */ public function update() { - return $this->binary. ' pull'; + return $this->getCommand('pull'); } } diff --git a/src/Rocketeer/Scm/Scm.php b/src/Rocketeer/Scm/ScmInterface.php similarity index 96% rename from src/Rocketeer/Scm/Scm.php rename to src/Rocketeer/Scm/ScmInterface.php index 1076e3b43..03a83d5ce 100644 --- a/src/Rocketeer/Scm/Scm.php +++ b/src/Rocketeer/Scm/ScmInterface.php @@ -4,7 +4,7 @@ /** * The interface for all SCMs */ -interface Scm +interface ScmInterface { /** * Check if the SCM is available diff --git a/src/Rocketeer/Tasks/Check.php b/src/Rocketeer/Tasks/Check.php index 3f933a17c..366bc7351 100644 --- a/src/Rocketeer/Tasks/Check.php +++ b/src/Rocketeer/Tasks/Check.php @@ -1,7 +1,7 @@ app = $app; + } + + //////////////////////////////////////////////////////////////////// + //////////////////////////////// HELPERS /////////////////////////// + //////////////////////////////////////////////////////////////////// + + /** + * Returns a command with the SCM's binary + * + * @param string $command + * + * @return string + */ + public function getCommand($command) + { + return $this->binary. ' ' .$command; + } +} \ No newline at end of file diff --git a/src/Rocketeer/Tasks/Abstracts/Task.php b/src/Rocketeer/Traits/Task.php similarity index 99% rename from src/Rocketeer/Tasks/Abstracts/Task.php rename to src/Rocketeer/Traits/Task.php index 6a0b8b559..76addca1c 100644 --- a/src/Rocketeer/Tasks/Abstracts/Task.php +++ b/src/Rocketeer/Traits/Task.php @@ -1,5 +1,5 @@ tasksQueue()->buildTask('Rocketeer\Tasks\Deploy'); - $this->assertInstanceOf('Rocketeer\Tasks\Abstracts\Task', $task); + $this->assertInstanceOf('Rocketeer\Traits\Task', $task); } public function testCanGetTasksBeforeOrAfterAnotherTask() diff --git a/tests/meta/coverage.txt b/tests/meta/coverage.txt index 955e33a52..56fc5542a 100644 --- a/tests/meta/coverage.txt +++ b/tests/meta/coverage.txt @@ -1,40 +1,24 @@ Code Coverage Report - 2013-07-06 18:32:38 + 2013-07-11 00:43:25 Summary: - Classes: 52.94% (9/17) - Methods: 83.96% (89/106) - Lines: 84.02% (410/488) + Classes: 11.11% (2/18) + Methods: 31.48% (34/108) + Lines: 24.54% (134/546) \Rocketeer::Bash - Methods: 100.00% (15/15) Lines: 91.78% ( 67/ 73) + Methods: 66.67% (10/15) Lines: 66.67% ( 50/ 75) \Rocketeer::ReleasesManager Methods: 100.00% ( 9/ 9) Lines: 100.00% ( 19/ 19) \Rocketeer::Rocketeer - Methods: 100.00% (13/13) Lines: 100.00% ( 41/ 41) + Methods: 61.54% ( 8/13) Lines: 66.67% ( 28/ 42) \Rocketeer::Server - Methods: 100.00% ( 9/ 9) Lines: 100.00% ( 34/ 34) + Methods: 100.00% ( 9/ 9) Lines: 73.53% ( 25/ 34) \Rocketeer::TasksQueue - Methods: 100.00% (15/15) Lines: 88.89% ( 88/ 99) + Methods: 20.00% ( 3/15) Lines: 11.11% ( 11/ 99) \Rocketeer\Scm::Git - Methods: 100.00% ( 6/ 6) Lines: 100.00% ( 9/ 9) -\Rocketeer\Tasks::Check - Methods: 100.00% ( 6/ 6) Lines: 64.00% ( 32/ 50) -\Rocketeer\Tasks::Cleanup - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 9/ 9) -\Rocketeer\Tasks::Closure - Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 5/ 5) -\Rocketeer\Tasks::CurrentRelease - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 7/ 7) -\Rocketeer\Tasks::Deploy - Methods: 80.00% ( 4/ 5) Lines: 65.85% ( 27/ 41) -\Rocketeer\Tasks::Rollback - Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 5/ 5) -\Rocketeer\Tasks::Setup - Methods: 100.00% ( 2/ 2) Lines: 95.24% ( 20/ 21) -\Rocketeer\Tasks::Teardown - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 4/ 4) -\Rocketeer\Tasks\Abstracts::Task - Methods: 87.50% (14/16) Lines: 80.95% ( 51/ 63) + Methods: 16.67% ( 1/ 6) Lines: 12.50% ( 1/ 8) +\Rocketeer\Traits::Scm + Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 3/ 3) From 003b82a86dc417a9521a1e406147a0f630bf7011 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Thu, 11 Jul 2013 00:46:56 +0200 Subject: [PATCH 4/5] Work on tests --- composer.json | 1 + composer.lock | 99 +++++++++++++++++++++- phpunit.xml | 2 +- src/Rocketeer/Bash.php | 2 +- src/Rocketeer/Commands/BaseTaskCommand.php | 17 ++++ src/Rocketeer/TasksQueue.php | 2 +- tests/BashTest.php | 3 - tests/TasksQueueTest.php | 7 ++ tests/TasksTest.php | 13 ++- tests/_start.php | 84 ++++++++++++------ tests/meta/coverage.txt | 36 ++++++-- 11 files changed, 224 insertions(+), 42 deletions(-) diff --git a/composer.json b/composer.json index 43b35019f..6c37a41db 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ "illuminate/support": "~4" }, "require-dev": { + "illuminate/console": "~4", "illuminate/container": "~4", "illuminate/filesystem": "~4", "mockery/mockery": "dev-master", diff --git a/composer.lock b/composer.lock index 2edded12d..e38c36011 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "f7618c164c61dea624b9dd2ab41b9ee6", + "hash": "84b89db1572019517583c6e0fc006907", "packages": [ { "name": "illuminate/support", @@ -56,6 +56,50 @@ } ], "packages-dev": [ + { + "name": "illuminate/console", + "version": "dev-master", + "target-dir": "Illuminate/Console", + "source": { + "type": "git", + "url": "https://github.com/illuminate/console.git", + "reference": "cb44b57a58a655b340332da4f06f892b52d5d8fe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/console/zipball/cb44b57a58a655b340332da4f06f892b52d5d8fe", + "reference": "cb44b57a58a655b340332da4f06f892b52d5d8fe", + "shasum": "" + }, + "require": { + "symfony/console": "2.3.*" + }, + "require-dev": { + "phpunit/phpunit": "3.7.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.1-dev" + } + }, + "autoload": { + "psr-0": { + "Illuminate\\Console": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "time": "2013-05-28 18:31:39" + }, { "name": "illuminate/container", "version": "dev-master", @@ -243,6 +287,59 @@ ], "time": "2013-06-26 03:40:32" }, + { + "name": "symfony/console", + "version": "2.3.x-dev", + "target-dir": "Symfony/Component/Console", + "source": { + "type": "git", + "url": "https://github.com/symfony/Console.git", + "reference": "68fda7fc4351e9dad8beef70470050aea752d780" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Console/zipball/68fda7fc4351e9dad8beef70470050aea752d780", + "reference": "68fda7fc4351e9dad8beef70470050aea752d780", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/event-dispatcher": "~2.1" + }, + "suggest": { + "symfony/event-dispatcher": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Console\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "http://symfony.com", + "time": "2013-07-01 12:24:43" + }, { "name": "symfony/finder", "version": "2.3.x-dev", diff --git a/phpunit.xml b/phpunit.xml index 0f03c0ac9..28894fb4d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,7 @@ getOption('pretend') and !$silent) { $this->command->line(implode(PHP_EOL, $commands)); - return true; + return $commands; } // Get output diff --git a/src/Rocketeer/Commands/BaseTaskCommand.php b/src/Rocketeer/Commands/BaseTaskCommand.php index acf35a1d7..30636b25f 100644 --- a/src/Rocketeer/Commands/BaseTaskCommand.php +++ b/src/Rocketeer/Commands/BaseTaskCommand.php @@ -17,6 +17,13 @@ class BaseTaskCommand extends BaseDeployCommand */ protected $name = 'deploy.custom'; + /** + * The Task to execute on fire + * + * @var Task + */ + protected $task; + /** * Build a new custom command * @@ -46,4 +53,14 @@ public function fire() { return $this->fireTasksQueue($this->task); } + + /** + * Get the Task the command will execute + * + * @return Task + */ + public function getTask() + { + return $this->task; + } } diff --git a/src/Rocketeer/TasksQueue.php b/src/Rocketeer/TasksQueue.php index 8cb1674cd..7d2ea135d 100644 --- a/src/Rocketeer/TasksQueue.php +++ b/src/Rocketeer/TasksQueue.php @@ -71,7 +71,7 @@ public function add($task) $task = $this->buildTask($task); } - $this->app['artisan']->add(new BaseTaskCommand($task)); + return $this->app['artisan']->add(new BaseTaskCommand($task)); } /** diff --git a/tests/BashTest.php b/tests/BashTest.php index a342a03eb..698f046bb 100644 --- a/tests/BashTest.php +++ b/tests/BashTest.php @@ -1,9 +1,6 @@ task->which('grep'); diff --git a/tests/TasksQueueTest.php b/tests/TasksQueueTest.php index 122b7f888..45f7d5612 100644 --- a/tests/TasksQueueTest.php +++ b/tests/TasksQueueTest.php @@ -10,6 +10,13 @@ public function testCanBuildTaskByName() $this->assertInstanceOf('Rocketeer\Traits\Task', $task); } + public function testCanAddCommandsToArtisan() + { + $command = $this->tasksQueue()->add('Rocketeer\Tasks\Deploy'); + $this->assertInstanceOf('Rocketeer\Commands\BaseTaskCommand', $command); + $this->assertInstanceOf('Rocketeer\Tasks\Deploy', $command->getTask()); + } + public function testCanGetTasksBeforeOrAfterAnotherTask() { $task = $this->task('Deploy'); diff --git a/tests/TasksTest.php b/tests/TasksTest.php index 874d6255d..54279a93a 100644 --- a/tests/TasksTest.php +++ b/tests/TasksTest.php @@ -10,6 +10,17 @@ public function testCanGetDescription() $this->assertNotNull($task->getDescription()); } + public function testCanRunMigrations() + { + $task = $this->pretendTask(); + + $commands = $task->runMigrations(); + $this->assertEquals('php artisan migrate', $commands[1]); + + $commands = $task->runMigrations(true); + $this->assertEquals('php artisan migrate --seed', $commands[1]); + } + //////////////////////////////////////////////////////////////////// //////////////////////////////// TASKS ///////////////////////////// //////////////////////////////////////////////////////////////////// @@ -143,6 +154,6 @@ public function testCanPretendToRunTasks() $this->task->command = $command; $output = $this->task->run('ls'); - $this->assertTrue($output); + $this->assertEquals(array('ls'), $output); } } diff --git a/tests/_start.php b/tests/_start.php index af115b6f5..c147190b6 100644 --- a/tests/_start.php +++ b/tests/_start.php @@ -1,4 +1,6 @@ app = new Container; - // Get the Mockery instances - $command = $this->getCommand(); - $config = $this->getConfig(); - $remote = $this->getRemote(); - // Laravel classes --------------------------------------------- / $this->app['path.base'] = '/src'; $this->app['path.storage'] = '/src/storage'; - $this->app->singleton('config', function () use ($config) { - return $config; - }); - - $this->app->singleton('remote', function () use ($remote) { - return $remote; - }); - - $this->app->singleton('files', function () { - return new Filesystem; - }); + $this->app['files'] = new Filesystem; + $this->app['config'] = $this->getConfig(); + $this->app['remote'] = $this->getRemote(); + $this->app['artisan'] = $this->getArtisan(); // Rocketeer classes ------------------------------------------- / @@ -79,23 +69,42 @@ public function setUp() return new Rocketeer\Server($app, __DIR__); }); + $command = $this->getCommand(); $this->app->singleton('rocketeer.tasks', function ($app) use ($command) { return new Rocketeer\TasksQueue($app, $command); }); // Bind dummy Task $this->task = $this->task('Cleanup'); + $this->recreateVirtualServer(); + } + /** + * Tears down the tests + * + * @return void + */ + public function tearDown() + { + Mockery::close(); + } + + /** + * Recreates the local file server + * + * @return void + */ + protected function recreateVirtualServer() + { // Recreate deployments file - $deployments = array( + $this->app['files']->put($this->deploymentsFile, json_encode(array( "foo" => "bar", "current_release" => 20000000000000, "directory_separator" => "/", "is_setup" => true, "apache" => array("username" => "www-datda","group" => "www-datda"), - "line_endings" => "\n" - ); - $this->app['files']->put($this->deploymentsFile, json_encode($deployments)); + "line_endings" => "\n", + ))); // Recreate altered local server $folders = array('current', 'shared', 'releases', 'releases/10000000000000', 'releases/20000000000000'); @@ -107,13 +116,25 @@ public function setUp() $this->app['files']->makeDirectory($folder, 0777, true); file_put_contents($folder.'/.gitkeep', ''); } - } //////////////////////////////////////////////////////////////////// /////////////////////////////// HELPERS //////////////////////////// //////////////////////////////////////////////////////////////////// + /** + * Get a pretend Task to run bogus commands + * + * @return Task + */ + protected function pretendTask() + { + $task = $this->task('Deploy'); + $task->command = clone $this->getCommand()->shouldReceive('option')->with('pretend')->andReturn(true)->mock(); + + return $task; + } + /** * Get Task instance * @@ -155,7 +176,7 @@ protected function getCommand($option = true) return $message; }; - $command = Mockery::mock('Illuminate\Console\Command'); + $command = Mockery::mock('Command'); $command->shouldReceive('comment')->andReturnUsing($message); $command->shouldReceive('error')->andReturnUsing($message); $command->shouldReceive('line')->andReturnUsing($message); @@ -163,9 +184,7 @@ protected function getCommand($option = true) $command->shouldReceive('argument'); $command->shouldReceive('ask'); $command->shouldReceive('secret'); - if ($option) { - $command->shouldReceive('option'); - } + $command->shouldReceive('option')->andReturn(null)->byDefault(); return $command; } @@ -236,4 +255,19 @@ protected function getRemote() return $remote; } + + /** + * Mock Artisan + * + * @return Mockery + */ + protected function getArtisan() + { + $artisan = Mockery::mock('Artisan'); + $artisan->shouldReceive('add')->andReturnUsing(function ($command) { + return $command; + }); + + return $artisan; + } } diff --git a/tests/meta/coverage.txt b/tests/meta/coverage.txt index 56fc5542a..3ccc9f9e9 100644 --- a/tests/meta/coverage.txt +++ b/tests/meta/coverage.txt @@ -1,24 +1,42 @@ Code Coverage Report - 2013-07-11 00:43:25 + 2013-07-11 01:13:30 Summary: - Classes: 11.11% (2/18) - Methods: 31.48% (34/108) - Lines: 24.54% (134/546) + Classes: 50.00% (9/18) + Methods: 84.26% (91/108) + Lines: 84.74% (422/498) \Rocketeer::Bash - Methods: 66.67% (10/15) Lines: 66.67% ( 50/ 75) + Methods: 100.00% (15/15) Lines: 92.00% ( 69/ 75) \Rocketeer::ReleasesManager Methods: 100.00% ( 9/ 9) Lines: 100.00% ( 19/ 19) \Rocketeer::Rocketeer - Methods: 61.54% ( 8/13) Lines: 66.67% ( 28/ 42) + Methods: 100.00% (13/13) Lines: 95.24% ( 40/ 42) \Rocketeer::Server - Methods: 100.00% ( 9/ 9) Lines: 73.53% ( 25/ 34) + Methods: 100.00% ( 9/ 9) Lines: 100.00% ( 34/ 34) \Rocketeer::TasksQueue - Methods: 20.00% ( 3/15) Lines: 11.11% ( 11/ 99) + Methods: 100.00% (15/15) Lines: 90.91% ( 90/ 99) \Rocketeer\Scm::Git - Methods: 16.67% ( 1/ 6) Lines: 12.50% ( 1/ 8) + Methods: 100.00% ( 6/ 6) Lines: 100.00% ( 8/ 8) +\Rocketeer\Tasks::Check + Methods: 100.00% ( 7/ 7) Lines: 66.67% ( 36/ 54) +\Rocketeer\Tasks::Cleanup + Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 9/ 9) +\Rocketeer\Tasks::Closure + Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 5/ 5) +\Rocketeer\Tasks::CurrentRelease + Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 7/ 7) +\Rocketeer\Tasks::Deploy + Methods: 80.00% ( 4/ 5) Lines: 65.85% ( 27/ 41) +\Rocketeer\Tasks::Rollback + Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 5/ 5) +\Rocketeer\Tasks::Setup + Methods: 100.00% ( 2/ 2) Lines: 95.65% ( 22/ 23) +\Rocketeer\Tasks::Teardown + Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 4/ 4) \Rocketeer\Traits::Scm Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 3/ 3) +\Rocketeer\Traits::Task + Methods: 87.50% (14/16) Lines: 83.87% ( 52/ 62) From 3c50a9fdeaf91e5313f73dc975ebf6e733c03bd1 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Thu, 11 Jul 2013 01:40:52 +0200 Subject: [PATCH 5/5] Bump version --- src/Rocketeer/Rocketeer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rocketeer/Rocketeer.php b/src/Rocketeer/Rocketeer.php index cdea5c04b..0bd7974f5 100644 --- a/src/Rocketeer/Rocketeer.php +++ b/src/Rocketeer/Rocketeer.php @@ -30,7 +30,7 @@ class Rocketeer * * @var string */ - const VERSION = '0.6.0'; + const VERSION = '0.6.2'; /** * Build a new ReleasesManager