Test Failed
Push — zf3-version ( 8a740a...f2c5f0 )
by Diego
03:23
created

DistributionReportControllerTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 113
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 113
loc 113
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 18 18 1
A testGetWholeSectoralDistributionActionActionCanBeAccessed() 20 20 1
A testGetSectoralDistributionActionCanBeAccessed() 20 20 1
A testGetGasesDistributionActionCanBeAccessed() 20 20 1
A testGetSectoralGasesDistributionActionCanBeAccessed() 16 16 1
A testInvalidRouteDoesNotCrash() 5 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
4
 * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
5
 * @license   http://framework.zend.com/license/new-bsd New BSD License
6
 */
7
8
namespace ApiTest\Controller;
9
10
use Api\Controller\DistributionReportController;
11
use Zend\Stdlib\ArrayUtils;
12
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
13
use Zend\Json\Json;
14
15 View Code Duplication
class DistributionReportControllerTest extends AbstractHttpControllerTestCase
0 ignored issues
show
Duplication introduced by
This class 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...
16
{
17
    public function setUp()
18
    {
19
        $configOverrides = [];
20
21
        $this->setApplicationConfig(ArrayUtils::merge(
22
            include __DIR__ . '/../../../../config/application.config.php',
23
            $configOverrides
24
        ));
25
26
        $services = $this->getApplicationServiceLocator();
27
        $config = $services->get('config');
28
        unset($config['db']);
29
        $services->setAllowOverride(true);
30
        $services->setService('config', $config);
31
        $services->setAllowOverride(false);
32
33
        parent::setUp();
34
    }
35
36
    public function testGetWholeSectoralDistributionActionActionCanBeAccessed()
37
    {
38
        $this->dispatch('/informe/distribucion-sectores/2014', 'GET');
39
        $this->assertResponseStatusCode(200);
40
        $this->assertResponseHeaderContains('Content-Type', 'application/json; charset=utf-8');
41
        $this->assertModuleName('api');
42
        $this->assertControllerName(DistributionReportController::class);
43
        $this->assertControllerClass('DistributionReportController');
44
        $this->assertMatchedRouteName('informe-todos-sectores');
45
46
        $data = $this->getResponse()->getContent();
47
48
        $this->assertJson($data);
49
50
        $data = Json::decode($data, Json::TYPE_ARRAY);
51
52
        $this->assertArrayHasKey('sector_1', $data);
53
        $this->assertArrayHasKey('colores', $data);
54
        $this->assertArrayHasKey('descripciones', $data);
55
    }
56
57
    public function testGetSectoralDistributionActionCanBeAccessed()
58
    {
59
        $this->dispatch('/informe/distribucion-sector/2014/1', 'GET');
60
        $this->assertResponseStatusCode(200);
61
        $this->assertResponseHeaderContains('Content-Type', 'application/json; charset=utf-8');
62
        $this->assertModuleName('api');
63
        $this->assertControllerName(DistributionReportController::class);
64
        $this->assertControllerClass('DistributionReportController');
65
        $this->assertMatchedRouteName('informe-por-sector');
66
67
        $data = $this->getResponse()->getContent();
68
69
        $this->assertJson($data);
70
71
        $data = Json::decode($data, Json::TYPE_ARRAY);
72
73
        $this->assertArrayHasKey('graph_data', $data);
74
        $this->assertArrayHasKey('sector', $data);
75
        $this->assertArrayHasKey('totalActividades', $data);
76
    }
77
78
    public function testGetGasesDistributionActionCanBeAccessed()
79
    {
80
        $this->dispatch('/informe/distribucion-gases/2014', 'GET');
81
        $this->assertResponseStatusCode(200);
82
        $this->assertResponseHeaderContains('Content-Type', 'application/json; charset=utf-8');
83
        $this->assertModuleName('api');
84
        $this->assertControllerName(DistributionReportController::class);
85
        $this->assertControllerClass('DistributionReportController');
86
        $this->assertMatchedRouteName('informe-gas');
87
88
        $data = $this->getResponse()->getContent();
89
90
        $this->assertJson($data);
91
92
        $data = Json::decode($data, Json::TYPE_ARRAY);
93
94
        $this->assertArrayHasKey('colores', $data);
95
        $this->assertArrayHasKey('gases', $data);
96
        $this->assertArrayHasKey('valores', $data);
97
    }
98
99
    public function testGetSectoralGasesDistributionActionCanBeAccessed()
100
    {
101
        $this->dispatch('/informe/distribucion-gases-sector/2014', 'GET');
102
        $this->assertResponseStatusCode(200);
103
        $this->assertResponseHeaderContains('Content-Type', 'application/json; charset=utf-8');
104
        $this->assertModuleName('api');
105
        $this->assertControllerName(DistributionReportController::class);
106
        $this->assertControllerClass('DistributionReportController');
107
        $this->assertMatchedRouteName('informe-gas-por-sector');
108
109
        $data = $this->getResponse()->getContent();
110
111
        $this->assertJson($data);
112
113
        $data = Json::decode($data, Json::TYPE_ARRAY);
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...
114
    }
115
116
    public function testInvalidRouteDoesNotCrash()
117
    {
118
        $this->dispatch('/invalid/route', 'GET');
119
        $this->assertResponseStatusCode(404);
120
    }
121
122
    // public function testInvalidHttpVerbDoesNotCrash()
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
123
    // {
124
    //     $this->dispatch('/informe/distribucion-sectores/2014', 'DELETE');
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
125
    //     $this->assertResponseStatusCode(405);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
126
    // }
127
}
128