Completed
Pull Request — dev (#24)
by
unknown
06:15
created

SurveyControllerTest::testApiSurveyUpdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace Tests\AppBundle\Controller\Api;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
7
class SurveyControllerTest extends WebTestCase
8
{
9
    public function testApiSurveys()
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
        $client->request('GET', '/api/surveys');
18
19
        $this->assertEquals(401, $client->getResponse()->getStatusCode());
20
21
        $client->request(
22
            'GET',
23
            '/api/surveys',
24
            array(),
25
            array(),
26
            array('HTTP_X-AUTH-TOKEN' => '1')
27
28
        );
29
        $this->assertTrue(
30
            $client->getResponse()->headers->contains(
31
                'Content-Type',
32
                'application/json'
33
            ),
34
            'the "Content-Type" header is "application/json"'
35
        );
36
        $this->assertTrue($client->getResponse()->isSuccessful(), 'response status is 2xx');
37
    }
38
39
    public function testApiSurvey()
40
    {
41
        $client = static::createClient();
42
43
        $client->request('GET', '/api/surveys/1');
44
45
        $this->assertEquals(401, $client->getResponse()->getStatusCode());
46
47
        $client->request(
48
            'GET',
49
            '/api/surveys',
50
            array(),
51
            array(),
52
            array('HTTP_X-AUTH-TOKEN' => '1')
53
54
        );
55
        $this->assertTrue(
56
            $client->getResponse()->headers->contains(
57
                'Content-Type',
58
                'application/json'
59
            ),
60
            'the "Content-Type" header is "application/json"'
61
        );
62
        $this->assertTrue($client->getResponse()->isSuccessful(), 'response status is 2xx');
63
    }
64
65
    public function testApiSurveyUpdate()
66
    {
67
        $client = static::createClient();
68
69
        $client->request('PUT', '/api/surveys/1');
70
71
        $this->assertEquals(401, $client->getResponse()->getStatusCode());
72
73
        $client->request(
74
            'PUT',
75
            '/api/surveys/2',
76
            array(),
77
            array(),
78
            array('CONTENT_TYPE' => 'application/json',
79
                  'HTTP_X-AUTH-TOKEN' => '2', ),
80
            $content = '{"1":"yes","2":"yes","3":"yes","4":"5","5":"7"}'
81
        );
82
83
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
84
        exec('./bin/console d:d:d --force --env=test');
85
    }
86
}
87