Completed
Pull Request — master (#96)
by Christian
06:33 queued 04:32
created

WeatherHistoryTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 25.81 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 16
loc 62
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testRewind() 0 8 1
A testCurrent() 0 7 1
A testNext() 0 8 1
A testValid() 0 6 1
A testJsonHasCountryAndPopulation() 8 8 1
A testJsonWithRainKey() 8 8 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\Tests\FakeData;
18
use \Cmfcmf\OpenWeatherMap\WeatherHistory;
19
20
class WeatherHistoryTest extends \PHPUnit_Framework_TestCase
21
{
22
    protected $fakeJson;
23
    protected $history;
24
25
    protected function setUp()
26
    {
27
        $this->fakeJson = json_decode(FakeData::WEATHER_HISTORY_JSON, true);
28
        $this->history = new WeatherHistory($this->fakeJson, 'Berlin');
29
    }
30
31
    public function testRewind()
32
    {
33
        $expectIndex = 0;
34
        $this->history->rewind();
35
        $position = $this->history->key();
36
37
        $this->assertSame($expectIndex, $position);
38
    }
39
40
    public function testCurrent()
41
    {
42
        $this->history->rewind();
43
        $current = $this->history->current();
44
45
        $this->assertInternalType('object', $current);
46
    }
47
48
    public function testNext()
49
    {
50
        $expectIndex = 1;
51
        $this->history->next();
52
        $position = $this->history->key();
53
54
        $this->assertSame($expectIndex, $position);
55
    }
56
57
    public function testValid()
58
    {
59
        $this->history->rewind();
60
        $this->history->next();
61
        $this->assertTrue($this->history->valid());
62
    }
63
64 View Code Duplication
    public function testJsonHasCountryAndPopulation()
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...
65
    {
66
        $fakeJson = json_decode(FakeData::WEATHER_HISTORY_WITH_COUNTRY_JSON, true);
67
        $history = new WeatherHistory($fakeJson, 'Berlin');
68
69
        $history->rewind();
70
        $this->assertTrue($history->valid());
71
    }
72
73 View Code Duplication
    public function testJsonWithRainKey()
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...
74
    {
75
        $fakeJson = json_decode(FakeData::WEATHER_HISTORY_WITH_RAIN_JSON, true);
76
        $history = new WeatherHistory($fakeJson, 'Berlin');
77
        
78
        $history->rewind();
79
        $this->assertTrue($history->valid());
80
    }
81
}
82