Completed
Pull Request — dev (#26)
by nonanerz
11:38
created

ApiDefaultControllerTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B testLogin() 0 34 1
1
<?php
2
3
namespace tests\AppBundle\Controller\Api;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
7
class ApiDefaultControllerTest extends WebTestCase
8
{
9
    public function testLogin()
10
    {
11
        $client = static::createClient();
12
13
        $json = '{
14
            "user": {
15
                "email": "[email protected]",
16
                "password":"intern1"
17
            }
18
        }';
19
20
        $client->request('POST', '/api/login', [], [], [], $json
21
        );
22
23
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
24
25
        $content = $client->getResponse()->getContent();
26
27
        $arrayContent = json_decode($content, true);
28
29
        $token = $arrayContent['X-AUTH-TOKEN'];
30
31
        $headers = ['HTTP_X-AUTH-TOKEN' => $token];
32
33
        $client->request('GET', '/api/user', [], [], $headers);
34
35
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
36
37
        $headers = ['HTTP_X-AUTH-TOKEN' => null];
38
39
        $client->request('GET', '/api/user', [], [], $headers);
40
41
        $this->assertEquals(401, $client->getResponse()->getStatusCode());
42
    }
43
}
44