Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
Make LocalStrategyTest more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
Anahkiasen committed Apr 3, 2015
1 parent 822bc1f commit 3cfddf7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"fabpot/php-cs-fixer": "2.0.*@dev",
"phpunit/phpunit": "~4.0",
"mockery/mockery": "^0.9.1",
"nesbot/carbon": "~1.4",
"nesbot/carbon": "~1.18",
"phpseclib/phpseclib": "~0.3.5",
"johnkary/phpunit-speedtrap": "dev-master",
"symfony/var-dumper": "~2.6"
Expand Down
4 changes: 3 additions & 1 deletion src/Rocketeer/Strategies/Deploy/LocalCloneStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
namespace Rocketeer\Strategies\Deploy;

use Carbon\Carbon;
use Exception;

class LocalCloneStrategy extends SyncStrategy
Expand Down Expand Up @@ -81,7 +82,8 @@ protected function cloneLocally($directory)
protected function getCloneDirectory()
{
$storagePath = $this->paths->getStoragePath();
$timestamp = Carbon::now()->timestamp;

return $storagePath.'/checkout/tmp/'.time().'/';
return $storagePath.'/checkout/tmp/'.$timestamp.'/';
}
}
24 changes: 18 additions & 6 deletions tests/Strategies/Deploy/LocalCloneStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
namespace Rocketeer\Strategies\Deploy;

use Carbon\Carbon;
use Rocketeer\TestCases\RocketeerTestCase;

class LocalCloneStrategyTest extends RocketeerTestCase
Expand All @@ -30,12 +31,11 @@ public function setUp()

public function testCanDeployRepository()
{
$time = $this->getCurrentTime();

$task = $this->pretendTask('Deploy');
$task->getStrategy('Deploy', 'LocalClone')->deploy();

// We just have to pray that second do not change during test
$time = time();

$matcher = [
'mkdir {server}/releases/{release}',
'git clone "https://github.com/Anahkiasen/html-object.git" "app/storage/checkout/tmp/'.$time.'/" --branch="master" --depth="1"',
Expand All @@ -47,6 +47,8 @@ public function testCanDeployRepository()

public function testCanSpecifyKey()
{
$time = $this->getCurrentTime();

$this->swapConfig([
'rocketeer::connections' => [
'production' => [
Expand All @@ -60,9 +62,6 @@ public function testCanSpecifyKey()
$task = $this->pretendTask('Deploy');
$task->getStrategy('Deploy', 'LocalClone')->deploy();

// We just have to pray that second do not change during test
$time = time();

$matcher = [
'mkdir {server}/releases/{release}',
'git clone "https://github.com/Anahkiasen/html-object.git" "app/storage/checkout/tmp/'.$time.'/" --branch="master" --depth="1"',
Expand All @@ -71,4 +70,17 @@ public function testCanSpecifyKey()

$this->assertHistory($matcher);
}

/**
* Mock the current time
*
* @return int
*/
protected function getCurrentTime()
{
Carbon::setTestNow(new Carbon(1234567890));
$time = Carbon::now()->timestamp;

return $time;
}
}

0 comments on commit 3cfddf7

Please sign in to comment.