]> git.mxchange.org Git - friendica-addons.git/blob - curweather/vendor/cmfcmf/openweathermap-php-api/tests/Util/UnitTest.php
bd85e16fe2dcae2489832f1329b87b12a623b343
[friendica-addons.git] / curweather / vendor / cmfcmf / openweathermap-php-api / tests / Util / UnitTest.php
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
19 class UnitTest extends \PHPUnit_Framework_TestCase
20 {
21     /**
22      * @var Unit
23      */
24     private $unit;
25
26     const POSITIVE_INT_VALUE = 23;
27
28     const POSITIVE_FLOAT_VALUE = 48.23534;
29
30     const NEGATIVE_INT_VALUE = -30;
31
32     const NEGATIVE_FLOAT_VALUE = -93.45839;
33
34     const ZERO_INT_VALUE = 0;
35
36     const ZERO_FLOAT_VALUE = 0.0;
37
38     public function testGetValueWithPositiveIntValue()
39     {
40         $this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE);
41
42         $this->assertSame((float)self::POSITIVE_INT_VALUE, $this->unit->getValue());
43     }
44
45     public function testGetValueWithPositiveFloatValue()
46     {
47         $this->givenThereIsAUnitWithValue(self::POSITIVE_FLOAT_VALUE);
48
49         $this->assertSame(self::POSITIVE_FLOAT_VALUE, $this->unit->getValue());
50     }
51
52     public function testGetValueWithNegativeIntValue()
53     {
54         $this->givenThereIsAUnitWithValue(self::NEGATIVE_INT_VALUE);
55
56         $this->assertSame((float)self::NEGATIVE_INT_VALUE, $this->unit->getValue());
57     }
58
59     public function testGetValueWithNegativeFloatValue()
60     {
61         $this->givenThereIsAUnitWithValue(self::NEGATIVE_FLOAT_VALUE);
62
63         $this->assertSame(self::NEGATIVE_FLOAT_VALUE, $this->unit->getValue());
64     }
65
66     public function testGetValueWithZeroIntValue()
67     {
68         $this->givenThereIsAUnitWithValue(self::ZERO_INT_VALUE);
69
70         $this->assertSame((float)self::ZERO_INT_VALUE, $this->unit->getValue());
71     }
72
73     public function testGetValueWithZeroFloatValue()
74     {
75         $this->givenThereIsAUnitWithValue(self::ZERO_FLOAT_VALUE);
76
77         $this->assertSame(self::ZERO_FLOAT_VALUE, $this->unit->getValue());
78     }
79
80     private function givenThereIsAUnitWithValue($value, $unit = null)
81     {
82         $this->unit = $unit === null ? new Unit($value) : new Unit($value, $unit);
83     }
84
85     public function testGetUnitWithEmptyUnit()
86     {
87         $this->givenThereIsAUnitWithUnit("");
88
89         $this->assertSame("", $this->unit->getUnit());
90     }
91
92     public function testGetUnitWithStringAsUnit()
93     {
94         $this->givenThereIsAUnitWithUnit("Hey! I'm cmfcmf");
95
96         $this->assertSame("Hey! I'm cmfcmf", $this->unit->getUnit());
97     }
98
99     public function testCelsiusFixture()
100     {
101         $this->givenThereIsAUnitWithUnit("celsius");
102
103         $this->assertSame("&deg;C", $this->unit->getUnit());
104     }
105
106     public function testFahrenheitFixture()
107     {
108         $this->givenThereIsAUnitWithUnit("fahrenheit");
109
110         $this->assertSame("F", $this->unit->getUnit());
111     }
112
113     private function givenThereIsAUnitWithUnit($unit)
114     {
115         $this->unit = new Unit(0, $unit);
116     }
117
118     public function testGetDescriptionWithEmptyDescription()
119     {
120         $this->givenThereIsAUnitWithDescription("");
121
122         $this->assertSame("", $this->unit->getDescription());
123     }
124
125     public function testGetDescriptionWithStringAsDescription()
126     {
127         $this->givenThereIsAUnitWithDescription("Hey! I'm cmfcmf");
128
129         $this->assertSame("Hey! I'm cmfcmf", $this->unit->getDescription());
130     }
131
132     private function givenThereIsAUnitWithDescription($description)
133     {
134         $this->unit = new Unit(0, "", $description);
135     }
136
137     public function testGetFormattedWithoutUnit()
138     {
139         $this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE);
140
141         $this->assertEquals(self::POSITIVE_INT_VALUE, $this->unit->getFormatted());
142         $this->assertEquals($this->unit->getValue(), $this->unit->getFormatted());
143     }
144
145     public function testGetFormattedWithUnit()
146     {
147         $this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE, 'K');
148
149         $this->assertEquals(self::POSITIVE_INT_VALUE . ' K', $this->unit->getFormatted());
150         $this->assertEquals($this->unit->getValue() . ' ' . $this->unit->getUnit(), $this->unit->getFormatted());
151     }
152
153     public function testToString()
154     {
155         $this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE, 'K');
156
157         $this->assertEquals($this->unit->getFormatted(), $this->unit);
158     }
159 }