TextTest::testJsonForMultipleItems()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 14
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
namespace CarlosIO\Geckoboard\Tests\Widgets;
4
5
use CarlosIO\Geckoboard\Widgets\Text;
6
use CarlosIO\Geckoboard\Data\Text\Item;
7
8
class TextTest extends \PHPUnit_Framework_TestCase
9
{
10
    /**
11
     * Test with an empty dataset.
12
     */
13
    public function testJsonForAnEmptyData()
14
    {
15
        $widget = new Text();
16
        $json = json_encode($widget->getData());
17
        $this->assertEquals('{"item":[]}', $json);
18
    }
19
20
    /**
21
     * Test with an incomplete dataset.
22
     */
23 View Code Duplication
    public function testJsonForSomeData()
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...
24
    {
25
        $widget = new Text();
26
        $firstItem = new Item();
27
        $firstItem->setText('first text');
28
        $widget->addItem($firstItem);
29
        $json = json_encode($widget->getData());
30
        $this->assertEquals('{"item":[{"text":"first text","type":0}]}', $json);
31
    }
32
33
    /**
34
     * Test with one full dataset.
35
     */
36 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...
37
    {
38
        $widget = new Text();
39
        $firstItem = new Item();
40
        $firstItem->setText('first text');
41
        $firstItem->setType(Item::TYPE_INFO);
42
        $widget->addItem($firstItem);
43
        $json = json_encode($widget->getData());
44
        $this->assertEquals('{"item":[{"text":"first text","type":2}]}', $json);
45
    }
46
47
    /**
48
     * Test with more than one dataset.
49
     */
50
    public function testJsonForMultipleItems()
51
    {
52
        $widget = new Text();
53
        $firstItem = new Item();
54
        $secondItem = new Item();
55
        $firstItem->setText('first text');
56
        $secondItem->setType(Item::TYPE_ALERT);
57
        $widget->addItem($firstItem);
58
        $widget->addItem($secondItem);
59
        $widget->setItems($widget->getItems());
60
61
        $json = json_encode($widget->getData());
62
        $this->assertEquals('{"item":[{"text":"first text","type":0},{"text":"","type":1}]}', $json);
63
    }
64
}
65