11<?php
22
3+ declare (strict_types=1 );
4+
35namespace PhpUnitsOfMeasureTest ;
46
5- use PHPUnit_Framework_TestCase ;
7+ use PHPUnit \ Framework \ TestCase ;
68use PhpUnitsOfMeasure \AbstractPhysicalQuantity ;
79use PhpUnitsOfMeasure \UnitOfMeasureInterface ;
810use PhpUnitsOfMeasure \Exception \PhysicalQuantityMismatch ;
2022 *
2123 * @runTestsInSeparateProcesses
2224 */
23- class AbstractPhysicalQuantityTest extends PHPUnit_Framework_TestCase
25+ class AbstractPhysicalQuantityTest extends TestCase
2426{
2527 protected function getTestUnitOfMeasure ($ name , $ aliases = [])
2628 {
@@ -45,6 +47,8 @@ function ($value) use ($aliases) {
4547 */
4648 public function testAddUnit ()
4749 {
50+ $ this ->expectNotToPerformAssertions ();
51+
4852 $ newUnit = $ this ->getTestUnitOfMeasure ('noconflict ' , ['definitelynoconflict ' ]);
4953
5054 Wonkicity::addUnit ($ newUnit );
@@ -53,10 +57,11 @@ public function testAddUnit()
5357 /**
5458 * @dataProvider exceptionProducingUnitsProvider
5559 * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::addUnit
56- * @expectedException \PhpUnitsOfMeasure\Exception\DuplicateUnitNameOrAlias
5760 */
5861 public function testAddUnitFailsOnNameCollision ($ unitName , $ unitAliases )
5962 {
63+ $ this ->expectException (\PhpUnitsOfMeasure \Exception \DuplicateUnitNameOrAlias::class);
64+
6065 $ newUnit = $ this ->getTestUnitOfMeasure ($ unitName , $ unitAliases );
6166
6267 Wonkicity::addUnit ($ newUnit );
@@ -78,6 +83,8 @@ public function testGetUnit()
7883 */
7984 public function testGetUnitFailsOnUnknownUnit ()
8085 {
86+ $ this ->expectException (\PhpUnitsOfMeasure \Exception \UnknownUnitOfMeasure::class);
87+
8188 Wonkicity::getUnit ('someUnknownUnit ' );
8289 }
8390
@@ -86,6 +93,8 @@ public function testGetUnitFailsOnUnknownUnit()
8693 */
8794 public function testInstantiateNewUnit ()
8895 {
96+ $ this ->expectNotToPerformAssertions ();
97+
8998 $ value = new Wonkicity (1.234 , 'quatloos ' );
9099 }
91100
@@ -95,28 +104,32 @@ public function testInstantiateNewUnit()
95104 */
96105 public function testInstantiateNewUnitNonNumericValue ()
97106 {
107+ $ this ->expectException (\PhpUnitsOfMeasure \Exception \NonNumericValue::class);
108+
98109 $ value = new Wonkicity ('string ' , 'quatloos ' );
99110 }
100111
101112 /**
102113 * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::__construct
103- * @expectedException \PhpUnitsOfMeasure\Exception\NonStringUnitName
104114 */
105115 public function testInstantiateNewUnitNonStringUnit ()
106116 {
117+ $ this ->expectException (\PhpUnitsOfMeasure \Exception \NonStringUnitName::class);
118+
107119 $ value = new Wonkicity (1.234 , 42 );
108120 }
109121
110122 /**
111123 * @dataProvider quantityConversionsProvider
112124 * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::toUnit
113- * @expectedException \PhpUnitsOfMeasure\Exception\UnknownUnitOfMeasure
114125 */
115126 public function testConvertToUnknownUnitThrowsException (
116127 AbstractPhysicalQuantity $ value ,
117128 $ arbitraryUnit ,
118129 $ valueInArbitraryUnit
119130 ) {
131+ $ this ->expectException (\PhpUnitsOfMeasure \Exception \UnknownUnitOfMeasure::class);
132+
120133 $ value ->toUnit ('someUnknownUnit ' );
121134 }
122135
@@ -129,7 +142,7 @@ public function testUnitConvertsToArbitraryUnit(
129142 $ arbitraryUnit ,
130143 $ valueInArbitraryUnit
131144 ) {
132- $ this ->assertSame ($ valueInArbitraryUnit , $ value ->toUnit ($ arbitraryUnit ));
145+ $ this ->assertEquals ($ valueInArbitraryUnit , $ value ->toUnit ($ arbitraryUnit ));
133146 }
134147
135148 /**
@@ -150,6 +163,8 @@ public function testSerialize(
150163 $ arbitraryUnit ,
151164 $ valueInArbitraryUnit
152165 ) {
166+ $ this ->expectNotToPerformAssertions ();
167+
153168 serialize ($ value );
154169 }
155170
@@ -163,7 +178,7 @@ public function testUnserialize(
163178 ) {
164179 $ unserializedValue = unserialize (serialize ($ value ));
165180
166- $ this ->assertSame ($ valueInArbitraryUnit , $ unserializedValue ->toUnit ($ arbitraryUnit ));
181+ $ this ->assertEquals ($ valueInArbitraryUnit , $ unserializedValue ->toUnit ($ arbitraryUnit ));
167182 }
168183
169184 /**
@@ -178,7 +193,7 @@ public function testAdd(
178193 $ diffString
179194 ) {
180195 if ($ shouldThrowException ) {
181- $ this ->setExpectedException ( ' PhpUnitsOfMeasure\Exception\PhysicalQuantityMismatch ' );
196+ $ this ->expectException (\ PhpUnitsOfMeasure \Exception \PhysicalQuantityMismatch::class );
182197 }
183198
184199 $ sum = $ firstValue ->add ($ secondValue );
@@ -200,7 +215,7 @@ public function testSubtract(
200215 $ diffString
201216 ) {
202217 if ($ shouldThrowException ) {
203- $ this ->setExpectedException ( ' PhpUnitsOfMeasure\Exception\PhysicalQuantityMismatch ' );
218+ $ this ->expectException (\ PhpUnitsOfMeasure \Exception \PhysicalQuantityMismatch::class );
204219 }
205220
206221 $ difference = $ firstValue ->subtract ($ secondValue );
@@ -230,26 +245,26 @@ public function testIsUnitDefined()
230245 {
231246 $ newUnit = $ this ->getTestUnitOfMeasure ('noconflict ' , ['definitelynoconflict_1 ' , 'definitelynoconflict_2 ' ]);
232247 Wonkicity::addUnit ($ newUnit );
233-
248+
234249 $ someExistingUnits = ['u ' , 'uvees ' , 'v ' , 'vorp ' , 'noconflict ' , 'definitelynoconflict_1 ' , 'definitelynoconflict_2 ' ];
235250 $ unexistingUnits = ['kg ' , 'l ' , 'definitelynoconflict_ ' ];
236-
251+
237252 foreach ($ someExistingUnits as $ someExistingUnit ) {
238253 $ this ->assertTrue (Wonkicity::isUnitDefined ($ someExistingUnit ), "$ someExistingUnit is not defined " );
239254 }
240255 foreach ($ unexistingUnits as $ unexistingUnit ) {
241256 $ this ->assertFalse (Wonkicity::isUnitDefined ($ unexistingUnit ), "$ unexistingUnit is not defined " );
242257 }
243258 }
244-
259+
245260 /**
246261 * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::listAllUnits
247262 */
248263 public function testListAllUnits ()
249264 {
250265 $ newUnit = $ this ->getTestUnitOfMeasure ('noconflict ' , ['definitelynoconflict_1 ' , 'definitelynoconflict_2 ' ]);
251266 Wonkicity::addUnit ($ newUnit );
252-
267+
253268 $ allUnits = Wonkicity::listAllUnits ();
254269 $ expected = [];
255270 $ expected ['u ' ] = ['uvee ' , 'uvees ' ];
0 commit comments