Room unit tests

This commit is contained in:
Yoann Celton 2018-12-04 18:58:23 +11:00 committed by Aryess
parent 6f95fecff6
commit b2a9e592a2
2 changed files with 66 additions and 2 deletions

View file

@ -84,13 +84,13 @@ class User {
/**
* Set this users avatar.
*
* @param $avatarUrl mxc url from previously uploaded
* @param string $avatarUrl mxc url from previously uploaded
* @return mixed //FIXME: add proper type
* @throws Exceptions\MatrixException
* @throws Exceptions\MatrixHttpLibException
* @throws Exceptions\MatrixRequestException
*/
public function setAvatarUrl($avatarUrl) {
public function setAvatarUrl(string $avatarUrl) {
return $this->api->setAvatarUrl($this->userId, $avatarUrl);
}

64
tests/UserTest.php Normal file
View file

@ -0,0 +1,64 @@
<?php
namespace Aryess\PhpMatrixSdk;
use Aryess\PhpMatrixSdk\Exceptions\MatrixException;
use Aryess\PhpMatrixSdk\Exceptions\MatrixHttpLibException;
use Aryess\PhpMatrixSdk\Exceptions\ValidationException;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Request;
class UserTest extends BaseTestCase {
const HOSTNAME = "http://localhost";
protected $userId = "@test:localhost";
protected $roomId = '!test:localhost';
/**
* @var MatrixClient
*/
protected $client;
/**
* @var User
*/
protected $user;
/**
* @var Room
*/
protected $room;
protected function setUp() {
parent::setUp();
$this->client = new MatrixClient(self::HOSTNAME);
$this->user = new User($this->client->api(), $this->userId);
$this->room = $this->invokePrivateMethod($this->client, 'mkRoom', [$this->roomId]);
}
public function testDisplayName() {
// No displayname
$displayname = 'test';
$this->assertEquals($this->user->userId(), $this->user->getDisplayName($this->room));
$container = [];
$handler = $this->getMockClientHandler([new Response(200, [], '{}')], $container);
$this->client->api()->setClient(new Client(['handler' => $handler]));
$this->assertEquals($this->user->userId(), $this->user->getDisplayName());
$this->assertEquals(1, count($container));
// $mapi->whoami();
// /** @var Request $req */
// $req = array_get($container, '0.request');
}
public function testDisplayNameGlobal() {
$displayname = 'test';
// Get global displayname
$container = [];
$str = sprintf('{"displayname": "%s"}', $displayname);
$handler = $this->getMockClientHandler([new Response(200, [], $str)], $container);
$this->client->api()->setClient(new Client(['handler' => $handler]));
$this->assertEquals($displayname, $this->user->getDisplayName());
$this->assertEquals(1, count($container));
}
}