-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1242 from pantheon-systems/env_deploy_unit_tests
Env:deploy unit tests
- Loading branch information
Showing
4 changed files
with
200 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
tests/new_unit_tests/Commands/Env/DeployCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
namespace Pantheon\Terminus\UnitTests\Commands\Env; | ||
|
||
use Pantheon\Terminus\Commands\Env\DeployCommand; | ||
use Pantheon\Terminus\Config; | ||
use Terminus\Exceptions\TerminusException; | ||
|
||
/** | ||
* Testing class for Pantheon\Terminus\Commands\Env\DeployCommand | ||
*/ | ||
class DeployCommandTest extends EnvCommandTest | ||
{ | ||
|
||
/** | ||
* Sets up the fixture, for example, open a network connection. | ||
* This method is called before a test is executed. | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->command = new DeployCommand($this->sites); | ||
$this->command->setLogger($this->logger); | ||
} | ||
|
||
|
||
/** | ||
* Tests the env:deploy command success with all parameters. | ||
* | ||
* @return void | ||
*/ | ||
public function testDeploy() | ||
{ | ||
$this->env->id = 'test'; | ||
|
||
$this->env->expects($this->once()) | ||
->method('hasDeployableCode') | ||
->willReturn(true); | ||
|
||
$this->env->expects($this->once()) | ||
->method('deploy') | ||
->willReturn($this->workflow) | ||
->with([ | ||
'updatedb' => 0, | ||
'clear_cache' => 0, | ||
'annotation' => 'Deploy from Terminus', | ||
'clone_database' => [ | ||
'from_environment' => 'live' | ||
], | ||
'clone_files' => [ | ||
'from_environment' => 'live' | ||
] | ||
]); | ||
|
||
$this->workflow->expects($this->once()) | ||
->method('wait'); | ||
|
||
// Run the deploy. | ||
$this->command->deploy('mysite.test', [ | ||
'sync-content' => true, | ||
'note' => 'Deploy from Terminus', | ||
'cc' => false, | ||
'updatedb' => false, | ||
]); | ||
} | ||
|
||
/** | ||
* Tests the env:deploy command where no code is deployable. | ||
* | ||
* @return void | ||
*/ | ||
public function testDeployNoCode() | ||
{ | ||
$this->env->id = 'test'; | ||
|
||
$this->env->expects($this->once()) | ||
->method('hasDeployableCode') | ||
->willReturn(false); | ||
|
||
$this->env->expects($this->never()) | ||
->method('deploy'); | ||
|
||
$this->logger->expects($this->once()) | ||
->method('log'); | ||
|
||
// Run the deploy. | ||
$this->command->deploy('mysite.test'); | ||
} | ||
|
||
/** | ||
* Tests the env:deploy command to live. | ||
* | ||
* @return void | ||
*/ | ||
public function testDeployLive() | ||
{ | ||
$this->env->id = 'live'; | ||
|
||
$this->env->expects($this->once()) | ||
->method('hasDeployableCode') | ||
->willReturn(true); | ||
|
||
$this->env->expects($this->once()) | ||
->method('deploy') | ||
->willReturn($this->workflow) | ||
->with([ | ||
'updatedb' => 1, | ||
'clear_cache' => 1, | ||
'annotation' => 'Deploy from Terminus', | ||
]); | ||
|
||
$this->workflow->expects($this->once()) | ||
->method('wait'); | ||
|
||
// Run the deploy. | ||
$this->command->deploy('mysite.live', [ | ||
'sync-content' => true, | ||
'note' => 'Deploy from Terminus', | ||
'cc' => true, | ||
'updatedb' => true, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
namespace Pantheon\Terminus\UnitTests\Commands\Env; | ||
|
||
use Pantheon\Terminus\UnitTests\Commands\CommandTestCase; | ||
|
||
use Pantheon\Terminus\Session\Session; | ||
use Psr\Log\NullLogger; | ||
use Terminus\Collections\Sites; | ||
use Terminus\Models\Site; | ||
use Terminus\Collections\Environments; | ||
use Terminus\Models\Environment; | ||
use Terminus\Models\Workflow; | ||
|
||
/** | ||
* @property \PHPUnit_Framework_MockObject_MockObject sites | ||
*/ | ||
abstract class EnvCommandTest extends CommandTestCase | ||
{ | ||
protected $session; | ||
protected $sites; | ||
protected $user; | ||
protected $logger; | ||
protected $command; | ||
|
||
/** | ||
* Sets up the fixture, for example, open a network connection. | ||
* This method is called before a test is executed. | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->sites = $this->getMockBuilder(Sites::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->site = $this->getMockBuilder(Site::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->sites->method('get') | ||
->willReturn($this->site); | ||
|
||
$this->site->environments = $this->getMockBuilder(Environments::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->env = $this->getMockBuilder(Environment::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->site->environments->method('get') | ||
->willReturn($this->env); | ||
|
||
$this->logger = $this->getMockBuilder(NullLogger::class) | ||
->setMethods(array('log')) | ||
->getMock(); | ||
|
||
$this->workflow = $this->getMockBuilder(Workflow::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
} | ||
} |