Completed
Pull Request — dev (#26)
by nonanerz
04:09
created

ApiDefaultControllerTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B testLogin() 0 30 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 = '{"email":"[email protected]",
14
        "password":"intern1"}';
15
16
        $client->request('POST', '/api/login', [], [], [], $json
17
        );
18
19
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
20
21
        $content = $client->getResponse()->getContent();
22
23
        $arrayContent = json_decode($content, true);
24
25
        $token = $arrayContent['X-AUTH-TOKEN'];
26
27
        $headers = ['HTTP_X-AUTH-TOKEN' => $token];
28
29
        $client->request('GET', '/api/user', [], [], $headers);
30
31
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
32
33
        $headers = ['HTTP_X-AUTH-TOKEN' => null];
34
35
        $client->request('GET', '/api/user', [], [], $headers);
36
37
        $this->assertEquals(401, $client->getResponse()->getStatusCode());
38
    }
39
}
40