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\Util; |
16
|
|
|
|
17
|
|
|
use \Cmfcmf\OpenWeatherMap\Util\Unit; |
18
|
|
|
use \Cmfcmf\OpenWeatherMap\Util\Temperature; |
19
|
|
|
|
20
|
|
|
class TemperatureTest extends \PHPUnit_Framework_TestCase |
21
|
|
|
{ |
22
|
|
|
protected $unit = 'Berlin'; |
23
|
|
|
protected $temperature; |
24
|
|
|
protected $nowTemp = '298.77'; |
25
|
|
|
protected $description = 'This is a description'; |
26
|
|
|
|
27
|
|
|
protected function setUp() |
28
|
|
|
{ |
29
|
|
|
$units = 'Berlin'; |
30
|
|
|
$fakeTempNow = 298.77; |
31
|
|
|
$fakeTempMin = 298.77; |
32
|
|
|
$fakeTempMax = 298.774; |
33
|
|
|
$tempNowUnit = new Unit($fakeTempNow, $units, $this->description); |
34
|
|
|
$tempMinUnit = new Unit($fakeTempMin, $units, $this->description); |
35
|
|
|
$tempMaxUnit = new Unit($fakeTempMax, $units, $this->description); |
36
|
|
|
$this->temperature = new Temperature($tempNowUnit, $tempMinUnit, $tempMaxUnit); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
View Code Duplication |
public function test__toString() |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$expectStr = $this->nowTemp; |
42
|
|
|
$expectStr .= ' ' . $this->unit; |
43
|
|
|
$temp = $this->temperature; |
44
|
|
|
$str = $temp->__toString(); |
45
|
|
|
|
46
|
|
|
$this->assertSame($expectStr, $str); |
47
|
|
|
$this->assertInternalType('string', $str); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
public function testGetUnit() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$expectUnit = $this->unit; |
53
|
|
|
$temp = $this->temperature; |
54
|
|
|
$unit = $temp->getUnit(); |
55
|
|
|
|
56
|
|
|
$this->assertSame($expectUnit, $unit); |
57
|
|
|
$this->assertInternalType('string', $unit); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testGetValue() |
61
|
|
|
{ |
62
|
|
|
$expectValue = $this->nowTemp; |
|
|
|
|
63
|
|
|
$temp = $this->temperature; |
64
|
|
|
$value = $temp->getValue(); |
65
|
|
|
|
66
|
|
|
$this->assertInternalType('double', $value); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
View Code Duplication |
public function testGetDescription() |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$expectDescription = $this->description; |
72
|
|
|
$temp = $this->temperature; |
73
|
|
|
$description = $temp->getDescription(); |
74
|
|
|
|
75
|
|
|
$this->assertSame($expectDescription, $description); |
76
|
|
|
$this->assertInternalType('string', $description); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
View Code Duplication |
public function testGetFormatted() |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
$expectFormattedString = $this->nowTemp; |
82
|
|
|
$expectFormattedString .= ' ' . $this->unit; |
83
|
|
|
$temp = $this->temperature; |
84
|
|
|
$formattedString = $temp->getFormatted(); |
85
|
|
|
|
86
|
|
|
$this->assertSame($expectFormattedString, $formattedString); |
87
|
|
|
$this->assertInternalType('string', $formattedString); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
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.