Completed
Pull Request — master (#30)
by
unknown
03:46
created

ApiDefaultControllerTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B testLogin() 0 38 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
        exec('./bin/console d:d:c --env=test');
12
        exec('./bin/console d:s:c --env=test');
13
        exec('./bin/console h:f:l -n --env=test');
14
15
        $client = static::createClient();
16
17
        $json = '{
18
            "user": {
19
                "email": "[email protected]",
20
                "password":"intern1"
21
            }
22
        }';
23
24
        $client->request('POST', '/api/login', [], [], [], $json
25
        );
26
27
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
28
29
        $content = $client->getResponse()->getContent();
30
31
        $arrayContent = json_decode($content, true);
32
33
        $token = $arrayContent['X-AUTH-TOKEN'];
34
35
        $headers = ['HTTP_X-AUTH-TOKEN' => $token];
36
37
        $client->request('GET', '/api/user', [], [], $headers);
38
39
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
40
41
        $headers = ['HTTP_X-AUTH-TOKEN' => null];
42
43
        $client->request('GET', '/api/user', [], [], $headers);
44
45
        $this->assertEquals(401, $client->getResponse()->getStatusCode());
46
    }
47
}
48