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

Commit

Permalink
Merge pull request #144 from niels-nijens/tests
Browse files Browse the repository at this point in the history
Improved tests and testability of SSHConnectionAdapter::getCurrentUsername
  • Loading branch information
niels-nijens committed May 4, 2016
2 parents d758de7 + 2e4c87e commit e9f7fab
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
9 changes: 1 addition & 8 deletions src/Deployment/Connection/SSHConnectionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,14 +406,7 @@ public function delete($remoteTarget, $recursive = false)
*/
private function getCurrentUsername()
{
if (function_exists('posix_getpwuid')) {
$username = posix_getpwuid(posix_geteuid())['name'];
} else {
// Fallback when POSIX functions are not available.
$username = get_current_user();
}

return $username;
return $_SERVER['USER'];
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/Deployment/Connection/ConnectionAdapterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public function tearDown()
$this->connectionAdapter->disconnect();
}

$this->workspaceUtility->remove();
if ($this->workspaceUtility instanceof WorkspaceUtility) {
$this->workspaceUtility->remove();
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/Deployment/Connection/SSHConnectionAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public function testConnectWithAuthenticationTypePasswordReturnsTrue()
*/
public function testConnectWithAuthenticationTypeSSHAgentReturnsTrue()
{
if (isset($_SERVER['SSH_AUTH_SOCK']) === false) {
$this->markTestSkipped('No running SSH agent found.');
}

$this->connectionAdapter = new SSHConnectionAdapter('localhost', SSHConnectionAdapter::AUTHENTICATION_SSH_AGENT, $this->getSSHUsername());

$this->assertTrue($this->connectionAdapter->connect());
Expand Down
42 changes: 42 additions & 0 deletions tests/EventDispatcher/Event/HostEventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Accompli\Test\EventDispatcher\Event;

use Accompli\EventDispatcher\Event\HostEvent;
use PHPUnit_Framework_TestCase;

/**
* HostEventTest.
*
* @author Niels Nijens <nijens.niels@gmail.com>
*/
class HostEventTest extends PHPUnit_Framework_TestCase
{
/**
* Tests if constructing a new HostEvent sets the properties.
*/
public function testConstruct()
{
$hostMock = $this->getMockBuilder('Accompli\Deployment\Host')
->disableOriginalConstructor()
->getMock();

$event = new HostEvent($hostMock);

$this->assertAttributeSame($hostMock, 'host', $event);
}

/**
* Tests if HostEvent::getHost returns the same value as during construction of HostEvent.
*/
public function testGetHost()
{
$hostMock = $this->getMockBuilder('Accompli\Deployment\Host')
->disableOriginalConstructor()
->getMock();

$event = new HostEvent($hostMock);

$this->assertSame($hostMock, $event->getHost());
}
}

0 comments on commit e9f7fab

Please sign in to comment.