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

SurveyControllerTest::testApiSurvey()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 16

Duplication

Lines 25
Ratio 100 %

Importance

Changes 0
Metric Value
dl 25
loc 25
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 16
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 View Code Duplication
    public function testApiSurveys()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
    {
11
        $client = static::createClient();
12
13
        $client->request('GET', '/api/surveys');
14
15
        $this->assertEquals(401, $client->getResponse()->getStatusCode());
16
17
        $client->request(
18
            'GET',
19
            '/api/surveys',
20
            array(),
21
            array(),
22
            array('HTTP_X-AUTH-TOKEN' => '1')
23
24
        );
25
        $this->assertTrue(
26
            $client->getResponse()->headers->contains(
27
                'Content-Type',
28
                'application/json'
29
            ),
30
            'the "Content-Type" header is "application/json"'
31
        );
32
        $this->assertTrue($client->getResponse()->isSuccessful(), 'response status is 2xx');
33
    }
34
35 View Code Duplication
    public function testApiSurvey()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        $client = static::createClient();
38
39
        $client->request('GET', '/api/survey/1');
40
41
        $this->assertEquals(401, $client->getResponse()->getStatusCode());
42
43
        $client->request(
44
            'GET',
45
            '/api/surveys',
46
            array(),
47
            array(),
48
            array('HTTP_X-AUTH-TOKEN' => '1')
49
50
        );
51
        $this->assertTrue(
52
            $client->getResponse()->headers->contains(
53
                'Content-Type',
54
                'application/json'
55
            ),
56
            'the "Content-Type" header is "application/json"'
57
        );
58
        $this->assertTrue($client->getResponse()->isSuccessful(), 'response status is 2xx');
59
    }
60
61
    public function testApiSurveyUpdate()
62
    {
63
        $client = static::createClient();
64
65
        $client->request('POST', '/api/survey/update/3');
66
67
        $this->assertEquals(401, $client->getResponse()->getStatusCode());
68
69
        $data = array('3' => 'yes');
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
70
71
        $client->request(
72
            'POST',
73
            '/api/survey/update/3',
74
            array(),
75
            array(),
76
            array('CONTENT_TYPE' => 'application/json',
77
                  'HTTP_X-AUTH-TOKEN' => '1', ),
78
            $content = '{"3":"yes"}'
79
        );
80
81
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
82
    }
83
}
84