1
|
|
|
<?php |
2
|
|
|
namespace Bhhaskin\WeatherBee\Tests; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
use Bhhaskin\WeatherBee\Util\{Temperature, Unit}; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @coversDefaultClass Bhhaskin\WeatherBee\Util\Temperature |
9
|
|
|
*/ |
10
|
|
|
class TemperatureTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @covers ::__construct |
14
|
|
|
*/ |
15
|
|
|
public function testTemperatureCreation() |
16
|
|
|
{ |
17
|
|
|
$unitTest = new Unit(1.1); |
18
|
|
|
$this->assertInstanceOf(Temperature::class, new Temperature( |
19
|
|
|
$unitTest, |
20
|
|
|
$unitTest, |
21
|
|
|
$unitTest |
22
|
|
|
)); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @covers ::getValue |
27
|
|
|
*/ |
28
|
|
|
public function testGetValue() |
29
|
|
|
{ |
30
|
|
|
$unit = new Unit(1.0); |
31
|
|
|
$temperature = new Temperature($unit, $unit, $unit); |
32
|
|
|
$this->assertEquals($temperature->getValue(), 1.0); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @covers ::getUnit |
37
|
|
|
*/ |
38
|
|
|
public function testgetUnit() |
39
|
|
|
{ |
40
|
|
|
$unit = new Unit(0.0, "foo"); |
41
|
|
|
$temperature = new Temperature($unit, $unit, $unit); |
42
|
|
|
$this->assertEquals($temperature->getUnit(), "foo"); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @covers ::getUnit |
47
|
|
|
*/ |
48
|
|
|
public function testgetUnitFahrenheit() |
49
|
|
|
{ |
50
|
|
|
$unit = new Unit(0.0, "fahrenheit"); |
51
|
|
|
$temperature = new Temperature($unit, $unit, $unit); |
52
|
|
|
$this->assertEquals($temperature->getUnit(), "F"); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @covers ::getUnit |
57
|
|
|
*/ |
58
|
|
|
public function testgetUnitCelsius() |
59
|
|
|
{ |
60
|
|
|
$unit = new Unit(0.0, "celsius"); |
61
|
|
|
$temperature = new Temperature($unit, $unit, $unit); |
62
|
|
|
$this->assertEquals($temperature->getUnit(), "C"); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @covers ::getDescription |
67
|
|
|
*/ |
68
|
|
|
public function testGetDecription() |
69
|
|
|
{ |
70
|
|
|
$unit = new Unit(0.0, "", "foo"); |
71
|
|
|
$temperature = new Temperature($unit, $unit, $unit); |
72
|
|
|
$this->assertEquals($temperature->getDescription(), "foo"); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @covers ::getFormatted |
77
|
|
|
*/ |
78
|
|
|
public function testGetFormattedWithUnit() |
79
|
|
|
{ |
80
|
|
|
$unit = new Unit(1.1, "fahrenheit"); |
81
|
|
|
$temperature = new Temperature($unit, $unit, $unit); |
82
|
|
|
$this->assertEquals($temperature->getFormatted(), "1.1 F"); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @covers ::getFormatted |
87
|
|
|
*/ |
88
|
|
|
public function testGetFormattedWithoutUnit() |
89
|
|
|
{ |
90
|
|
|
$unit = new Unit(1.1); |
91
|
|
|
$temperature = new Temperature($unit, $unit, $unit); |
92
|
|
|
$this->assertEquals($temperature->getFormatted(), "1.1"); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @covers ::__toString |
97
|
|
|
*/ |
98
|
|
|
public function testToString() |
99
|
|
|
{ |
100
|
|
|
$unit = new Unit(1.1, "fahrenheit"); |
101
|
|
|
$temperature = new Temperature($unit, $unit, $unit); |
102
|
|
|
$this->assertEquals($temperature, "1.1 F"); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|