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
|
|
|
class DistributionReportControllerTest extends AbstractHttpControllerTestCase |
16
|
|
|
{ |
17
|
5 |
|
public function setUp() |
18
|
|
|
{ |
19
|
5 |
|
$configOverrides = []; |
20
|
|
|
|
21
|
5 |
|
$this->setApplicationConfig(ArrayUtils::merge( |
22
|
5 |
|
include __DIR__.'/../../../../config/application.config.php', |
23
|
|
|
$configOverrides |
24
|
|
|
)); |
25
|
|
|
|
26
|
5 |
|
parent::setUp(); |
27
|
5 |
|
} |
28
|
|
|
|
29
|
1 |
View Code Duplication |
public function testGetWholeSectoralDistributionActionActionCanBeAccessed() |
|
|
|
|
30
|
|
|
{ |
31
|
1 |
|
$this->dispatch('/informe/distribucion-sectores/2014', 'GET'); |
32
|
1 |
|
$this->assertResponseStatusCode(200); |
33
|
1 |
|
$this->assertResponseHeaderContains('Content-Type', 'application/json; charset=utf-8'); |
34
|
1 |
|
$this->assertModuleName('api'); |
35
|
1 |
|
$this->assertControllerName(DistributionReportController::class); |
36
|
1 |
|
$this->assertControllerClass('DistributionReportController'); |
37
|
1 |
|
$this->assertMatchedRouteName('informe-todos-sectores'); |
38
|
|
|
|
39
|
1 |
|
$data = $this->getResponse()->getContent(); |
40
|
|
|
|
41
|
1 |
|
$this->assertJson($data); |
42
|
|
|
|
43
|
1 |
|
$data = Json::decode($data, Json::TYPE_ARRAY); |
44
|
|
|
|
45
|
1 |
|
$this->assertArrayHasKey('sector_1', $data); |
46
|
1 |
|
$this->assertArrayHasKey('colores', $data); |
47
|
1 |
|
$this->assertArrayHasKey('descripciones', $data); |
48
|
1 |
|
} |
49
|
|
|
|
50
|
1 |
View Code Duplication |
public function testGetSectoralDistributionActionCanBeAccessed() |
|
|
|
|
51
|
|
|
{ |
52
|
1 |
|
$this->dispatch('/informe/distribucion-sector/2014/1', 'GET'); |
53
|
1 |
|
$this->assertResponseStatusCode(200); |
54
|
1 |
|
$this->assertResponseHeaderContains('Content-Type', 'application/json; charset=utf-8'); |
55
|
1 |
|
$this->assertModuleName('api'); |
56
|
1 |
|
$this->assertControllerName(DistributionReportController::class); |
57
|
1 |
|
$this->assertControllerClass('DistributionReportController'); |
58
|
1 |
|
$this->assertMatchedRouteName('informe-por-sector'); |
59
|
|
|
|
60
|
1 |
|
$data = $this->getResponse()->getContent(); |
61
|
|
|
|
62
|
1 |
|
$this->assertJson($data); |
63
|
|
|
|
64
|
1 |
|
$data = Json::decode($data, Json::TYPE_ARRAY); |
65
|
|
|
|
66
|
1 |
|
$this->assertArrayHasKey('graph_data', $data); |
67
|
1 |
|
$this->assertArrayHasKey('sector', $data); |
68
|
1 |
|
$this->assertArrayHasKey('totalActividades', $data); |
69
|
1 |
|
} |
70
|
|
|
|
71
|
1 |
View Code Duplication |
public function testGetGasesDistributionActionCanBeAccessed() |
|
|
|
|
72
|
|
|
{ |
73
|
1 |
|
$this->dispatch('/informe/distribucion-gases/2014', 'GET'); |
74
|
1 |
|
$this->assertResponseStatusCode(200); |
75
|
1 |
|
$this->assertResponseHeaderContains('Content-Type', 'application/json; charset=utf-8'); |
76
|
1 |
|
$this->assertModuleName('api'); |
77
|
1 |
|
$this->assertControllerName(DistributionReportController::class); |
78
|
1 |
|
$this->assertControllerClass('DistributionReportController'); |
79
|
1 |
|
$this->assertMatchedRouteName('informe-gas'); |
80
|
|
|
|
81
|
1 |
|
$data = $this->getResponse()->getContent(); |
82
|
|
|
|
83
|
1 |
|
$this->assertJson($data); |
84
|
|
|
|
85
|
1 |
|
$data = Json::decode($data, Json::TYPE_ARRAY); |
86
|
|
|
|
87
|
1 |
|
$this->assertArrayHasKey('colores', $data); |
88
|
1 |
|
$this->assertArrayHasKey('gases', $data); |
89
|
1 |
|
$this->assertArrayHasKey('valores', $data); |
90
|
1 |
|
} |
91
|
|
|
|
92
|
1 |
|
public function testGetSectoralGasesDistributionActionCanBeAccessed() |
93
|
|
|
{ |
94
|
1 |
|
$this->dispatch('/informe/distribucion-gases-sector/2014', 'GET'); |
95
|
1 |
|
$this->assertResponseStatusCode(200); |
96
|
1 |
|
$this->assertResponseHeaderContains('Content-Type', 'application/json; charset=utf-8'); |
97
|
1 |
|
$this->assertModuleName('api'); |
98
|
1 |
|
$this->assertControllerName(DistributionReportController::class); |
99
|
1 |
|
$this->assertControllerClass('DistributionReportController'); |
100
|
1 |
|
$this->assertMatchedRouteName('informe-gas-por-sector'); |
101
|
|
|
|
102
|
1 |
|
$data = $this->getResponse()->getContent(); |
103
|
|
|
|
104
|
1 |
|
$this->assertJson($data); |
105
|
|
|
|
106
|
1 |
|
$data = Json::decode($data, Json::TYPE_ARRAY); |
|
|
|
|
107
|
1 |
|
} |
108
|
|
|
|
109
|
1 |
|
public function testInvalidRouteDoesNotCrash() |
110
|
|
|
{ |
111
|
1 |
|
$this->dispatch('/invalid/route', 'GET'); |
112
|
1 |
|
$this->assertResponseStatusCode(404); |
113
|
1 |
|
} |
114
|
|
|
|
115
|
|
|
// public function testInvalidHttpVerbDoesNotCrash() |
|
|
|
|
116
|
|
|
// { |
117
|
|
|
// $this->dispatch('/informe/distribucion-sectores/2014', 'DELETE'); |
|
|
|
|
118
|
|
|
// $this->assertResponseStatusCode(405); |
|
|
|
|
119
|
|
|
// } |
120
|
|
|
} |
121
|
|
|
|
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.