HighchartsChartTest::testJsonAddingData()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 33
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 33
rs 8.8571
cc 3
eloc 22
nc 3
nop 0
1
<?php
2
3
namespace CarlosIO\Geckoboard\Widgets;
4
5
class HighchartsChartTest extends \PHPUnit_Framework_TestCase
6
{
7 View Code Duplication
    public function testJsonForSingleSeriesData()
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...
8
    {
9
        $myWidget = new HighchartsChart();
10
        $myWidget->setId('56797-7e3d4237-f798-433a-abe7-ac1857dfdf0f');
11
12
        $myWidget->setType('line');
13
        $myWidget->setTitle('Monthly Average Temperature');
14
        $myWidget->setSubtitle('Source: WorldClimate.com');
15
        $myWidget->setXAxisLabels(array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'));
16
        $myWidget->setYAxisTitle('Temperature (°C)');
17
        $myWidget->setSingleSerie('Tokyo', array(7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6));
18
        $myWidget->setSingleSerie('London', array(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8));
19
20
        $data = $myWidget->getData();
21
        $json = json_encode($data);
22
23
        $testJson = '{"highchart":{"chart":{"type":"line"},"title":{"text":"Monthly Average Temperature"},"subtitle":{"text":"Source: WorldClimate.com"},'.
24
            '"xAxis":{"categories":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]},'.
25
            '"yAxis":{"title":{"text":"Temperature (\u00b0C)"}},"plotOptions":{"line":{"dataLabels":{"enabled":true},"enableMouseTracking":false}},'.
26
            '"series":[{"name":"Tokyo","data":[7,6.9,9.5,14.5,18.4,21.5,25.2,26.5,23.3,18.3,13.9,9.6],"type":"line"},{"name":"London","data":[3.9,4.2,5.7,8.5,'.
27
            '11.9,15.2,17,16.6,14.2,10.3,6.6,4.8],"type":"line"}]}}';
28
29
        $this->assertEquals($testJson, $json);
30
    }
31
32 View Code Duplication
    public function testJsonForFullData()
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...
33
    {
34
        $myWidget = new HighchartsChart();
35
        $myWidget->setId('56797-7e3d4237-f798-433a-abe7-ac1857dfdf0f');
36
37
        $myWidget->setType('line');
38
        $myWidget->setTitle('Monthly Average Temperature');
39
        $myWidget->setSubtitle('Source: WorldClimate.com');
40
        $myWidget->setXAxisLabels(array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'));
41
        $myWidget->setXAxisTitle('Month');
42
        $series = array(
43
            'Tokyo' => array(7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6),
44
            'London' => array(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8),
45
        );
46
        $myWidget->setSeries($series);
47
48
        $data = $myWidget->getData();
49
        $json = json_encode($data);
50
51
        $testJson = '{"highchart":{"chart":{"type":"line"},"title":{"text":"Monthly Average Temperature"},"subtitle":{"text":"Source: WorldClimate.com"},'.
52
            '"xAxis":{"categories":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"title":{"text":"Month"}},'.
53
            '"plotOptions":{"line":{"dataLabels":{"enabled":true},"enableMouseTracking":false}},'.
54
            '"series":[{"name":"Tokyo","data":[7,6.9,9.5,14.5,18.4,21.5,25.2,26.5,23.3,18.3,13.9,9.6],"type":"line"},{"name":"London","data":[3.9,4.2,5.7,8.5,'.
55
            '11.9,15.2,17,16.6,14.2,10.3,6.6,4.8],"type":"line"}]}}';
56
57
        $this->assertEquals($testJson, $json);
58
    }
59
60
    public function testJsonAddingData()
61
    {
62
        $myWidget = new HighchartsChart();
63
        $myWidget->setId('56797-7e3d4237-f798-433a-abe7-ac1857dfdf0f');
64
65
        $myWidget->setType('line');
66
        $myWidget->setTitle('Monthly Average Temperature');
67
        $myWidget->setSubtitle('Source: WorldClimate.com');
68
        $myWidget->setYAxisLabels(array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'));
69
        $myWidget->setYAxisTitle('Temperature (°C)');
70
71
        $series = array(
72
            'Tokyo' => array(7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6),
73
            'London' => array(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8),
74
        );
75
76
        foreach ($series as $city => $values) {
77
            foreach ($values as $val) {
78
                $myWidget->addItemSerie($city, $val);
79
            }
80
        }
81
82
        $data = $myWidget->getData();
83
        $json = json_encode($data);
84
85
        $testJson = '{"highchart":{"chart":{"type":"line"},"title":{"text":"Monthly Average Temperature"},"subtitle":{"text":"Source: WorldClimate.com"},'.
86
            '"yAxis":{"categories":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],'.
87
            '"title":{"text":"Temperature (\u00b0C)"}},"plotOptions":{"line":{"dataLabels":{"enabled":true},"enableMouseTracking":false}},'.
88
            '"series":[{"name":"Tokyo","data":[7,6.9,9.5,14.5,18.4,21.5,25.2,26.5,23.3,18.3,13.9,9.6],"type":"line"},{"name":"London","data":[3.9,4.2,5.7,8.5,'.
89
            '11.9,15.2,17,16.6,14.2,10.3,6.6,4.8],"type":"line"}]}}';
90
91
        $this->assertEquals($testJson, $json);
92
    }
93
}
94