Completed
Push — master ( 9529d6...d756e3 )
by Carlos
10s
created

testSetDisplayAsTimeDuration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace CarlosIO\Geckoboard\Tests\Widgets;
4
5
use CarlosIO\Geckoboard\Widgets\NumberAndSecondaryStat;
6
7
class NumberAndSecondaryStatTest extends \PHPUnit_Framework_TestCase
8
{
9
    public function testJsonForAnEmptyData()
10
    {
11
        $widget = new NumberAndSecondaryStat();
12
        $json = json_encode($widget->getData());
13
        $this->assertEquals('{"item":[{"text":"","value":0}],"type":null}', $json);
14
    }
15
16
    public function testGetAndSetWidgetId()
17
    {
18
        $widget = new NumberAndSecondaryStat();
19
        $this->assertNull($widget->getId());
20
21
        $testId = 'test-id';
22
        $this->assertSame($testId, $widget->setId('test-id')->getId());
23
    }
24
25
    public function testJsonForSomeData()
26
    {
27
        $widget = new NumberAndSecondaryStat();
28
        $widget->setMainValue(35);
29
        $json = json_encode($widget->getData());
30
        $this->assertEquals('{"item":[{"text":"","value":35}],"type":null}', $json);
31
    }
32
33 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...
34
    {
35
        $widget = new NumberAndSecondaryStat();
36
        $widget->setMainValue(100);
37
        $widget->setSecondaryValue(50);
38
        $widget->setMainPrefix('EUR');
39
        $json = json_encode($widget->getData());
40
        $this->assertEquals('{"item":[{"text":"","value":100,"prefix":"EUR"},{"text":"","value":50}],"type":null}', $json);
41
    }
42
43 View Code Duplication
    public function testSettingADifferentType()
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...
44
    {
45
        $widget = new NumberAndSecondaryStat();
46
        $widget->setMainValue(100);
47
        $widget->setType(NumberAndSecondaryStat::TYPE_REVERSE);
48
        $json = json_encode($widget->getData());
49
        $this->assertEquals('{"item":[{"text":"","value":100}],"type":"reverse"}', $json);
50
    }
51
52
    public function testSetGetMainText()
53
    {
54
        $text = 'text';
55
        $widget = new NumberAndSecondaryStat();
56
        $widget->setMainText($text);
57
58
        $this->assertSame($text, $widget->getMainText());
59
        $data = $widget->getData();
60
        $this->assertSame($text, $data['item'][0]['text']);
61
    }
62
63
    public function testSetGetSecondaryText()
64
    {
65
        $text = 'text';
66
        $widget = new NumberAndSecondaryStat();
67
        $widget->setSecondaryValue(1);
68
        $widget->setSecondaryText($text);
69
70
        $this->assertSame($text, $widget->getSecondaryText());
71
        $data = $widget->getData();
72
        $this->assertSame($text, $data['item'][1]['text']);
73
    }
74
75
    public function testAbsolute()
76
    {
77
        $widget = new NumberAndSecondaryStat();
78
        $widget->setAbsolute(true);
79
80
        $data = $widget->getData();
81
82
        $this->assertTrue($data['absolute']);
83
    }
84
85
    public function testSetDisplayAsTimeDuration()
86
    {
87
        $widget = new NumberAndSecondaryStat();
88
        $widget->setDisplayAsTimeDuration(true);
89
90
        $data = $widget->getData();
91
92
        $this->assertSame('time_duration', $data['item'][0]['type']);
93
    }
94
}
95