1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use PHPUnit\Framework\TestCase; |
4
|
|
|
use Bhhaskin\WeatherBee\Util\Unit; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @coversDefaultClass Bhhaskin\WeatherBee\Util\Unit |
8
|
|
|
*/ |
9
|
|
|
final class UnitTest extends TestCase |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @covers ::__construct |
14
|
|
|
*/ |
15
|
|
|
public function testUnitCreation() |
16
|
|
|
{ |
17
|
|
|
$this->assertInstanceOf(Unit::class, new Unit(0.0, "", "")); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @covers ::getValue |
22
|
|
|
*/ |
23
|
|
|
public function testGetValue() |
24
|
|
|
{ |
25
|
|
|
$unit = new Unit(1.0, "", ""); |
26
|
|
|
$this->assertEquals($unit->getValue(), 1.0); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @covers ::getUnit |
31
|
|
|
*/ |
32
|
|
|
public function testgetUnit() |
33
|
|
|
{ |
34
|
|
|
$unit = new Unit(0.0, "foo", ""); |
35
|
|
|
$this->assertEquals($unit->getUnit(), "foo"); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @covers ::getUnit |
40
|
|
|
*/ |
41
|
|
|
public function testgetUnitFahrenheit() |
42
|
|
|
{ |
43
|
|
|
$unit = new Unit(0.0, "fahrenheit", ""); |
44
|
|
|
$this->assertEquals($unit->getUnit(), "F"); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @covers ::getUnit |
49
|
|
|
*/ |
50
|
|
|
public function testgetUnitCelsius() |
51
|
|
|
{ |
52
|
|
|
$unit = new Unit(0.0, "celsius", ""); |
53
|
|
|
$this->assertEquals($unit->getUnit(), "C"); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @covers ::getDescription |
58
|
|
|
*/ |
59
|
|
|
public function testGetDecription() |
60
|
|
|
{ |
61
|
|
|
$unit = new Unit(0.0, "", "foo"); |
62
|
|
|
$this->assertEquals($unit->getDescription(), "foo"); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @covers ::getDescription |
67
|
|
|
*/ |
68
|
|
|
public function getFormatted() |
69
|
|
|
{ |
70
|
|
|
$unit = new Unit(1.1, "fahrenheit", ""); |
71
|
|
|
$this->assertEquals($unit->getFormatted(), "1.1 F"); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @covers ::__toString |
76
|
|
|
*/ |
77
|
|
|
public function testToString() |
78
|
|
|
{ |
79
|
|
|
$unit = new Unit(1.1, "fahrenheit", ""); |
80
|
|
|
$this->assertEquals($unit, "1.1 F"); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.