phpseclib/tests/Functional/Net/SFTPWrongServerTest.php

27 lines
793 B
PHP
Raw Normal View History

2019-09-17 10:09:51 +00:00
<?php
2022-06-04 15:31:21 +00:00
declare(strict_types=1);
namespace phpseclib3\Tests\Functional\Net;
use phpseclib3\Exception\UnableToConnectException;
2022-01-30 15:34:42 +00:00
use phpseclib3\Net\SFTP;
2019-09-17 10:09:51 +00:00
use PHPUnit\Framework\TestCase;
class SFTPWrongServerTest extends TestCase
{
2022-06-04 15:31:21 +00:00
public function testLoginToInvalidServer(): void
2019-09-17 10:09:51 +00:00
{
try {
(new SFTP('dummy-server'))->login('username', 'password');
static::fail('The connection to the non-existent server must not succeed.');
} catch (UnableToConnectException $e) {
// getaddrinfo message seems not to return stable text
static::assertSame(
2022-02-17 02:25:59 +00:00
'Cannot connect to dummy-server:22. Error 0. php_network_getaddresses: getaddrinfo',
substr($e->getMessage(), 0, 81)
);
2019-09-17 10:09:51 +00:00
}
}
}