TransactionsControllerTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A testCors() 0 37 1
1
<?php
2
3
namespace Tests\KI\FoyerBundle\Controller;
4
5
use Tests\KI\CoreBundle\WebTestCase;
6
7
class TransactionsControllerTest extends WebTestCase
8
{
9
    // On crée une ressource sur laquelle seront effectués les tests.
10
    // Ne pas oublier de supprimer à la fin avec le test DELETE.
11
    public function testCors()
12
    {
13
        $this->connect('peluchom', 'password');
14
        $this->client->request('POST', '/transactions', ['user' => 'trasqdsqdsqsqdncara', 'beer' => 'lesqddqsqffe']);
15
        $response = $this->client->getResponse();
16
        $this->assertJsonResponse($response, 404);
17
18
        $this->client->request('POST', '/transactions', ['user' => 'trancara', 'beer' => 'leffe']);
19
        $response = $this->client->getResponse();
20
        $this->assertJsonResponse($response, 201);
21
22
        $this->client->request('GET', '/transactions');
23
        $response = $this->client->getResponse();
24
        $this->assertJsonResponse($response, 200);
25
26
        $this->client->request('GET', '/userbeers');
27
        $response = $this->client->getResponse();
28
        $this->assertJsonResponse($response, 200);
29
30
        $this->client->request('GET', '/users/trancara/transactions');
31
        $response = $this->client->getResponse();
32
        $this->assertJsonResponse($response, 200);
33
34
        $data = json_decode($response->getContent(), true);
35
        $this->assertTrue(!empty($data));
36
        $key = array_keys($data)[0];
37
        $this->assertTrue(isset($data[$key]['id']));
38
        $transactionId = $data[$key]['id'];
39
40
        $this->client->request('DELETE', '/transactions/'.$transactionId);
41
        $response = $this->client->getResponse();
42
        $this->assertJsonResponse($response, 204);
43
44
        $this->client->request('DELETE', '/transactions/'.$transactionId);
45
        $response = $this->client->getResponse();
46
        $this->assertJsonResponse($response, 404);
47
    }
48
}
49