diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..c1606df --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,57 @@ +# .github/workflows/code_checks.yaml +name: Code_Checks + +on: ["push", "pull_request"] + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: ['7.4'] + stability: [ prefer-stable ] + experimental: [false] + include: + - php: '7.4' + stability: prefer-lowest + - php: '8.0' + - php: '8.1' + - php: '8.2' + + name: PHP ${{ matrix.php }} - ${{ matrix.stability }} tests + steps: + # basically git clone + - uses: actions/checkout@v3 + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ~/.composer/cache/files + key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + + # use PHP of specific version + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: pcov + coverage: pcov + + - name: Install dependencies + run: | + composer install --verbose --prefer-dist --no-interaction -o + + - name: Execute tests + run: vendor/bin/phpunit -c ./tests/phpunit.xml.dist ./tests --verbose + + cs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + coverage: none # disable xdebug, pcov + - run: composer install --no-progress + - run: ./vendor/bin/phpcs --encoding=utf-8 --extensions=php --standard=./tests/phpcs.xml -nsp ./ + diff --git a/.gitignore b/.gitignore index 4430eed..7e4c780 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ Desktop.ini # Vagrant files /.vagrant/ + +.phpunit.result.cache +tests/clover.xml \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 69f3391..0000000 --- a/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -language: php -dist: trusty - -before_script: - - composer self-update - - composer install --verbose --prefer-dist --no-interaction -o - -script: - - composer test - - composer phpcs - -notifications: - email: false - -jobs: - include: - - php: 5.6 - before_script: - - composer require "phpunit/phpunit":"5.*" - - php: 7.0 - - php: 7.1 - - php: 7.2 - - php: 7.3 - - php: 7.4 - - php: 8.0 - dist: xenial - before_script: - - composer require "phpunit/phpunit":"8.*" - - php: nightly - dist: xenial - before_script: - - composer require "phpunit/phpunit":"9.*" - allow_failures: - - php: nightly - diff --git a/CHANGELOG.md b/CHANGELOG.md index 986ede8..540e019 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -## v2.2.0 (April XXth, 2019) +## v2.2.1 (xxx) +- Drop support of php < 7.4 + +## v2.2.0 (Feb 17th, 2021) +- Added support for php 8.0 - Added option power factor for Si factor, ie for square (2) and cubic (3) - Added new Physical Quantity volume flow with commonly used units - Added lowercase aliases for temperature units @@ -14,7 +18,6 @@ - Additional unit for power: dBm - Fixed native unit for mass as gram - ## v2.1.0 (July 24th, 2016) - Added getUnitDefinitions() method to PhysicalQuantity classes, to get a raw list of UnitofMeasure objects defined on that quantity - Added UPPERCASE templating support for autogenerated metric units to support names like MEGA_METERS, for example. diff --git a/README.md b/README.md index 402723a..c53b03e 100644 --- a/README.md +++ b/README.md @@ -43,17 +43,17 @@ isTooTallToRideThisTrain( new Length(2, 'm') ); ``` ## Installation -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). +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). -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: +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: - vendor namespace 'PhpUnitsOfMeasure\' maps to the library's base directory 'source/' See the documentation of your autoloader for further instructions. ### Project Tags and Versions -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. +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. -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. +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. ## Use @@ -239,7 +239,7 @@ class Length extends AbstractPhysicalQuantity 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. ### Adding New Physical Quantities -[Physical quantities](http://en.wikipedia.org/wiki/Physical_quantity) are categories of measurable values, like mass, length, force, etc. +[Physical quantities](https://en.wikipedia.org/wiki/Physical_quantity) are categories of measurable values, like mass, length, force, etc. 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. diff --git a/composer.json b/composer.json index 1e92638..925b9c8 100644 --- a/composer.json +++ b/composer.json @@ -27,12 +27,12 @@ }, "require": { - "php": ">=5.6.0" + "php": ">=7.4" }, "require-dev": { - "phpunit/phpunit": "6.*", - "squizlabs/php_codesniffer": "3.5.*" + "phpunit/phpunit": "^9.5", + "squizlabs/php_codesniffer": "^3.7" }, "replace": { diff --git a/tests/AbstractPhysicalQuantityTest.php b/tests/AbstractPhysicalQuantityTest.php index a74c277..239e364 100644 --- a/tests/AbstractPhysicalQuantityTest.php +++ b/tests/AbstractPhysicalQuantityTest.php @@ -2,14 +2,10 @@ namespace PhpUnitsOfMeasureTest; -use \PHPUnit\Framework\TestCase; +use PHPUnit\Framework\TestCase; use PhpUnitsOfMeasure\AbstractPhysicalQuantity; use PhpUnitsOfMeasure\UnitOfMeasureInterface; use PhpUnitsOfMeasure\Exception\PhysicalQuantityMismatch; -use PhpUnitsOfMeasure\Exception\DuplicateUnitNameOrAlias; -use PhpUnitsOfMeasure\Exception\NonNumericValue; -use PhpUnitsOfMeasure\Exception\NonStringUnitName; -use PhpUnitsOfMeasure\Exception\UnknownUnitOfMeasure; use PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Wonkicity; use PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Woogosity; @@ -20,11 +16,11 @@ * * @runTestsInSeparateProcesses */ -class AbstractPhysicalQuantityTest extends \PHPUnit\Framework\TestCase +class AbstractPhysicalQuantityTest extends TestCase { protected function getTestUnitOfMeasure($name, $aliases = []) { - $newUnit = $this->getMockBuilder('PhpUnitsOfMeasure\UnitOfMeasureInterface') + $newUnit = $this->getMockBuilder(UnitOfMeasureInterface::class) ->getMock(); $newUnit->method('getName') ->willReturn($name); @@ -43,7 +39,7 @@ function ($value) use ($aliases) { /** * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::addUnit */ - public function testAddUnit() + public function testAddUnit(): void { $newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict']); @@ -53,10 +49,10 @@ public function testAddUnit() /** * @dataProvider exceptionProducingUnitsProvider * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::addUnit - * @expectedException \PhpUnitsOfMeasure\Exception\DuplicateUnitNameOrAlias */ - public function testAddUnitFailsOnNameCollision($unitName, $unitAliases) + public function testAddUnitFailsOnNameCollision($unitName, $unitAliases): void { + $this->expectException(\PhpUnitsOfMeasure\Exception\DuplicateUnitNameOrAlias::class); $newUnit = $this->getTestUnitOfMeasure($unitName, $unitAliases); Wonkicity::addUnit($newUnit); @@ -65,7 +61,7 @@ public function testAddUnitFailsOnNameCollision($unitName, $unitAliases) /** * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::getUnit */ - public function testGetUnit() + public function testGetUnit(): void { $unit = Wonkicity::getUnit('u'); @@ -74,49 +70,49 @@ public function testGetUnit() /** * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::getUnit - * @expectedException \PhpUnitsOfMeasure\Exception\UnknownUnitOfMeasure */ - public function testGetUnitFailsOnUnknownUnit() + public function testGetUnitFailsOnUnknownUnit(): void { + $this->expectException(\PhpUnitsOfMeasure\Exception\UnknownUnitOfMeasure::class); Wonkicity::getUnit('someUnknownUnit'); } /** * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::__construct */ - public function testInstantiateNewUnit() + public function testInstantiateNewUnit(): void { $value = new Wonkicity(1.234, 'quatloos'); } /** * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::__construct - * @expectedException \PhpUnitsOfMeasure\Exception\NonNumericValue */ - public function testInstantiateNewUnitNonNumericValue() + public function testInstantiateNewUnitNonNumericValue(): void { + $this->expectException(\PhpUnitsOfMeasure\Exception\NonNumericValue::class); $value = new Wonkicity('string', 'quatloos'); } /** * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::__construct - * @expectedException \PhpUnitsOfMeasure\Exception\NonStringUnitName */ - public function testInstantiateNewUnitNonStringUnit() + public function testInstantiateNewUnitNonStringUnit(): void { + $this->expectException(\PhpUnitsOfMeasure\Exception\NonStringUnitName::class); $value = new Wonkicity(1.234, 42); } /** * @dataProvider quantityConversionsProvider * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::toUnit - * @expectedException \PhpUnitsOfMeasure\Exception\UnknownUnitOfMeasure */ public function testConvertToUnknownUnitThrowsException( AbstractPhysicalQuantity $value, $arbitraryUnit, $valueInArbitraryUnit - ) { + ): void { + $this->expectException(\PhpUnitsOfMeasure\Exception\UnknownUnitOfMeasure::class); $value->toUnit('someUnknownUnit'); } @@ -128,7 +124,7 @@ public function testUnitConvertsToArbitraryUnit( AbstractPhysicalQuantity $value, $arbitraryUnit, $valueInArbitraryUnit - ) { + ): void { $this->assertSame($valueInArbitraryUnit, $value->toUnit($arbitraryUnit)); } @@ -136,20 +132,19 @@ public function testUnitConvertsToArbitraryUnit( * @dataProvider toStringProvider * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::__toString */ - public function testToString(AbstractPhysicalQuantity $value, $string) + public function testToString(AbstractPhysicalQuantity $value, $string): void { $this->assertSame($string, (string) $value); } /** - * * @dataProvider quantityConversionsProvider */ public function testSerialize( AbstractPhysicalQuantity $value, $arbitraryUnit, $valueInArbitraryUnit - ) { + ): void { serialize($value); } @@ -160,7 +155,7 @@ public function testUnserialize( AbstractPhysicalQuantity $value, $arbitraryUnit, $valueInArbitraryUnit - ) { + ): void { $unserializedValue = unserialize(serialize($value)); $this->assertSame($valueInArbitraryUnit, $unserializedValue->toUnit($arbitraryUnit)); @@ -176,9 +171,9 @@ public function testAdd( AbstractPhysicalQuantity $secondValue, $sumString, $diffString - ) { + ): void { if ($shouldThrowException) { - $this->expectException('PhpUnitsOfMeasure\Exception\PhysicalQuantityMismatch'); + $this->expectException(PhysicalQuantityMismatch::class); } $sum = $firstValue->add($secondValue); @@ -198,9 +193,9 @@ public function testSubtract( AbstractPhysicalQuantity $secondValue, $sumString, $diffString - ) { + ): void { if ($shouldThrowException) { - $this->expectException('PhpUnitsOfMeasure\Exception\PhysicalQuantityMismatch'); + $this->expectException(PhysicalQuantityMismatch::class); } $difference = $firstValue->subtract($secondValue); @@ -213,11 +208,11 @@ public function testSubtract( /** * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::getUnitDefinitions */ - public function testGetAllUnits() + public function testGetAllUnits(): void { $array = Wonkicity::getUnitDefinitions(); - $this->assertTrue(is_array($array)); + $this->assertIsArray($array); $expected = array(Wonkicity::getUnit('u'), Wonkicity::getUnit('v')); $this->assertEquals($array, $expected); @@ -226,7 +221,7 @@ public function testGetAllUnits() /** * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::isUnitDefined */ - public function testIsUnitDefined() + public function testIsUnitDefined(): void { $newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']); Wonkicity::addUnit($newUnit); @@ -245,7 +240,7 @@ public function testIsUnitDefined() /** * @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::listAllUnits */ - public function testListAllUnits() + public function testListAllUnits(): void { $newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']); Wonkicity::addUnit($newUnit); @@ -263,7 +258,7 @@ public function testListAllUnits() * 1) The name of the new unit to test * 2) The set of aliases for the new unit to test */ - public function exceptionProducingUnitsProvider() + public function exceptionProducingUnitsProvider(): array { return [ ['u', []], // new name / existing name collision @@ -279,7 +274,7 @@ public function exceptionProducingUnitsProvider() * 2) The unit name to which to convert * 3) The expected resulting value of the conversion */ - public function quantityConversionsProvider() + public function quantityConversionsProvider(): array { return [ [new Wonkicity(2, 'u'), 'u', 2], @@ -296,7 +291,7 @@ public function quantityConversionsProvider() * 1) The object which will be cast to a string * 2) the expected resulting string from the conversion */ - public function toStringProvider() + public function toStringProvider(): array { return [ [new Wonkicity(2, 'u'), '2 u'], @@ -316,7 +311,7 @@ public function toStringProvider() * 4) The string-cast result of a sum operation with the two operands (ignored for errors) * 5) The string-cast result of a subtraction operation with the two operands (ignored for errors) */ - public function arithmeticProvider() + public function arithmeticProvider(): array { return [ [false, new Wonkicity(2, 'u'), new Wonkicity(2.5, 'u'), '4.5 u', '-0.5 u'], diff --git a/tests/DemonstrationTests.php b/tests/DemonstrationTests.php index 626c03b..b8c915b 100644 --- a/tests/DemonstrationTests.php +++ b/tests/DemonstrationTests.php @@ -2,16 +2,10 @@ namespace PhpUnitsOfMeasureTest; -use \PHPUnit\Framework\TestCase; +use PHPUnit\Framework\TestCase; use PhpUnitsOfMeasure\UnitOfMeasure; -use PhpUnitsOfMeasure\AbstractDerivedPhysicalQuantity; -use PhpUnitsOfMeasure\DerivedPhysicalQuantityFactory; -use PhpUnitsOfMeasure\PhysicalQuantity\UnknownDerivedPhysicalQuantity; -use PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Plooposity; -use PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Pumpalumpiness; use PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Wigginess; -use PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Wonkicity; use PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Woogosity; /** @@ -32,9 +26,9 @@ * * @runTestsInSeparateProcesses */ -class DemonstrationTests extends \PHPUnit\Framework\TestCase +class DemonstrationTests extends TestCase { - public function testInstantiatingQuantities() + public function testInstantiatingQuantities(): void { // New quantities are created like this, with // the class name being the physical quantity that @@ -44,25 +38,25 @@ public function testInstantiatingQuantities() // Note that each unit can be referred to by several names // (for example sopee, sopees, s). $a = new Wigginess(1, 'sopee'); - $this->assertInstanceOf('PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Wigginess', $a); + $this->assertInstanceOf(Wigginess::class, $a); $a = new Wigginess(2.123, 'sopees'); - $this->assertInstanceOf('PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Wigginess', $a); + $this->assertInstanceOf(Wigginess::class, $a); $a = new Wigginess(2.6, 's'); - $this->assertInstanceOf('PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Wigginess', $a); + $this->assertInstanceOf(Wigginess::class, $a); $a = new Wigginess(1, 'tumpet'); - $this->assertInstanceOf('PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Wigginess', $a); + $this->assertInstanceOf(Wigginess::class, $a); $a = new Wigginess(2.123, 'tumpets'); - $this->assertInstanceOf('PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Wigginess', $a); + $this->assertInstanceOf(Wigginess::class, $a); $a = new Wigginess(2.6, 't'); - $this->assertInstanceOf('PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Wigginess', $a); + $this->assertInstanceOf(Wigginess::class, $a); } - public function testStringConversionForQuantities() + public function testStringConversionForQuantities(): void { // Casting physical quantity objects to strings will // produce a reasonable string describing the quantity. @@ -73,7 +67,7 @@ public function testStringConversionForQuantities() $this->assertSame('21.123 t', (string) $a); } - public function testUnitConversionForQuantities() + public function testUnitConversionForQuantities(): void { // Creating equivalent quantities from existing // quantities in different units of measure is done @@ -90,7 +84,7 @@ public function testUnitConversionForQuantities() $this->assertSame(21/2.5, $a->toUnit('t')); } - public function testCreatingNewUnitsForQuantities() + public function testCreatingNewUnitsForQuantities(): void { // New units of measure can be defined and registered // with physical quantities on the fly. @@ -150,7 +144,7 @@ function ($valueInThisUnit) { $this->assertSame((21*2.5)-100, $b->toUnit('eeee')); } - public function testAutomaticSIUnitsForQuantities() + public function testAutomaticSIUnitsForQuantities(): void { // SI units have a standard prefix naming convention to easily // provide powers-of-ten versions of a standard unit. For instance, @@ -164,14 +158,14 @@ public function testAutomaticSIUnitsForQuantities() // for an example of how this is done. $a = new Woogosity(21, 'plurp'); - $this->assertInstanceOf('PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Woogosity', $a); + $this->assertInstanceOf(Woogosity::class, $a); $this->assertSame(21*4.5 * 1e3, $a->toUnit('millilupees')); $this->assertSame(21*4.5 * 1e3, $a->toUnit('ml')); $this->assertSame(21*4.5 / 1e6, $a->toUnit('megalupees')); $this->assertSame(21*4.5 / 1e6, $a->toUnit('Ml')); } - public function testAddQuantities() + public function testAddQuantities(): void { // Two quantities of equivalent value can be summed // by calling the add method. @@ -179,11 +173,11 @@ public function testAddQuantities() $b = new Wigginess(2, 'tumpet'); $c = $a->add($b); - $this->assertInstanceOf('PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Wigginess', $c); + $this->assertInstanceOf(Wigginess::class, $c); $this->assertSame(3 + (2*2.5), $c->toUnit('sopee')); } - public function testSubtractQuantities() + public function testSubtractQuantities(): void { // Similar to the add method, subtract called on the // left-hand-side operand object will subtract the @@ -192,7 +186,7 @@ public function testSubtractQuantities() $b = new Wigginess(2, 'tumpet'); $c = $a->subtract($b); - $this->assertInstanceOf('PhpUnitsOfMeasureTest\Fixtures\PhysicalQuantity\Wigginess', $c); + $this->assertInstanceOf(Wigginess::class, $c); $this->assertSame(3 - (2*2.5), $c->toUnit('sopee')); } } diff --git a/tests/Fixtures/PhysicalQuantity/Wigginess.php b/tests/Fixtures/PhysicalQuantity/Wigginess.php index 6102d5a..cc2ba7d 100644 --- a/tests/Fixtures/PhysicalQuantity/Wigginess.php +++ b/tests/Fixtures/PhysicalQuantity/Wigginess.php @@ -9,7 +9,7 @@ class Wigginess extends AbstractPhysicalQuantity { protected static $unitDefinitions; - protected static function initialize() + protected static function initialize(): void { $native = UnitOfMeasure::nativeUnitFactory('s'); $native->addAlias('sopee'); diff --git a/tests/Fixtures/PhysicalQuantity/Wonkicity.php b/tests/Fixtures/PhysicalQuantity/Wonkicity.php index ff06a4d..5ff59ef 100644 --- a/tests/Fixtures/PhysicalQuantity/Wonkicity.php +++ b/tests/Fixtures/PhysicalQuantity/Wonkicity.php @@ -9,7 +9,7 @@ class Wonkicity extends AbstractPhysicalQuantity { protected static $unitDefinitions; - protected static function initialize() + protected static function initialize(): void { $native = UnitOfMeasure::nativeUnitFactory('u'); $native->addAlias('uvee'); diff --git a/tests/Fixtures/PhysicalQuantity/Woogosity.php b/tests/Fixtures/PhysicalQuantity/Woogosity.php index 0b47a64..1974ce1 100644 --- a/tests/Fixtures/PhysicalQuantity/Woogosity.php +++ b/tests/Fixtures/PhysicalQuantity/Woogosity.php @@ -12,7 +12,7 @@ class Woogosity extends AbstractPhysicalQuantity protected static $unitDefinitions; - protected static function initialize() + protected static function initialize(): void { $native = UnitOfMeasure::nativeUnitFactory('l'); $native->addAlias('lupee'); diff --git a/tests/PhysicalQuantity/AbstractPhysicalQuantityTestCase.php b/tests/PhysicalQuantity/AbstractPhysicalQuantityTestCase.php index e8b2650..d956eb3 100644 --- a/tests/PhysicalQuantity/AbstractPhysicalQuantityTestCase.php +++ b/tests/PhysicalQuantity/AbstractPhysicalQuantityTestCase.php @@ -2,19 +2,20 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; -use \PHPUnit\Framework\TestCase; +use PHPUnit\Framework\TestCase; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; /** * This is a parent class for all the PhysicalQuantity childrens' test cases. */ -abstract class AbstractPhysicalQuantityTestCase extends \PHPUnit\Framework\TestCase +abstract class AbstractPhysicalQuantityTestCase extends TestCase { - protected $supportedUnitsWithAliases = []; + protected array $supportedUnitsWithAliases = []; /** * Verify that the object instantiates without error. */ - public function testConstructorSucceeds() + public function testConstructorSucceeds(): void { $this->instantiateTestQuantity(); } @@ -23,7 +24,7 @@ public function testConstructorSucceeds() * Convert to each of the known supported units, verifying that no * exceptions are thrown. */ - public function testSupportedUnits() + public function testSupportedUnits(): void { $quantity = $this->instantiateTestQuantity(); @@ -34,8 +35,6 @@ public function testSupportedUnits() /** * Build a test object of the target physical quantity. - * - * @return PhysicalQuantityInterface */ - abstract protected function instantiateTestQuantity(); + abstract protected function instantiateTestQuantity(): PhysicalQuantityInterface; } diff --git a/tests/PhysicalQuantity/AccelerationTest.php b/tests/PhysicalQuantity/AccelerationTest.php index 410c895..5732ef2 100644 --- a/tests/PhysicalQuantity/AccelerationTest.php +++ b/tests/PhysicalQuantity/AccelerationTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\Acceleration; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class AccelerationTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'm/s^2', 'm/s²', 'meter per second squared', @@ -15,7 +16,7 @@ class AccelerationTest extends AbstractPhysicalQuantityTestCase 'metres per second squared', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new Acceleration(1, 'm/s^2'); } diff --git a/tests/PhysicalQuantity/AngleTest.php b/tests/PhysicalQuantity/AngleTest.php index 63ed22b..281c9d2 100644 --- a/tests/PhysicalQuantity/AngleTest.php +++ b/tests/PhysicalQuantity/AngleTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\Angle; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class AngleTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'rad', 'radian', 'radians', @@ -249,18 +250,18 @@ class AngleTest extends AbstractPhysicalQuantityTestCase 'yas', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new Angle(1, 'deg'); } - public function testToDegrees() + public function testToDegrees(): void { $angle = new Angle(2 * M_PI, 'rad'); $this->assertEquals(360, $angle->toUnit('deg')); } - public function testToRadians() + public function testToRadians(): void { $angle = new Angle(720, 'degree'); $this->assertEquals(M_PI * 4, $angle->toUnit('rad')); diff --git a/tests/PhysicalQuantity/AreaTest.php b/tests/PhysicalQuantity/AreaTest.php index deb16ff..260245b 100644 --- a/tests/PhysicalQuantity/AreaTest.php +++ b/tests/PhysicalQuantity/AreaTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\Area; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class AreaTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'm^2', 'm²', 'meter squared', @@ -161,12 +162,12 @@ class AreaTest extends AbstractPhysicalQuantityTestCase 'acres', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new Area(1, 'm^2'); } - public function testToHectares() + public function testToHectares(): void { $area = new Area(3, 'ha'); @@ -177,7 +178,7 @@ public function testToHectares() * There aren't lots of super nice conversions between ac -> m^2, * so we'll check that it's close. */ - public function testToAcres() + public function testToAcres(): void { $area = new Area(13, 'ac'); @@ -186,13 +187,13 @@ public function testToAcres() $this->assertEquals(52609.133491, $area); } - public function testToAre() + public function testToAre(): void { $area = new Area(100, 'm^2'); $this->assertEquals(1, $area->toUnit('are')); } - public function testToDecare() + public function testToDecare(): void { $area = new Area(1000, 'm^2'); $this->assertEquals(1, $area->toUnit('decare')); diff --git a/tests/PhysicalQuantity/ElectricCurrentTest.php b/tests/PhysicalQuantity/ElectricCurrentTest.php index 7c0cb35..0c3d65a 100644 --- a/tests/PhysicalQuantity/ElectricCurrentTest.php +++ b/tests/PhysicalQuantity/ElectricCurrentTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\ElectricCurrent; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class ElectricCurrentTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'A', 'amp', 'amps', @@ -114,7 +115,7 @@ class ElectricCurrentTest extends AbstractPhysicalQuantityTestCase 'yoctoamperes', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new ElectricCurrent(1, 'A'); } diff --git a/tests/PhysicalQuantity/EnergyTest.php b/tests/PhysicalQuantity/EnergyTest.php index c666f9a..1a46534 100644 --- a/tests/PhysicalQuantity/EnergyTest.php +++ b/tests/PhysicalQuantity/EnergyTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\Energy; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class EnergyTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'Wh', 'watt hour', 'watt hours', @@ -72,30 +73,30 @@ class EnergyTest extends AbstractPhysicalQuantityTestCase 'megacalories', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new Energy(1, 'Wh'); } - public function testToKilowattHour() + public function testToKilowattHour(): void { $quantity = new Energy(1000, 'Wh'); $this->assertEquals(1, $quantity->toUnit('kWh')); } - public function testToWattHour() + public function testToWattHour(): void { $quantity = new Energy(1, 'kWh'); $this->assertEquals(1000, $quantity->toUnit('Wh')); } - public function testToMegaJoule() + public function testToMegaJoule(): void { $quantity = new Energy(1, 'kWh'); $this->assertEquals(3.6, $quantity->toUnit('megajoule')); } - public function testToJoule() + public function testToJoule(): void { $quantity = new Energy(1, 'Wh'); $this->assertEquals(3600, $quantity->toUnit('joule')); diff --git a/tests/PhysicalQuantity/LengthTest.php b/tests/PhysicalQuantity/LengthTest.php index 8ad854f..db4dd61 100644 --- a/tests/PhysicalQuantity/LengthTest.php +++ b/tests/PhysicalQuantity/LengthTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\Length; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class LengthTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'm', 'meter', 'meters', @@ -203,42 +204,42 @@ class LengthTest extends AbstractPhysicalQuantityTestCase ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new Length(1, 'm'); } - public function testToMillimeters() + public function testToMillimeters(): void { $quantity = new Length(5, 'm'); $this->assertEquals(5000, $quantity->toUnit('mm')); } - public function testToMegameters() + public function testToMegameters(): void { $quantity = new Length(5, 'm'); $this->assertEquals(5/1e6, $quantity->toUnit('Mm')); } - public function testToInches() + public function testToInches(): void { $quantity = new Length(2, 'ft'); $this->assertEquals(24, $quantity->toUnit('in')); } - public function testToNauticalMiles() + public function testToNauticalMiles(): void { $quantity = new Length(3704, 'm'); $this->assertEquals(2, $quantity->toUnit('nmi')); } - public function testToScandinavianMil() + public function testToScandinavianMil(): void { $quantity = new Length(20000, 'm'); $this->assertEquals(2, $quantity->toUnit('mil')); } - public function testToAstronomicalUnit() + public function testToAstronomicalUnit(): void { $quantity = new Length(150000000, 'km'); $this->assertEquals(1.0026880683402668, $quantity->toUnit('AU')); diff --git a/tests/PhysicalQuantity/LuminousIntensityTest.php b/tests/PhysicalQuantity/LuminousIntensityTest.php index 204158d..b62ba6d 100644 --- a/tests/PhysicalQuantity/LuminousIntensityTest.php +++ b/tests/PhysicalQuantity/LuminousIntensityTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\LuminousIntensity; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class LuminousIntensityTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'cd', 'candela', 'Ycd', @@ -51,7 +52,7 @@ class LuminousIntensityTest extends AbstractPhysicalQuantityTestCase 'yoctocandela', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new LuminousIntensity(1, 'cd'); } diff --git a/tests/PhysicalQuantity/MassTest.php b/tests/PhysicalQuantity/MassTest.php index 12b65e8..8126f41 100644 --- a/tests/PhysicalQuantity/MassTest.php +++ b/tests/PhysicalQuantity/MassTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\Mass; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class MassTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'kg', 'kilogram', 'kilograms', @@ -101,30 +102,30 @@ class MassTest extends AbstractPhysicalQuantityTestCase 'tam', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new Mass(1, 'g'); } - public function testToGrams() + public function testToGrams(): void { $quantity = new Mass(5, 'kg'); $this->assertEquals(5000, $quantity->toUnit('g')); } - public function testToMilligrams() + public function testToMilligrams(): void { $quantity = new Mass(5, 'kg'); $this->assertEquals(5*1e6, $quantity->toUnit('mg')); } - public function testToPounds() + public function testToPounds(): void { $quantity = new Mass(16, 'oz'); $this->assertEquals(1, $quantity->toUnit('pound')); } - public function testToStones() + public function testToStones(): void { $quantity = new Mass(14, 'pound'); $this->assertEquals(1, $quantity->toUnit('st')); diff --git a/tests/PhysicalQuantity/PowerTest.php b/tests/PhysicalQuantity/PowerTest.php index 8e872ac..3a52a1a 100644 --- a/tests/PhysicalQuantity/PowerTest.php +++ b/tests/PhysicalQuantity/PowerTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\Power; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class PowerTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'W', 'watt', 'watts', @@ -33,18 +34,18 @@ class PowerTest extends AbstractPhysicalQuantityTestCase 'petawatts', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new Power(1, 'W'); } - public function testToKilowatt() + public function testToKilowatt(): void { $quantity = new Power(1000, 'W'); $this->assertEquals(1, $quantity->toUnit('kW')); } - public function testToWatt() + public function testToWatt(): void { $quantity = new Power(1, 'kW'); $this->assertEquals(1000, $quantity->toUnit('W')); diff --git a/tests/PhysicalQuantity/PressureTest.php b/tests/PhysicalQuantity/PressureTest.php index 06e8a62..a79d07b 100644 --- a/tests/PhysicalQuantity/PressureTest.php +++ b/tests/PhysicalQuantity/PressureTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\Pressure; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class PressureTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'Pa', 'pascal', 'YPa', @@ -86,7 +87,7 @@ class PressureTest extends AbstractPhysicalQuantityTestCase 'pounds per square inch', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new Pressure(1, 'Pa'); } diff --git a/tests/PhysicalQuantity/QuantityTest.php b/tests/PhysicalQuantity/QuantityTest.php index 29ef59c..958c5c5 100644 --- a/tests/PhysicalQuantity/QuantityTest.php +++ b/tests/PhysicalQuantity/QuantityTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\Quantity; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class QuantityTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'mol', 'mole', 'moles', @@ -72,7 +73,7 @@ class QuantityTest extends AbstractPhysicalQuantityTestCase 'yoctomoles', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new Quantity(1, 'mol'); } diff --git a/tests/PhysicalQuantity/SolidAngleTest.php b/tests/PhysicalQuantity/SolidAngleTest.php index a282eed..8c920e6 100644 --- a/tests/PhysicalQuantity/SolidAngleTest.php +++ b/tests/PhysicalQuantity/SolidAngleTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\SolidAngle; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class SolidAngleTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'sr', 'steradian', 'steradians', @@ -72,7 +73,7 @@ class SolidAngleTest extends AbstractPhysicalQuantityTestCase 'yoctosteradians', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new SolidAngle(1, 'steradian'); } diff --git a/tests/PhysicalQuantity/TemperatureTest.php b/tests/PhysicalQuantity/TemperatureTest.php index ff28ea3..f8a65cf 100644 --- a/tests/PhysicalQuantity/TemperatureTest.php +++ b/tests/PhysicalQuantity/TemperatureTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\Temperature; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class TemperatureTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'K', '°K', 'kelvin', @@ -79,7 +80,7 @@ class TemperatureTest extends AbstractPhysicalQuantityTestCase 'romer', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new Temperature(1, 'K'); } diff --git a/tests/PhysicalQuantity/TimeTest.php b/tests/PhysicalQuantity/TimeTest.php index 957d1d8..9a677f2 100644 --- a/tests/PhysicalQuantity/TimeTest.php +++ b/tests/PhysicalQuantity/TimeTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\Time; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class TimeTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 's', 'sec', 'secs', @@ -140,48 +141,48 @@ class TimeTest extends AbstractPhysicalQuantityTestCase 'julian years', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new Time(1, 'sec'); } - public function testToSeconds() + public function testToSeconds(): void { $angle = new Time(5, 'm'); $this->assertEquals(300, $angle->toUnit('seconds')); } - public function testToMinutes() + public function testToMinutes(): void { $angle = new Time(360, 'sec'); $this->assertEquals(6, $angle->toUnit('min')); } - public function testToHours() + public function testToHours(): void { $angle = new Time(120, 'mins'); $this->assertEquals(2, $angle->toUnit('hrs')); } - public function testToDays() + public function testToDays(): void { $angle = new Time(72, 'hours'); $this->assertEquals(3, $angle->toUnit('days')); } - public function testToWeeks() + public function testToWeeks(): void { $angle = new Time(14, 'd'); $this->assertEquals(2, $angle->toUnit('week')); } - public function testToGregorianYears() + public function testToGregorianYears(): void { $angle = new Time(365.2425, 'd'); $this->assertEquals(1, $angle->toUnit('yr')); } - public function testToJulianYears() + public function testToJulianYears(): void { $angle = new Time(365.25, 'd'); $this->assertEquals(1, $angle->toUnit('jyr')); diff --git a/tests/PhysicalQuantity/VelocityTest.php b/tests/PhysicalQuantity/VelocityTest.php index e40d024..ffaa9bc 100644 --- a/tests/PhysicalQuantity/VelocityTest.php +++ b/tests/PhysicalQuantity/VelocityTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\Velocity; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class VelocityTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'm/s', 'meters/sec', 'meters per second', @@ -29,30 +30,30 @@ class VelocityTest extends AbstractPhysicalQuantityTestCase 'knots', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new Velocity(1, 'm/s'); } - public function testToKilometersPerHour() + public function testToKilometersPerHour(): void { $speed = new Velocity(1, 'km/h'); $this->assertEquals(0.277778, $speed->toUnit('m/s'), '', 0.000001); } - public function testToFeetPerSecond() + public function testToFeetPerSecond(): void { $speed = new Velocity(2, 'm/s'); $this->assertEquals(6.561679790026246, $speed->toUnit('ft/s')); } - public function testToKmPerHour() + public function testToKmPerHour(): void { $speed = new Velocity(2, 'mph'); $this->assertEquals(3.218688, $speed->toUnit('km/h'), '', 0.000001); } - public function testToKnot() + public function testToKnot(): void { $speed = new Velocity(2, 'm/s'); $this->assertEquals(3.8876923435786983, $speed->toUnit('knot')); diff --git a/tests/PhysicalQuantity/VolumeTest.php b/tests/PhysicalQuantity/VolumeTest.php index f10be9c..4be4708 100644 --- a/tests/PhysicalQuantity/VolumeTest.php +++ b/tests/PhysicalQuantity/VolumeTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\Volume; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class VolumeTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'm^3', 'm³', 'cubic meter', @@ -84,7 +85,7 @@ class VolumeTest extends AbstractPhysicalQuantityTestCase 'cups', ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new Volume(1, 'm^3'); } diff --git a/tests/UnitOfMeasureTest.php b/tests/UnitOfMeasureTest.php index 03d2075..d9bee8b 100644 --- a/tests/UnitOfMeasureTest.php +++ b/tests/UnitOfMeasureTest.php @@ -2,15 +2,16 @@ namespace PhpUnitsOfMeasureTest; +use PHPUnit\Framework\TestCase; use PhpUnitsOfMeasure\UnitOfMeasure; -class UnitOfMeasureTest extends \PHPUnit\Framework\TestCase +class UnitOfMeasureTest extends TestCase { /** * @covers \PhpUnitsOfMeasure\UnitOfMeasure::__construct * @covers \PhpUnitsOfMeasure\UnitOfMeasure::getName */ - public function testGetName() + public function testGetName(): void { $uom = new UnitOfMeasure( 'quatloos', @@ -27,10 +28,10 @@ function ($valueInThisUnit) { /** * @covers \PhpUnitsOfMeasure\UnitOfMeasure::__construct - * @expectedException \PhpUnitsOfMeasure\Exception\NonStringUnitName */ - public function testConstructWithNonStringName() + public function testConstructWithNonStringName(): void { + $this->expectException(\PhpUnitsOfMeasure\Exception\NonStringUnitName::class); $uom = new UnitOfMeasure( 42, function ($valueInNativeUnit) { @@ -46,7 +47,7 @@ function ($valueInThisUnit) { * @covers \PhpUnitsOfMeasure\UnitOfMeasure::addAlias * @covers \PhpUnitsOfMeasure\UnitOfMeasure::getAliases */ - public function testGetAliases() + public function testGetAliases(): void { $uom = new UnitOfMeasure( 'quatloos', @@ -69,10 +70,10 @@ function ($valueInThisUnit) { /** * @covers \PhpUnitsOfMeasure\UnitOfMeasure::addAlias - * @expectedException \PhpUnitsOfMeasure\Exception\NonStringUnitName */ - public function testAddAliasWithNonStringAlias() + public function testAddAliasWithNonStringAlias(): void { + $this->expectException(\PhpUnitsOfMeasure\Exception\NonStringUnitName::class); $uom = new UnitOfMeasure( 'quatloos', function ($valueInNativeUnit) { @@ -89,7 +90,7 @@ function ($valueInThisUnit) { /** * @covers \PhpUnitsOfMeasure\UnitOfMeasure::isAliasOf */ - public function testIsAliasOf() + public function testIsAliasOf(): void { $uom = new UnitOfMeasure( 'quatloos', @@ -109,7 +110,7 @@ function ($valueInThisUnit) { /** * @covers \PhpUnitsOfMeasure\UnitOfMeasure::isAliasOf */ - public function testIsNotAliasOf() + public function testIsNotAliasOf(): void { $uom = new UnitOfMeasure( 'quatloos', @@ -128,10 +129,11 @@ function ($valueInThisUnit) { /** * @covers \PhpUnitsOfMeasure\UnitOfMeasure::isAliasOf - * @expectedException \PhpUnitsOfMeasure\Exception\NonStringUnitName + * */ - public function testIsAliasOfWithNonStringAlias() + public function testIsAliasOfWithNonStringAlias(): void { + $this->expectException(\PhpUnitsOfMeasure\Exception\NonStringUnitName::class); $uom = new UnitOfMeasure( 'quatloos', function ($valueInNativeUnit) { @@ -150,7 +152,7 @@ function ($valueInThisUnit) { /** * @covers \PhpUnitsOfMeasure\UnitOfMeasure::convertValueFromNativeUnitOfMeasure */ - public function testConvertValueFromNativeUnitOfMeasure() + public function testConvertValueFromNativeUnitOfMeasure(): void { $uom = new UnitOfMeasure( 'quatloos', @@ -167,10 +169,10 @@ function ($valueInThisUnit) { /** * @covers \PhpUnitsOfMeasure\UnitOfMeasure::convertValueFromNativeUnitOfMeasure - * @expectedException \PhpUnitsOfMeasure\Exception\NonNumericValue */ - public function testConvertValueFromNativeUnitOfMeasureWithNonNumericalValue() + public function testConvertValueFromNativeUnitOfMeasureWithNonNumericalValue(): void { + $this->expectException(\PhpUnitsOfMeasure\Exception\NonNumericValue::class); $uom = new UnitOfMeasure( 'quatloos', function ($valueInNativeUnit) { @@ -187,7 +189,7 @@ function ($valueInThisUnit) { /** * @covers \PhpUnitsOfMeasure\UnitOfMeasure::convertValueToNativeUnitOfMeasure */ - public function testConvertValueToNativeUnitOfMeasure() + public function testConvertValueToNativeUnitOfMeasure(): void { $uom = new UnitOfMeasure( 'quatloos', @@ -204,10 +206,10 @@ function ($valueInThisUnit) { /** * @covers \PhpUnitsOfMeasure\UnitOfMeasure::convertValueToNativeUnitOfMeasure - * @expectedException \PhpUnitsOfMeasure\Exception\NonNumericValue */ - public function testConvertValueToNativeUnitOfMeasureWithNonNumericalValue() + public function testConvertValueToNativeUnitOfMeasureWithNonNumericalValue(): void { + $this->expectException(\PhpUnitsOfMeasure\Exception\NonNumericValue::class); $uom = new UnitOfMeasure( 'quatloos', function ($valueInNativeUnit) { diff --git a/tests/phpunit.xml.dist b/tests/phpunit.xml.dist index a561687..cf73b4d 100644 --- a/tests/phpunit.xml.dist +++ b/tests/phpunit.xml.dist @@ -1,10 +1,10 @@ - - + @@ -12,16 +12,16 @@ - + + + ../source + - ../vendor + ../vendor - - ../source - - + + + + - - -