UserTestCase   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testUserLoginSuccess() 0 5 1
A testBaseRoute() 0 3 1
A testUserLoginFailure() 0 5 1
1
<?php
2
/**
3
 * This file is part of user_management
4
 * User: Sinan TURGUT <[email protected]>
5
 * Date: 24.06.2019
6
 * php version 7.2
7
 *
8
 * @category Assessment
9
 * @package  UserManagement
10
 * @author   Sinan TURGUT <[email protected]>
11
 * @license  See LICENSE file
12
 * @link     https://dev.sinanturgut.com.tr
13
 */
14
15
namespace Tests;
16
17
/**
18
 * Class UserTestCase
19
 * @package Tests
20
 */
21
class UserTestCase extends BaseTestCase
22
{
23
    /**
24
     * Test that the index route returns http 200
25
     */
26
    public function testBaseRoute() {
27
        $response = $this->runApp('GET', '/');
28
        $this->assertEquals(200, $response->getStatusCode());
29
    }
30
31
    /**
32
     * Test that the login route returns http 200 and token has a value
33
     */
34
    public function testUserLoginSuccess() {
35
        $response = $this->runApp('POST', '/user/login', ['user'=>['username'=>'admin','password'=>'123123']]);
36
        $result = json_decode($response->getBody(), true);
37
        $this->assertNotNull($result['user']['token']);
38
        $this->assertSame($response->getStatusCode(), 200);
39
    }
40
41
    /**
42
     * Test that the login route returns http 422 and token is null when wrong user info
43
     */
44
    public function testUserLoginFailure() {
45
        $response = $this->runApp('POST', '/user/login', ['user'=>['username'=>'adminx','password'=>'11111']]);
46
        $result = json_decode($response->getBody(), true);
47
        $this->assertFalse(isset($result['user']['token']));
48
        $this->assertSame($response->getStatusCode(), 422);
49
    }
50
51
}