This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ConnectionAdapterProcessExecutor
- Loading branch information
1 parent
4797484
commit bcc9a28
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
tests/Deployment/Connection/ConnectionAdapterProcessExecutorTest.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,84 @@ | ||
<?php | ||
|
||
namespace Accompli\Test; | ||
|
||
use Accompli\Chrono\Process\ProcessExecutionResult; | ||
use Accompli\Deployment\Connection\ConnectionAdapterProcessExecutor; | ||
use PHPUnit_Framework_TestCase; | ||
|
||
/** | ||
* ConnectionAdapterProcessExecutorTest. | ||
* | ||
* @author Niels Nijens <nijens.niels@gmail.com> | ||
*/ | ||
class ConnectionAdapterProcessExecutorTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* Tests if constructing a new ConnectionAdapterProcessExecutor instance sets the instance properties. | ||
*/ | ||
public function testConstruct() | ||
{ | ||
$connectionAdapterMock = $this->getMockBuilder('Accompli\Deployment\Connection\ConnectionAdapterInterface')->getMock(); | ||
|
||
$processExecutor = new ConnectionAdapterProcessExecutor($connectionAdapterMock); | ||
|
||
$this->assertAttributeSame($connectionAdapterMock, 'connectionAdapter', $processExecutor); | ||
} | ||
|
||
/** | ||
* Tests if ConnectionAdapterProcessExecutor::isDirectory returns the expected result. | ||
* | ||
* @depends testConstruct | ||
*/ | ||
public function testIsDirectory() | ||
{ | ||
$connectionAdapterMock = $this->getMockBuilder('Accompli\Deployment\Connection\ConnectionAdapterInterface')->getMock(); | ||
$connectionAdapterMock->expects($this->once())->method('isDirectory')->willReturn(true); | ||
|
||
$processExecutor = new ConnectionAdapterProcessExecutor($connectionAdapterMock); | ||
|
||
$this->assertTrue($processExecutor->isDirectory('/test/path')); | ||
} | ||
|
||
/** | ||
* Tests if ConnectionAdapterProcessExecutor::execute returns the expected result. | ||
* | ||
* @depends testConstruct | ||
*/ | ||
public function testExecute() | ||
{ | ||
$connectionAdapterMock = $this->getMockBuilder('Accompli\Deployment\Connection\ConnectionAdapterInterface')->getMock(); | ||
$connectionAdapterMock->expects($this->once())->method('executeCommand')->willReturn(new ProcessExecutionResult(0, '', '')); | ||
|
||
$processExecutor = new ConnectionAdapterProcessExecutor($connectionAdapterMock); | ||
|
||
$this->assertInstanceOf('Accompli\Chrono\Process\ProcessExecutionResult', $processExecutor->execute('echo test')); | ||
} | ||
|
||
/** | ||
* Tests if ConnectionAdapterProcessExecutor::execute changes the working directory and returns the expected result. | ||
* | ||
* @depends testExecute | ||
*/ | ||
public function testExecuteWithWorkingDirectory() | ||
{ | ||
$connectionAdapterMock = $this->getMockBuilder('Accompli\Deployment\Connection\ConnectionAdapterInterface')->getMock(); | ||
$connectionAdapterMock->expects($this->once()) | ||
->method('getWorkingDirectory') | ||
->willReturn('/previous/directory'); | ||
$connectionAdapterMock->expects($this->exactly(2)) | ||
->method('changeWorkingDirectory') | ||
->withConsecutive( | ||
array('/test/path'), | ||
array('/previous/directory') | ||
) | ||
->willReturn(true); | ||
$connectionAdapterMock->expects($this->once()) | ||
->method('executeCommand') | ||
->willReturn(new ProcessExecutionResult(0, '', '')); | ||
|
||
$processExecutor = new ConnectionAdapterProcessExecutor($connectionAdapterMock); | ||
|
||
$this->assertInstanceOf('Accompli\Chrono\Process\ProcessExecutionResult', $processExecutor->execute('echo test', '/test/path')); | ||
} | ||
} |