Completed
Push — master ( 0f638d...b58a50 )
by Carlos
02:28
created

LeaderBoardTest::canAddThreeItemsOrderAscDuplicatesValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 11
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A LeaderBoardTest::addItem() 0 8 1
1
<?php
2
3
namespace CarlosIO\Geckoboard\Tests\Widgets;
4
5
use CarlosIO\Geckoboard\Data\LeaderBoard\Item;
6
use CarlosIO\Geckoboard\Widgets\LeaderBoard;
7
8
/**
9
 * Class LeaderBoardTest.
10
 */
11
class LeaderBoardTest extends \PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @var LeaderBoard
15
     */
16
    protected $widget;
17
18
    protected function setUp()
19
    {
20
        $this->widget = new LeaderBoard();
21
    }
22
    /**
23
     * @test
24
     */
25
    public function getDataWithNoItems()
26
    {
27
        $json = json_encode($this->widget->getData());
28
        $this->assertEquals('{"items":[]}', $json);
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function canAddSingleItem()
35
    {
36
        $this->widget->setId(123);
37
        $this->addItem('Title text', 10, 2);
38
39
        $json = json_encode($this->widget->getData());
40
        $this->assertEquals('{"items":[{"label":"Title text","value":10,"previous_rank":2}]}', $json);
41
    }
42
43
    /**
44
     * @test
45
     */
46 View Code Duplication
    public function canAddThreeItemsOrderDescByDefault()
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...
47
    {
48
        $this->addItem('Title text', 10);
49
        $this->addItem('Title text2', 15);
50
        $this->addItem('Title text3', 7);
51
52
        $json = json_encode($this->widget->getData());
53
        $this->assertEquals('{"items":[{"label":"Title text2","value":15},{"label":"Title text","value":10},'.
54
            '{"label":"Title text3","value":7}]}', $json);
55
    }
56
57
    /**
58
     * @test
59
     */
60 View Code Duplication
    public function canAddThreeItemsOrderAsc()
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...
61
    {
62
        $this->addItem('Title text', 10);
63
        $this->addItem('Title text2', 15);
64
        $this->addItem('Title text3', 7);
65
66
        $json = json_encode($this->widget->getData(LeaderBoard::SORT_ASC));
67
        $this->assertEquals('{"items":[{"label":"Title text3","value":7},{"label":"Title text","value":10},'.
68
            '{"label":"Title text2","value":15}]}', $json);
69
    }
70
71
    /**
72
     * @param $label
73
     * @param $value
74
     * @param null $previousRanking
75
     */
76
    private function addItem($label, $value, $previousRanking = null)
77
    {
78
        $item = new Item();
79
        $item->setLabel($label)
80
            ->setValue($value)
81
            ->setPreviousRank($previousRanking);
82
        $this->widget->addItem($item);
83
    }
84
}
85