CommentsControllerTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B testComments() 0 55 2
1
<?php
2
3
namespace Tests\KI\CoreBundle\Controller;
4
5
use Tests\KI\CoreBundle\WebTestCase;
6
7
// Tests généraux à toutes les classes
8
class CommentsControllerTest extends WebTestCase
9
{
10
    public function testComments()
11
    {
12
        $this->client->request('GET', '/newsitems/le-jeu/comments');
13
        $response = $this->client->getResponse();
14
        $this->assertJsonResponse($response, 200);
15
16
        $this->client->request('POST', '/newsitems/le-jeu/comments');
17
        $response = $this->client->getResponse();
18
        $this->assertJsonResponse($response, 400);
19
20
        $this->client->request('POST', '/newsitems/le-jeu/comments', ['text' => 'J\'ai perdu.']);
21
        $response = $this->client->getResponse();
22
        $this->assertJsonResponse($response, 201);
23
24
        $comment = json_decode($response->getContent(), true);
25
26
        $this->assertTrue(isset($comment['id']) && !empty($comment['id']));
27
        $id = $comment['id'];
28
29
        $this->client->request('PATCH', '/comments/'.$id, ['text' => 'J\'ai perdu au Jeu.']);
30
        $response = $this->client->getResponse();
31
        $this->assertJsonResponse($response, 204);
32
33
        $this->client->request('PATCH', '/comments/'.$id, ['text' => '']);
34
        $response = $this->client->getResponse();
35
        $this->assertJsonResponse($response, 400);
36
37
        $this->client->request('PATCH', '/comments/qsdqdsq', ['text' => 'J\'ai perdu au Jeu.']);
38
        $response = $this->client->getResponse();
39
        $this->assertJsonResponse($response, 404);
40
41
        $this->client->request('POST', '/comments/'.$id.'/like');
42
        $response = $this->client->getResponse();
43
        $this->assertJsonResponse($response, 204);
44
45
        $this->client->request('DELETE', '/comments/'.$id.'/like');
46
        $response = $this->client->getResponse();
47
        $this->assertJsonResponse($response, 204);
48
49
        $this->client->request('POST', '/comments/'.$id.'/dislike');
50
        $response = $this->client->getResponse();
51
        $this->assertJsonResponse($response, 204);
52
53
        $this->client->request('DELETE', '/comments/'.$id.'/dislike');
54
        $response = $this->client->getResponse();
55
        $this->assertJsonResponse($response, 204);
56
57
        $this->client->request('DELETE', '/comments/'.$id, ['text' => 'J\'ai perdu au Jeu.']);
58
        $response = $this->client->getResponse();
59
        $this->assertJsonResponse($response, 204);
60
61
        $this->client->request('DELETE', '/comments/sqdqsdqs', ['text' => 'J\'ai perdu au Jeu.']);
62
        $response = $this->client->getResponse();
63
        $this->assertJsonResponse($response, 404);
64
    }
65
}
66