Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Added ConnectionAdapterProcessExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
niels-nijens committed Nov 26, 2015
1 parent 4797484 commit bcc9a28
Showing 1 changed file with 84 additions and 0 deletions.
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'));
}
}

0 comments on commit bcc9a28

Please sign in to comment.