Skip to content

Commit

Permalink
FIX: isConnected() does not detect that the server closes the connection
Browse files Browse the repository at this point in the history
  • Loading branch information
pvgnd committed Apr 25, 2020
1 parent 8ae057d commit 96b0df0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,8 @@ public function setVisibility($path, $visibility)
*/
public function isConnected()
{
if ($this->connection instanceof SFTP && $this->connection->isConnected()) {
return true;
if ($this->connection instanceof SFTP) {
return $this->connection->ping();
}

return false;
Expand Down
8 changes: 4 additions & 4 deletions tests/SftpAdapterTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function adapterProvider()
$adapter = new Sftp(['username' => 'test', 'password' => 'test']);
$mock = Mockery::mock('phpseclib\Net\SFTP')->makePartial();
$mock->shouldReceive('__toString')->andReturn('Net_SFTP');
$mock->shouldReceive('isConnected')->andReturn(true);
$mock->shouldReceive('ping')->andReturn(true);
$mock->shouldReceive('disconnect');
$adapter->setNetSftpConnection($mock);
$filesystem = new Filesystem($adapter);
Expand Down Expand Up @@ -517,7 +517,7 @@ public function testLoginFail($filesystem, $adapter, $mock)
public function testIsConnected($filesystem, SftpAdapter $adapter, $mock)
{
$adapter->setNetSftpConnection($mock);
$mock->shouldReceive('isConnected')->andReturn(true);
$mock->shouldReceive('ping')->andReturn(true);
$this->assertTrue($adapter->isConnected());
}

Expand All @@ -532,7 +532,7 @@ public function testIsNotConnected($filesystem, SftpAdapter $adapter)
$mock = Mockery::mock('phpseclib\Net\SFTP');
$mock->shouldReceive('__toString')->andReturn('Net_SFTP');
$mock->shouldReceive('disconnect');
$mock->shouldReceive('isConnected')->andReturn(false);
$mock->shouldReceive('ping')->andReturn(false);
$adapter->setNetSftpConnection($mock);
$this->assertFalse($adapter->isConnected());
}
Expand Down Expand Up @@ -600,7 +600,7 @@ public function testNetSftpConnectionSetter()
'NetSftpConnection' => $mock = Mockery::mock('phpseclib\Net\SFTP'),
];

$mock->shouldReceive('isConnected')->andReturn(true);
$mock->shouldReceive('ping')->andReturn(true);
$mock->shouldReceive('disconnect');

$adapter = new Sftp($settings);
Expand Down

0 comments on commit 96b0df0

Please sign in to comment.