Initial commit
This commit is contained in:
124
tests/OptionsTest.php
Normal file
124
tests/OptionsTest.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
use Pdahal\Xmpp\Options;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class OptionsTest extends TestCase
|
||||
{
|
||||
protected $host;
|
||||
protected $port;
|
||||
protected $username;
|
||||
protected $password;
|
||||
|
||||
public Options $options;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->host = 'www.host.com';
|
||||
$this->username = 'foo';
|
||||
$this->password = 'bar';
|
||||
$this->port = 5222;
|
||||
$this->options = new Options();
|
||||
|
||||
$this->options
|
||||
->setHost($this->host)
|
||||
->setPort($this->port)
|
||||
->setUsername($this->username)
|
||||
->setPassword($this->password)
|
||||
;
|
||||
}
|
||||
|
||||
public function testIfNoHostThrowsError(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->options->setHost('');
|
||||
$this->options->getHost();
|
||||
}
|
||||
|
||||
public function testIfNoUsernameThrowsError(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->options->setUsername('');
|
||||
$this->options->getUsername();
|
||||
}
|
||||
|
||||
public function testIfNoPasswordThrowsError(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->options->setPassword('');
|
||||
$this->options->getPassword();
|
||||
}
|
||||
|
||||
public function testIfHostGetsTrimmed(): void
|
||||
{
|
||||
$this->options->setHost(' host');
|
||||
$this->assertEquals('host', $this->options->getHost());
|
||||
|
||||
$this->options->setHost('host ');
|
||||
$this->assertEquals('host', $this->options->getHost());
|
||||
|
||||
$this->options->setHost(' host ');
|
||||
$this->assertEquals('host', $this->options->getHost());
|
||||
}
|
||||
|
||||
public function testIfUsernameSplitResource(): void
|
||||
{
|
||||
$this->options->setUsername('user/resource');
|
||||
$this->assertEquals('user', $this->options->getUsername());
|
||||
$this->assertEquals('resource', $this->options->getResource());
|
||||
|
||||
$this->options->setUsername('user');
|
||||
$this->assertEquals('user', $this->options->getUsername());
|
||||
|
||||
$this->options->setUsername('user/resource/resource2/resource3');
|
||||
$this->assertEquals('user', $this->options->getUsername());
|
||||
$this->assertEquals('resource', $this->options->getResource());
|
||||
}
|
||||
|
||||
public function testResourcePrecedence(): void
|
||||
{
|
||||
$this->options->setUsername('user/resource');
|
||||
$this->options->setResource('resource2');
|
||||
$this->assertEquals('user', $this->options->getUsername());
|
||||
$this->assertEquals('resource2', $this->options->getResource());
|
||||
|
||||
$this->options->setResource('resource2');
|
||||
$this->options->setUsername('user/resource');
|
||||
$this->assertEquals('user', $this->options->getUsername());
|
||||
$this->assertEquals('resource', $this->options->getResource());
|
||||
}
|
||||
|
||||
public function testIfResourceGetsTrimmed(): void
|
||||
{
|
||||
$this->options->setResource(' resource');
|
||||
$this->assertEquals('resource', $this->options->getResource());
|
||||
|
||||
$this->options->setResource('resource ');
|
||||
$this->assertEquals('resource', $this->options->getResource());
|
||||
|
||||
$this->options->setResource(' resource ');
|
||||
$this->assertEquals('resource', $this->options->getResource());
|
||||
}
|
||||
|
||||
public function testFullSocketAddress(): void
|
||||
{
|
||||
$this->assertEquals('tcp://www.host.com:5222', $this->options->fullSocketAddress());
|
||||
}
|
||||
|
||||
public function testFullJid(): void
|
||||
{
|
||||
$this->options->setResource('resource');
|
||||
$this->assertEquals('foo@www.host.com/resource', $this->options->fullJid());
|
||||
}
|
||||
|
||||
public function testBareJid(): void
|
||||
{
|
||||
$this->assertEquals('foo@www.host.com', $this->options->bareJid());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user