UserTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testInit() 0 9 1
A testUserChat() 0 13 1
1
<?php
2
namespace tests\codeception\unit;
3
4
use jones\wschat\components\ChatRoom;
5
use jones\wschat\components\User;
6
use yii\codeception\TestCase;
7
8
/**
9
 * Class UserTest
10
 * @package tests\codeception\unit
11
 */
12
class UserTest extends TestCase
13
{
14
    protected $rid = 1;
15
    protected $id = 1;
16
17
    public function testInit()
18
    {
19
        $user = new User($this->id);
20
        $this->assertInstanceOf('jones\wschat\components\User', $user,
21
            'User should be instance of jones\wschat\components\User');
22
        $this->assertEquals($this->id, $user->getId(), 'Id\'s should match');
23
        $user->setRid($this->rid);
24
        $this->assertEquals($this->rid, $user->getRid(), 'Resource id\'s should match');
25
    }
26
27
    public function testUserChat()
28
    {
29
        $user = new User($this->id);
30
        $user->setChat(new ChatRoom());
31
        $chat = $user->getChat();
32
        $this->assertInstanceOf('jones\wschat\components\ChatRoom', $chat,
33
            'Chat should be instance of jones\wschat\components\ChatRoom');
34
        $users = $chat->getUsers();
35
        $this->assertEquals(1, count($users), 'Chat should contain only one user');
36
        $this->assertTrue(isset($users[$this->id]), 'User should be in chat');
37
        $this->assertInstanceOf('jones\wschat\components\User', $users[$this->id],
38
            'Chat user should be instance of jones\wschat\components\User');
39
    }
40
}