1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace PhpUnitsOfMeasureTest ;
4
6
5
- use PHPUnit_Framework_TestCase ;
7
+ use PHPUnit \ Framework \ TestCase ;
6
8
use PhpUnitsOfMeasure \AbstractPhysicalQuantity ;
7
9
use PhpUnitsOfMeasure \UnitOfMeasureInterface ;
8
10
use PhpUnitsOfMeasure \Exception \PhysicalQuantityMismatch ;
20
22
*
21
23
* @runTestsInSeparateProcesses
22
24
*/
23
- class AbstractPhysicalQuantityTest extends PHPUnit_Framework_TestCase
25
+ class AbstractPhysicalQuantityTest extends TestCase
24
26
{
25
27
protected function getTestUnitOfMeasure ($ name , $ aliases = [])
26
28
{
@@ -45,6 +47,8 @@ function ($value) use ($aliases) {
45
47
*/
46
48
public function testAddUnit ()
47
49
{
50
+ $ this ->expectNotToPerformAssertions ();
51
+
48
52
$ newUnit = $ this ->getTestUnitOfMeasure ('noconflict ' , ['definitelynoconflict ' ]);
49
53
50
54
Wonkicity::addUnit ($ newUnit );
@@ -53,10 +57,11 @@ public function testAddUnit()
53
57
/**
54
58
* @dataProvider exceptionProducingUnitsProvider
55
59
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::addUnit
56
- * @expectedException \PhpUnitsOfMeasure\Exception\DuplicateUnitNameOrAlias
57
60
*/
58
61
public function testAddUnitFailsOnNameCollision ($ unitName , $ unitAliases )
59
62
{
63
+ $ this ->expectException (\PhpUnitsOfMeasure \Exception \DuplicateUnitNameOrAlias::class);
64
+
60
65
$ newUnit = $ this ->getTestUnitOfMeasure ($ unitName , $ unitAliases );
61
66
62
67
Wonkicity::addUnit ($ newUnit );
@@ -78,6 +83,8 @@ public function testGetUnit()
78
83
*/
79
84
public function testGetUnitFailsOnUnknownUnit ()
80
85
{
86
+ $ this ->expectException (\PhpUnitsOfMeasure \Exception \UnknownUnitOfMeasure::class);
87
+
81
88
Wonkicity::getUnit ('someUnknownUnit ' );
82
89
}
83
90
@@ -86,6 +93,8 @@ public function testGetUnitFailsOnUnknownUnit()
86
93
*/
87
94
public function testInstantiateNewUnit ()
88
95
{
96
+ $ this ->expectNotToPerformAssertions ();
97
+
89
98
$ value = new Wonkicity (1.234 , 'quatloos ' );
90
99
}
91
100
@@ -95,28 +104,32 @@ public function testInstantiateNewUnit()
95
104
*/
96
105
public function testInstantiateNewUnitNonNumericValue ()
97
106
{
107
+ $ this ->expectException (\PhpUnitsOfMeasure \Exception \NonNumericValue::class);
108
+
98
109
$ value = new Wonkicity ('string ' , 'quatloos ' );
99
110
}
100
111
101
112
/**
102
113
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::__construct
103
- * @expectedException \PhpUnitsOfMeasure\Exception\NonStringUnitName
104
114
*/
105
115
public function testInstantiateNewUnitNonStringUnit ()
106
116
{
117
+ $ this ->expectException (\PhpUnitsOfMeasure \Exception \NonStringUnitName::class);
118
+
107
119
$ value = new Wonkicity (1.234 , 42 );
108
120
}
109
121
110
122
/**
111
123
* @dataProvider quantityConversionsProvider
112
124
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::toUnit
113
- * @expectedException \PhpUnitsOfMeasure\Exception\UnknownUnitOfMeasure
114
125
*/
115
126
public function testConvertToUnknownUnitThrowsException (
116
127
AbstractPhysicalQuantity $ value ,
117
128
$ arbitraryUnit ,
118
129
$ valueInArbitraryUnit
119
130
) {
131
+ $ this ->expectException (\PhpUnitsOfMeasure \Exception \UnknownUnitOfMeasure::class);
132
+
120
133
$ value ->toUnit ('someUnknownUnit ' );
121
134
}
122
135
@@ -129,7 +142,7 @@ public function testUnitConvertsToArbitraryUnit(
129
142
$ arbitraryUnit ,
130
143
$ valueInArbitraryUnit
131
144
) {
132
- $ this ->assertSame ($ valueInArbitraryUnit , $ value ->toUnit ($ arbitraryUnit ));
145
+ $ this ->assertEquals ($ valueInArbitraryUnit , $ value ->toUnit ($ arbitraryUnit ));
133
146
}
134
147
135
148
/**
@@ -150,6 +163,8 @@ public function testSerialize(
150
163
$ arbitraryUnit ,
151
164
$ valueInArbitraryUnit
152
165
) {
166
+ $ this ->expectNotToPerformAssertions ();
167
+
153
168
serialize ($ value );
154
169
}
155
170
@@ -163,7 +178,7 @@ public function testUnserialize(
163
178
) {
164
179
$ unserializedValue = unserialize (serialize ($ value ));
165
180
166
- $ this ->assertSame ($ valueInArbitraryUnit , $ unserializedValue ->toUnit ($ arbitraryUnit ));
181
+ $ this ->assertEquals ($ valueInArbitraryUnit , $ unserializedValue ->toUnit ($ arbitraryUnit ));
167
182
}
168
183
169
184
/**
@@ -178,7 +193,7 @@ public function testAdd(
178
193
$ diffString
179
194
) {
180
195
if ($ shouldThrowException ) {
181
- $ this ->setExpectedException ( ' PhpUnitsOfMeasure\Exception\PhysicalQuantityMismatch ' );
196
+ $ this ->expectException (\ PhpUnitsOfMeasure \Exception \PhysicalQuantityMismatch::class );
182
197
}
183
198
184
199
$ sum = $ firstValue ->add ($ secondValue );
@@ -200,7 +215,7 @@ public function testSubtract(
200
215
$ diffString
201
216
) {
202
217
if ($ shouldThrowException ) {
203
- $ this ->setExpectedException ( ' PhpUnitsOfMeasure\Exception\PhysicalQuantityMismatch ' );
218
+ $ this ->expectException (\ PhpUnitsOfMeasure \Exception \PhysicalQuantityMismatch::class );
204
219
}
205
220
206
221
$ difference = $ firstValue ->subtract ($ secondValue );
@@ -230,26 +245,26 @@ public function testIsUnitDefined()
230
245
{
231
246
$ newUnit = $ this ->getTestUnitOfMeasure ('noconflict ' , ['definitelynoconflict_1 ' , 'definitelynoconflict_2 ' ]);
232
247
Wonkicity::addUnit ($ newUnit );
233
-
248
+
234
249
$ someExistingUnits = ['u ' , 'uvees ' , 'v ' , 'vorp ' , 'noconflict ' , 'definitelynoconflict_1 ' , 'definitelynoconflict_2 ' ];
235
250
$ unexistingUnits = ['kg ' , 'l ' , 'definitelynoconflict_ ' ];
236
-
251
+
237
252
foreach ($ someExistingUnits as $ someExistingUnit ) {
238
253
$ this ->assertTrue (Wonkicity::isUnitDefined ($ someExistingUnit ), "$ someExistingUnit is not defined " );
239
254
}
240
255
foreach ($ unexistingUnits as $ unexistingUnit ) {
241
256
$ this ->assertFalse (Wonkicity::isUnitDefined ($ unexistingUnit ), "$ unexistingUnit is not defined " );
242
257
}
243
258
}
244
-
259
+
245
260
/**
246
261
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::listAllUnits
247
262
*/
248
263
public function testListAllUnits ()
249
264
{
250
265
$ newUnit = $ this ->getTestUnitOfMeasure ('noconflict ' , ['definitelynoconflict_1 ' , 'definitelynoconflict_2 ' ]);
251
266
Wonkicity::addUnit ($ newUnit );
252
-
267
+
253
268
$ allUnits = Wonkicity::listAllUnits ();
254
269
$ expected = [];
255
270
$ expected ['u ' ] = ['uvee ' , 'uvees ' ];
0 commit comments