CoursesControllerTest::testAttend()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Tests\KI\PublicationBundle\Controller;
4
5
use Tests\KI\CoreBundle\WebTestCase;
6
7
class CoursesControllerTest extends WebTestCase
8
{
9
//    public function testCoursesParsing()
10
//    {
11
//        $this->client->request('HEAD', '/courses');
12
//        $response = $this->client->getResponse();
13
//        $this->assertJsonResponse($response, 202);
14
//    }
15
16
    // On crée une ressource sur laquelle seront effectués les tests. Ne pas oublier de supprimer à la fin avec le test DELETE.
17
    public function testPost()
18
    {
19
        $this->client->request(
20
            'POST',
21
            '/courses',
22
            ['name' => 'Mécanique des familles',
23
                'groups' => [0, 1, 2, 3],
24
                'semester' => 'Année complète',
25
                'active' => true,
26
                'ects' => 3.5,
27
                'department' => 'GCC']
28
            );
29
        $response = $this->client->getResponse();
30
        $this->assertJsonResponse($response, 201);
31
    }
32
33 View Code Duplication
    public function testGet()
34
    {
35
        $this->client->request('GET', '/courses');
36
        $response = $this->client->getResponse();
37
        $this->assertJsonResponse($response, 200);
38
39
        $this->client->request('GET', '/courses/mecanique-des-familles');
40
        $response = $this->client->getResponse();
41
        $this->assertJsonResponse($response, 200);
42
43
        $this->client->request('GET', '/courses/qdqddsdwxa');
44
        $response = $this->client->getResponse();
45
        $this->assertJsonResponse($response, 404);
46
47
        $this->client->request('GET', '/own/courses');
48
        $response = $this->client->getResponse();
49
        $this->assertJsonResponse($response, 200);
50
    }
51
52
    public function testAttend()
53
    {
54
        $this->client->request('POST', '/courses/mecanique-des-familles/attend', ['group' => 1]);
55
        $response = $this->client->getResponse();
56
        $this->assertJsonResponse($response, 204);
57
58
        $this->client->request('POST', '/courses/mecanique-des-familles/attend', ['group' => 1]);
59
        $response = $this->client->getResponse();
60
        $this->assertJsonResponse($response, 400);
61
62
        $this->client->request('DELETE', '/courses/mecanique-des-familles/attend');
63
        $response = $this->client->getResponse();
64
        $this->assertJsonResponse($response, 204);
65
66
        $this->client->request('DELETE', '/courses/mecanique-des-familles/attend');
67
        $response = $this->client->getResponse();
68
        $this->assertJsonResponse($response, 400);
69
    }
70
71
    public function testPatch()
72
    {
73
        $this->client->request('PATCH', '/courses/mecanique-des-familles', ['name' => '']);
74
        $response = $this->client->getResponse();
75
        $this->assertJsonResponse($response, 400);
76
77
        $this->client->request(
78
            'PATCH', '/courses/mecanique-des-familles', ['semester' => 1]
79
            );
80
        $response = $this->client->getResponse();
81
        $this->assertJsonResponse($response, 204);
82
83
        $this->client->request('PATCH', '/courses/sjoajsiohaysahais-asbsksaba7', ['username' => 'miam', 'email' => '[email protected]']);
84
        $response = $this->client->getResponse();
85
        $this->assertJsonResponse($response, 404);
86
    }
87
}
88