food_server/vendor/php-mqtt/client/tests/Feature/ConnectWithInvalidHostAndPortTest.php
tk 9ef6902c1d 【类 型】:fix
【主	题】:提交runing字段
【描	述】:
	[原因]:正则匹配 bind_route 添加runing字段 PS:对应取出bind_route的, 即分割符
	[过程]:
	[影响]:
【结	束】
2024-07-09 17:35:54 +08:00

37 lines
1.0 KiB
PHP

<?php
/** @noinspection PhpUnhandledExceptionInspection */
declare(strict_types=1);
namespace Tests\Feature;
use PhpMqtt\Client\Exceptions\ConnectingToBrokerFailedException;
use PhpMqtt\Client\MqttClient;
use Tests\TestCase;
/**
* Tests that the client throws an exception if connecting using invalid host and port.
*
* @package Tests\Feature
*/
class ConnectWithInvalidHostAndPortTest extends TestCase
{
public function test_throws_exception_when_connecting_using_invalid_host_and_port(): void
{
$client = new MqttClient('127.0.0.1', 56565, 'test-invalid-host');
$this->expectException(ConnectingToBrokerFailedException::class);
$this->expectExceptionCode(ConnectingToBrokerFailedException::EXCEPTION_CONNECTION_SOCKET_ERROR);
try {
$client->connect(null, true);
} catch (ConnectingToBrokerFailedException $e) {
$this->assertGreaterThan(0, $e->getConnectionErrorCode());
$this->assertNotEmpty($e->getConnectionErrorMessage());
throw $e;
}
}
}