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 #83 from niels-nijens/connection-adapter-linking
Browse files Browse the repository at this point in the history
Implemented ConnectionAdapterInterface::isLink for checking symlinks
  • Loading branch information
niels-nijens committed Dec 15, 2015
2 parents dc2eb45 + 1222745 commit 5b8d2ba
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Deployment/Connection/ConnectionAdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public function isConnected();
*/
public function isFile($remoteFilename);

/**
* Returns true if $remoteTarget is a symlink.
*
* @param string $remoteTarget
*
* @return bool
*/
public function isLink($remoteTarget);

/**
* Returns true if $remoteDirectory is a remote directory.
*
Expand Down
8 changes: 8 additions & 0 deletions src/Deployment/Connection/LocalConnectionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public function isFile($remoteFilename)
return is_file($remoteFilename);
}

/**
* {@inheritdoc}
*/
public function isLink($remoteTarget)
{
return is_link($remoteTarget);
}

/**
* {@inheritdoc}
*/
Expand Down
12 changes: 12 additions & 0 deletions src/Deployment/Connection/SSHConnectionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ public function isFile($remoteFilename)
return false;
}

/**
* {@inheritdoc}
*/
public function isLink($remoteTarget)
{
if ($this->isConnected()) {
return $this->connection->is_link($remoteTarget);
}

return false;
}

/**
* {@inheritdoc}
*/
Expand Down
11 changes: 11 additions & 0 deletions tests/Deployment/Connection/ConnectedConnectionAdapterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ public function testIsFileReturnsFalseWhenNotConnected()
$this->assertFalse($this->connectionAdapter->isFile($this->workspaceUtility->getWorkspacePath().'/test.txt'));
}

/**
* Tests if ConnectionAdapterInterface::isLink returns false when not connected.
*/
public function testIsLinkReturnsFalseWhenNotConnected()
{
$this->workspaceUtility->createFile('/test.txt');
symlink($this->workspaceUtility->getWorkspacePath().'/test.txt', $this->workspaceUtility->getWorkspacePath().'/testLink');

$this->assertFalse($this->connectionAdapter->isLink($this->workspaceUtility->getWorkspacePath().'/testLink'));
}

/**
* Tests if ConnectionAdapterInterface::isDirectory returns false when not connected.
*/
Expand Down
27 changes: 27 additions & 0 deletions tests/Deployment/Connection/ConnectionAdapterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,33 @@ public function testIsFileReturnsTrueWhenFileExists()
$this->assertTrue($this->connectionAdapter->isFile($this->workspaceUtility->getWorkspacePath().'/test.txt'));
}

/**
* Tests if ConnectionAdapterInterface::isLink returns false when the link does not exist.
*
* @depends testConnectReturnsTrue
*/
public function testIsLinkReturnsFalseWhenLinkNotExists()
{
$this->connectionAdapter->connect();

$this->assertFalse($this->connectionAdapter->isLink($this->workspaceUtility->getWorkspacePath().'testLink'));
}

/**
* Tests if ConnectionAdapterInterface::isLink returns true when the link exists.
*
* @depends testConnectReturnsTrue
*/
public function testIsLinkReturnsTrueWhenLinkExists()
{
$this->workspaceUtility->createFile('/test.txt');
symlink($this->workspaceUtility->getWorkspacePath().'/test.txt', $this->workspaceUtility->getWorkspacePath().'/testLink');

$this->connectionAdapter->connect();

$this->assertTrue($this->connectionAdapter->isLink($this->workspaceUtility->getWorkspacePath().'/testLink'));
}

/**
* Tests if ConnectionAdapterInterface::isDirectory returns false when the directory does not exist.
*
Expand Down

0 comments on commit 5b8d2ba

Please sign in to comment.