Completed
Pull Request — master (#93)
by lee
12:27
created

CurrentWeatherGroupTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 90
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 18
loc 90
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 46 1
A testRewind() 9 9 1
A testCurrent() 0 8 1
A testNext() 9 9 1
A testValid() 0 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Copyright Zikula Foundation 2014 - Zikula Application Framework
4
 *
5
 * This work is contributed to the Zikula Foundation under one or more
6
 * Contributor Agreements and licensed to You under the following license:
7
 *
8
 * @license GNU/LGPv3 (or at your option any later version).
9
 * @package OpenWeatherMap-PHP-Api
10
 *
11
 * Please see the NOTICE file distributed with this source code for further
12
 * information regarding copyright and licensing.
13
 */
14
 
15
namespace Cmfcmf\OpenWeatherMap\Tests\OpenWeatherMap;
16
17
use \Cmfcmf\OpenWeatherMap\CurrentWeatherGroup;
18
19
class CurrentWeatherGroupTest extends \PHPUnit_Framework_TestCase
20
{
21
    protected $fakeJson;
22
    protected $currentWeatherGroup;
23
24
    public function setUp()
25
    {
26
        $this->fakeJson = '{
27
            "list":[{
28
                "id":1851632,
29
                "dt":1406106000,
30
                "coord":{"lon":138.933334,"lat":34.966671},
31
                "sys":{"type":3,"id":168940,"message":0.0297,"country":"US","sunrise":1427723751,"sunset":1427768967},
32
                "name":"Shuzenji",
33
                "main":{
34
                    "temp":298.77,
35
                    "temp_min":298.77,
36
                    "temp_max":298.774,
37
                    "pressure":1005.93,
38
                    "sea_level":1018.18,
39
                    "grnd_level":1005.93,
40
                    "humidity":87
41
                },
42
                "weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],
43
                "clouds":{"all":88},
44
                "wind":{"speed":5.71,"deg":229.501},
45
                "dt_txt":"2014-07-23 09:00:00"
46
            },{
47
                "id":1851632,
48
                "dt":1406106000,
49
                "coord":{"lon":138.933334,"lat":34.966671},
50
                "sys":{"type":3,"id":168940,"message":0.0297,"country":"US","sunrise":1427723751,"sunset":1427768967},
51
                "name":"Shuzenji",
52
                "main":{
53
                    "temp":298.77,
54
                    "temp_min":298.77,
55
                    "temp_max":298.774,
56
                    "pressure":1005.93,
57
                    "sea_level":1018.18,
58
                    "grnd_level":1005.93,
59
                    "humidity":87
60
                },
61
                "weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],
62
                "clouds":{"all":88},
63
                "wind":{"speed":5.71,"deg":229.501},
64
                "dt_txt":"2014-07-23 09:00:00"
65
            }]
66
        }';
67
        $this->fakeJson = json_decode($this->fakeJson);
68
        $this->currentWeatherGroup = new CurrentWeatherGroup($this->fakeJson, 'metric');
69
    }
70
71 View Code Duplication
    public function testRewind()
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...
72
    {
73
        $expectIndex = 1851632;
74
        $currentWeatherGroup = $this->currentWeatherGroup;
75
        $currentWeatherGroup->rewind();
76
        $position = $currentWeatherGroup->key();
77
78
        $this->assertSame($expectIndex, $position);
79
    }
80
81
    public function testCurrent()
82
    {
83
        $currentWeatherGroup = $this->currentWeatherGroup;
84
        $currentWeatherGroup->rewind();
85
        $current = $currentWeatherGroup->current();
86
87
        $this->assertInternalType('object', $current);
88
    }
89 View Code Duplication
    public function testNext()
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...
90
    {
91
        $expectIndex = 1851632;
92
        $currentWeatherGroup = $this->currentWeatherGroup;
93
        $currentWeatherGroup->next();
94
        $position = $currentWeatherGroup->key();
95
96
        $this->assertSame($expectIndex, $position);
97
    }
98
99
    public function testValid()
100
    {
101
        $currentWeatherGroup = $this->currentWeatherGroup;
102
        $currentWeatherGroup->rewind();
103
        $currentWeatherGroup->next();
104
        $result = $currentWeatherGroup->valid();
105
106
        $this->assertTrue($result);
107
    }
108
}
109