Tests: add test for connecting to non-existant host

This commit is contained in:
terrafrost 2022-01-08 16:12:25 -06:00
parent b3a606b90c
commit 9b587a87c0
2 changed files with 28 additions and 0 deletions

View File

@ -23,6 +23,14 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
self::$exampleDataLength = 10000;
}
public function testBadHostname()
{
$this->setExpectedException('PHPUnit_Framework_Error_Notice');
$sftp = new Net_SFTP('bad host name');
$sftp->login('username', 'password');
}
public function testConstructor()
{
$sftp = new Net_SFTP($this->getEnv('SSH_HOSTNAME'));

View File

@ -145,4 +145,24 @@ abstract class PhpseclibTestCase extends PHPUnit\Framework\TestCase
parent::assertNotContains($needle, $haystack, $message);
}
public function setExpectedException($name, $message = null, $code = null)
{
if (version_compare(PHP_VERSION, '7.0.0') < 0) {
parent::setExpectedException($name, $message, $code);
return;
}
switch ($name) {
case 'PHPUnit_Framework_Error_Notice':
case 'PHPUnit_Framework_Error_Warning':
$name = str_replace('_', '\\', $name);
}
$this->expectException($name);
if (!empty($message)) {
$this->expectExceptionMessage($message);
}
if (!empty($code)) {
$this->expectExceptionCode($code);
}
}
}