From b2a9e592a2969189c2aed3d7a0c85751217d7682 Mon Sep 17 00:00:00 2001 From: Yoann Celton Date: Tue, 4 Dec 2018 18:58:23 +1100 Subject: [PATCH] Room unit tests --- src/User.php | 4 +-- tests/UserTest.php | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 tests/UserTest.php diff --git a/src/User.php b/src/User.php index fc22526..4548e14 100644 --- a/src/User.php +++ b/src/User.php @@ -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); } diff --git a/tests/UserTest.php b/tests/UserTest.php new file mode 100644 index 0000000..cbfe173 --- /dev/null +++ b/tests/UserTest.php @@ -0,0 +1,64 @@ +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)); + + } +} \ No newline at end of file