LineChartTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 5
c 2
b 1
f 1
lcom 0
cbo 2
dl 0
loc 63
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testJsonForAnEmptyData() 0 6 1
A testThrowsExceptionOnInvalidColour() 0 5 1
A testThrowsExceptionOnInvalidItems() 0 5 1
A testThrowsExceptionOnInvalidAxisDimension() 0 5 1
A testJsonWithValidData() 0 20 1
1
<?php
2
3
namespace CarlosIO\Geckoboard\Tests\Widgets;
4
5
use CarlosIO\Geckoboard\Widgets\LineChart;
6
7
class LineChartTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * Test with an empty dataset.
11
     */
12
    public function testJsonForAnEmptyData()
13
    {
14
        $widget = new LineChart();
15
        $json = json_encode($widget->getData());
16
        $this->assertJsonStringEqualsJsonString('{"item":[], "settings": {"axisx": [], "axisy": [], "colour": "ff9900"} }', $json);
17
    }
18
19
    /**
20
     * Test with a full dataset.
21
     */
22
    public function testJsonWithValidData()
23
    {
24
        $widget = new LineChart();
25
        $widget->setItems(array(1, 1.23));
26
        $widget->setColour('ff0000');
27
        $widget->setAxis(LineChart::DIMENSION_X, array('min', 'max'));
28
        $widget->setAxis(LineChart::DIMENSION_Y, array('bottom', 'top'));
29
30
        $current = json_encode($widget->getData());
31
        $expected = <<<EOF
32
{ "item": [ "1", "1.23"],
33
  "settings" : {
34
    "axisx" : [ "min", "max" ],
35
    "axisy" : [ "bottom", "top" ],
36
    "colour": "ff0000"
37
  }
38
}
39
EOF;
40
        $this->assertJsonStringEqualsJsonString($expected, $current);
41
    }
42
43
    /**
44
     * @expectedException InvalidArgumentException
45
     */
46
    public function testThrowsExceptionOnInvalidColour()
47
    {
48
        $widget = new LineChart();
49
        $widget->setColour('invalid');
50
    }
51
52
    /**
53
     * @expectedException InvalidArgumentException
54
     */
55
    public function testThrowsExceptionOnInvalidItems()
56
    {
57
        $widget = new LineChart();
58
        $widget->setItems(array('foo', 'bar'));
59
    }
60
61
    /**
62
     * @expectedException InvalidArgumentException
63
     */
64
    public function testThrowsExceptionOnInvalidAxisDimension()
65
    {
66
        $widget = new LineChart();
67
        $widget->setAxis('z', array('foo', 'bar'));
68
    }
69
}
70