WowPress-Tailwind/theme/vendor/planetteamspeak/ts3-php-framework/tests/Adapter/ServerQueryTest.php

52 lines
1.6 KiB
PHP
Raw Normal View History

2024-06-11 11:06:25 +02:00
<?php
namespace PlanetTeamSpeak\TeamSpeak3Framework\Tests\Adapter;
use PHPUnit\Framework\TestCase;
use PlanetTeamSpeak\TeamSpeak3Framework\Adapter\MockServerQuery;
use PlanetTeamSpeak\TeamSpeak3Framework\Exception\AdapterException;
use PlanetTeamSpeak\TeamSpeak3Framework\Exception\ServerQueryException;
class ServerQueryTest extends TestCase
{
public const S_ERROR_OK = 'error id=0 msg=ok';
/**
* @throws AdapterException
*/
protected function createMockServerQuery(): MockServerQuery
{
return new MockServerQuery(['host' => '0.0.0.0', 'port' => 9987]);
}
/**
* @throws ServerQueryException
*/
public function testRequestIllegalCharakterException()
{
$query = "Hello\nWorld\r";
$this->expectException(AdapterException::class);
$this->expectExceptionMessage(sprintf("illegal characters in command '%s'", $query));
$serverQuery = $this->createMockServerQuery();
$serverQuery->request($query);
}
/**
* @throws AdapterException
* @throws ServerQueryException
*/
public function testLogin()
{
$query = "login serveradmin secret";
$serverQuery = $this->createMockServerQuery();
$reply = $serverQuery->request($query);
$this->assertEquals("ok", $reply->getErrorProperty('msg')->toString());
$query = "login client_login_name=serveradmin client_login_password=secret";
$serverQuery = $this->createMockServerQuery();
$reply = $serverQuery->request($query);
$this->assertEquals("ok", $reply->getErrorProperty('msg')->toString());
}
}