Skip to content

Commit 676a643

Browse files
committed
feat: modernise, drop support for php < 7.4, migrate tests and config for phpUnit 9
1 parent 9c68bcb commit 676a643

29 files changed

+202
-192
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ Desktop.ini
2525

2626
# Vagrant files
2727
/.vagrant/
28+
29+
.phpunit.result.cache
30+
tests/clover.xml

.travis.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@ sudo: false
33
dist: trusty
44

55
php:
6-
- '5.5'
7-
- '5.6'
8-
- '7.0'
9-
- '7.1'
10-
- '7.2'
11-
- nightly
12-
- hhvm
6+
- '7.4'
7+
- '8.0'
8+
- '8.1'
9+
- '8.2'
1310

1411
before_script:
1512
- composer self-update
@@ -21,10 +18,3 @@ script:
2118

2219
notifications:
2320
email: false
24-
25-
matrix:
26-
allow_failures:
27-
- php: '5.5'
28-
- php: nightly
29-
- php: hhvm
30-

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v2.2.0 (xxx)
2+
3+
- Drop support of php < 7.4
4+
15
## v2.1.0 (July 24th, 2016)
26
- Added getUnitDefinitions() method to PhysicalQuantity classes, to get a raw list of UnitofMeasure objects defined on that quantity
37
- Added UPPERCASE templating support for autogenerated metric units to support names like MEGA_METERS, for example.

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ isTooTallToRideThisTrain( new Length(2, 'm') );
4343
```
4444

4545
## Installation
46-
This library is best included in your projects via Composer. See the [Composer website](http://getcomposer.org/) for more details, and see the [Packagist.org site for this library](https://packagist.org/packages/php-units-of-measure/php-units-of-measure).
46+
This library is best included in your projects via Composer. See the [Composer website](https://getcomposer.org/) for more details, and see the [Packagist.org site for this library](https://packagist.org/packages/php-units-of-measure/php-units-of-measure).
4747

48-
If you'd prefer to manually include this library as a dependency in your project, then it is recommended that you use a [PSR-4](http://www.php-fig.org/psr/psr-4/) compliant PHP autoloader. The mapping between this project's root namespace and its base directory is:
48+
If you'd prefer to manually include this library as a dependency in your project, then it is recommended that you use a [PSR-4](https://www.php-fig.org/psr/psr-4/) compliant PHP autoloader. The mapping between this project's root namespace and its base directory is:
4949
- vendor namespace 'PhpUnitsOfMeasure\' maps to the library's base directory 'source/'
5050

5151
See the documentation of your autoloader for further instructions.
5252

5353
### Project Tags and Versions
54-
This project follows the guidelines set out in [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html). In general, versions are of the form 'X.Y.Z', and increments to X denote backward-incompatible major changes.
54+
This project follows the guidelines set out in [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html). In general, versions are of the form 'X.Y.Z', and increments to X denote backward-incompatible major changes.
5555

56-
It is recommended that if your project includes this project as a dependency and you are using an automated dependency management tool such as [Composer](http://getcomposer.org/), then you should 'pin' the major version (X) and allow only variations in 'Y' (minor changes) and 'Z' (bugfixes). See the documentation of your dependency manager for more details.
56+
It is recommended that if your project includes this project as a dependency and you are using an automated dependency management tool such as [Composer](https://getcomposer.org/), then you should 'pin' the major version (X) and allow only variations in 'Y' (minor changes) and 'Z' (bugfixes). See the documentation of your dependency manager for more details.
5757

5858

5959
## Use
@@ -239,7 +239,7 @@ class Length extends AbstractPhysicalQuantity
239239
Now any program which uses `Length` will start with the cubits unit already built in. Note that here we used the more concise linear unit factory method, but the result is equivalent to the expanded form calling the `UnitOfMeasure` constructor, as used above. Also, notice that the `static` keyword was used instead of the class name, though either would be acceptable in this case.
240240

241241
### Adding New Physical Quantities
242-
[Physical quantities](http://en.wikipedia.org/wiki/Physical_quantity) are categories of measurable values, like mass, length, force, etc.
242+
[Physical quantities](https://en.wikipedia.org/wiki/Physical_quantity) are categories of measurable values, like mass, length, force, etc.
243243

244244
For physical quantities that are not already present in this library, it will be necessary to write a class to support a new one. All physical quantities implement the `\PhpUnitsOfMeasure\PhysicalQuantityInterface` interface, typically extend the `\PhpUnitsOfMeasure\AbstractPhysicalQuantity` class, and typically have only an `initialize()` method which creates the quantity's units of measure. See above for typical examples of physical quantity classes and of how to add new units to a quantity class.
245245

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
},
2828

2929
"require": {
30-
"php": ">=5.5.0"
30+
"php": ">=7.4"
3131
},
3232

3333
"require-dev": {
34-
"phpunit/phpunit": "4.8.*",
35-
"squizlabs/php_codesniffer": "2.8.1"
34+
"phpunit/phpunit": "^9.5",
35+
"squizlabs/php_codesniffer": "^2.8.1"
3636
},
3737

3838
"replace": {

tests/AbstractPhysicalQuantityTest.php

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22

33
namespace PhpUnitsOfMeasureTest;
44

5-
use PHPUnit_Framework_TestCase;
5+
use PHPUnit\Framework\TestCase;
66
use PhpUnitsOfMeasure\AbstractPhysicalQuantity;
77
use PhpUnitsOfMeasure\UnitOfMeasureInterface;
88
use PhpUnitsOfMeasure\Exception\PhysicalQuantityMismatch;
9-
use PhpUnitsOfMeasure\Exception\DuplicateUnitNameOrAlias;
10-
use PhpUnitsOfMeasure\Exception\NonNumericValue;
11-
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
12-
use PhpUnitsOfMeasure\Exception\UnknownUnitOfMeasure;
139
use PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Wonkicity;
1410
use PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Woogosity;
1511

@@ -20,11 +16,11 @@
2016
*
2117
* @runTestsInSeparateProcesses
2218
*/
23-
class AbstractPhysicalQuantityTest extends PHPUnit_Framework_TestCase
19+
class AbstractPhysicalQuantityTest extends TestCase
2420
{
2521
protected function getTestUnitOfMeasure($name, $aliases = [])
2622
{
27-
$newUnit = $this->getMockBuilder('PhpUnitsOfMeasure\UnitOfMeasureInterface')
23+
$newUnit = $this->getMockBuilder(UnitOfMeasureInterface::class)
2824
->getMock();
2925
$newUnit->method('getName')
3026
->willReturn($name);
@@ -43,7 +39,7 @@ function ($value) use ($aliases) {
4339
/**
4440
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::addUnit
4541
*/
46-
public function testAddUnit()
42+
public function testAddUnit(): void
4743
{
4844
$newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict']);
4945

@@ -53,10 +49,10 @@ public function testAddUnit()
5349
/**
5450
* @dataProvider exceptionProducingUnitsProvider
5551
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::addUnit
56-
* @expectedException \PhpUnitsOfMeasure\Exception\DuplicateUnitNameOrAlias
5752
*/
58-
public function testAddUnitFailsOnNameCollision($unitName, $unitAliases)
53+
public function testAddUnitFailsOnNameCollision($unitName, $unitAliases): void
5954
{
55+
$this->expectException(\PhpUnitsOfMeasure\Exception\DuplicateUnitNameOrAlias::class);
6056
$newUnit = $this->getTestUnitOfMeasure($unitName, $unitAliases);
6157

6258
Wonkicity::addUnit($newUnit);
@@ -65,7 +61,7 @@ public function testAddUnitFailsOnNameCollision($unitName, $unitAliases)
6561
/**
6662
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::getUnit
6763
*/
68-
public function testGetUnit()
64+
public function testGetUnit(): void
6965
{
7066
$unit = Wonkicity::getUnit('u');
7167

@@ -74,49 +70,50 @@ public function testGetUnit()
7470

7571
/**
7672
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::getUnit
77-
* @expectedException \PhpUnitsOfMeasure\Exception\UnknownUnitOfMeasure
7873
*/
79-
public function testGetUnitFailsOnUnknownUnit()
74+
public function testGetUnitFailsOnUnknownUnit(): void
8075
{
76+
$this->expectException(\PhpUnitsOfMeasure\Exception\UnknownUnitOfMeasure::class);
8177
Wonkicity::getUnit('someUnknownUnit');
8278
}
8379

8480
/**
8581
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::__construct
8682
*/
87-
public function testInstantiateNewUnit()
83+
public function testInstantiateNewUnit(): void
8884
{
8985
$value = new Wonkicity(1.234, 'quatloos');
9086
}
9187

9288
/**
9389
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::__construct
94-
* @expectedException \PhpUnitsOfMeasure\Exception\NonNumericValue
9590
*/
96-
public function testInstantiateNewUnitNonNumericValue()
91+
public function testInstantiateNewUnitNonNumericValue(): void
9792
{
93+
$this->expectException(\PhpUnitsOfMeasure\Exception\NonNumericValue::class);
9894
$value = new Wonkicity('string', 'quatloos');
9995
}
10096

10197
/**
10298
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::__construct
103-
* @expectedException \PhpUnitsOfMeasure\Exception\NonStringUnitName
10499
*/
105-
public function testInstantiateNewUnitNonStringUnit()
100+
public function testInstantiateNewUnitNonStringUnit(): void
106101
{
102+
$this->expectException(\PhpUnitsOfMeasure\Exception\NonStringUnitName::class);
107103
$value = new Wonkicity(1.234, 42);
108104
}
109105

110106
/**
111107
* @dataProvider quantityConversionsProvider
112108
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::toUnit
113-
* @expectedException \PhpUnitsOfMeasure\Exception\UnknownUnitOfMeasure
114109
*/
115110
public function testConvertToUnknownUnitThrowsException(
116111
AbstractPhysicalQuantity $value,
117112
$arbitraryUnit,
118113
$valueInArbitraryUnit
119-
) {
114+
): void
115+
{
116+
$this->expectException(\PhpUnitsOfMeasure\Exception\UnknownUnitOfMeasure::class);
120117
$value->toUnit('someUnknownUnit');
121118
}
122119

@@ -128,28 +125,29 @@ public function testUnitConvertsToArbitraryUnit(
128125
AbstractPhysicalQuantity $value,
129126
$arbitraryUnit,
130127
$valueInArbitraryUnit
131-
) {
128+
): void
129+
{
132130
$this->assertSame($valueInArbitraryUnit, $value->toUnit($arbitraryUnit));
133131
}
134132

135133
/**
136134
* @dataProvider toStringProvider
137135
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::__toString
138136
*/
139-
public function testToString(AbstractPhysicalQuantity $value, $string)
137+
public function testToString(AbstractPhysicalQuantity $value, $string): void
140138
{
141139
$this->assertSame($string, (string) $value);
142140
}
143141

144142
/**
145-
*
146143
* @dataProvider quantityConversionsProvider
147144
*/
148145
public function testSerialize(
149146
AbstractPhysicalQuantity $value,
150147
$arbitraryUnit,
151148
$valueInArbitraryUnit
152-
) {
149+
): void
150+
{
153151
serialize($value);
154152
}
155153

@@ -160,7 +158,8 @@ public function testUnserialize(
160158
AbstractPhysicalQuantity $value,
161159
$arbitraryUnit,
162160
$valueInArbitraryUnit
163-
) {
161+
): void
162+
{
164163
$unserializedValue = unserialize(serialize($value));
165164

166165
$this->assertSame($valueInArbitraryUnit, $unserializedValue->toUnit($arbitraryUnit));
@@ -176,9 +175,10 @@ public function testAdd(
176175
AbstractPhysicalQuantity $secondValue,
177176
$sumString,
178177
$diffString
179-
) {
178+
): void
179+
{
180180
if ($shouldThrowException) {
181-
$this->setExpectedException('PhpUnitsOfMeasure\Exception\PhysicalQuantityMismatch');
181+
$this->expectException(PhysicalQuantityMismatch::class);
182182
}
183183

184184
$sum = $firstValue->add($secondValue);
@@ -198,9 +198,11 @@ public function testSubtract(
198198
AbstractPhysicalQuantity $secondValue,
199199
$sumString,
200200
$diffString
201-
) {
201+
): void
202+
{
202203
if ($shouldThrowException) {
203-
$this->setExpectedException('PhpUnitsOfMeasure\Exception\PhysicalQuantityMismatch');
204+
$this->expectException(PhysicalQuantityMismatch::class);
205+
204206
}
205207

206208
$difference = $firstValue->subtract($secondValue);
@@ -213,11 +215,11 @@ public function testSubtract(
213215
/**
214216
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::getUnitDefinitions
215217
*/
216-
public function testGetAllUnits()
218+
public function testGetAllUnits(): void
217219
{
218220
$array = Wonkicity::getUnitDefinitions();
219221

220-
$this->assertTrue(is_array($array));
222+
$this->assertIsArray($array);
221223

222224
$expected = array(Wonkicity::getUnit('u'), Wonkicity::getUnit('v'));
223225
$this->assertEquals($array, $expected);
@@ -226,7 +228,7 @@ public function testGetAllUnits()
226228
/**
227229
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::isUnitDefined
228230
*/
229-
public function testIsUnitDefined()
231+
public function testIsUnitDefined(): void
230232
{
231233
$newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
232234
Wonkicity::addUnit($newUnit);
@@ -245,7 +247,7 @@ public function testIsUnitDefined()
245247
/**
246248
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::listAllUnits
247249
*/
248-
public function testListAllUnits()
250+
public function testListAllUnits(): void
249251
{
250252
$newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
251253
Wonkicity::addUnit($newUnit);
@@ -263,7 +265,7 @@ public function testListAllUnits()
263265
* 1) The name of the new unit to test
264266
* 2) The set of aliases for the new unit to test
265267
*/
266-
public function exceptionProducingUnitsProvider()
268+
public function exceptionProducingUnitsProvider(): array
267269
{
268270
return [
269271
['u', []], // new name / existing name collision
@@ -279,7 +281,7 @@ public function exceptionProducingUnitsProvider()
279281
* 2) The unit name to which to convert
280282
* 3) The expected resulting value of the conversion
281283
*/
282-
public function quantityConversionsProvider()
284+
public function quantityConversionsProvider(): array
283285
{
284286
return [
285287
[new Wonkicity(2, 'u'), 'u', 2],
@@ -296,7 +298,7 @@ public function quantityConversionsProvider()
296298
* 1) The object which will be cast to a string
297299
* 2) the expected resulting string from the conversion
298300
*/
299-
public function toStringProvider()
301+
public function toStringProvider(): array
300302
{
301303
return [
302304
[new Wonkicity(2, 'u'), '2 u'],
@@ -316,7 +318,7 @@ public function toStringProvider()
316318
* 4) The string-cast result of a sum operation with the two operands (ignored for errors)
317319
* 5) The string-cast result of a subtraction operation with the two operands (ignored for errors)
318320
*/
319-
public function arithmeticProvider()
321+
public function arithmeticProvider(): array
320322
{
321323
return [
322324
[false, new Wonkicity(2, 'u'), new Wonkicity(2.5, 'u'), '4.5 u', '-0.5 u'],

0 commit comments

Comments
 (0)