From a6929d80d9e369ecc8307a9a991ca8a359f436c5 Mon Sep 17 00:00:00 2001 From: Denis Smetannikov Date: Wed, 21 Apr 2021 21:19:28 +0300 Subject: [PATCH 1/4] strict_types=1 --- .gitattributes | 11 +++ .phan/config.php | 2 + README.md | 2 +- demo.php | 2 + src/Config/Area.php | 2 + src/Config/Config.php | 2 + src/Config/Degree.php | 2 + src/Config/Info.php | 5 +- src/Config/Length.php | 2 + src/Config/Money.php | 2 + src/Config/Temp.php | 2 + src/Config/Time.php | 2 + src/Config/Volume.php | 2 + src/Config/Weight.php | 2 + src/Exception.php | 2 + src/Formatter.php | 8 +- src/Parser.php | 2 + src/Type/AbstractType.php | 2 + src/Type/Area.php | 2 + src/Type/Degree.php | 2 + src/Type/Info.php | 2 + src/Type/Length.php | 2 + src/Type/Money.php | 2 + src/Type/Temp.php | 2 + src/Type/Time.php | 2 + src/Type/Volume.php | 2 + src/Type/Weight.php | 2 + tests/CalcTest.php | 130 +++++++++++++++-------------- tests/CompareTest.php | 70 ++++++++-------- tests/ConfigTest.php | 2 + tests/ConverterTest.php | 3 +- tests/InstancesTest.php | 2 + tests/MagicTest.php | 2 + tests/OutputTest.php | 2 + tests/ParserTest.php | 2 + tests/RoundingTest.php | 2 + tests/RuleTest.php | 3 +- tests/SimpleTypesCodeStyleTest.php | 2 + tests/SimpleTypesComposerTest.php | 2 + tests/SimpleTypesCopyrightTest.php | 3 + tests/SimpleTypesReadmeTest.php | 8 ++ tests/autoload.php | 2 + tests/phpunit-functions.php | 2 + tests/type/AreaTypeTest.php | 2 + tests/type/DegreeTypeTest.php | 2 + tests/type/InfoTypeTest.php | 2 + tests/type/LengthTypeTest.php | 2 + tests/type/TempTypeTest.php | 2 + tests/type/TimeTypeTest.php | 2 + tests/type/TypeTest.php | 2 + tests/type/VolumeTypeTest.php | 2 + tests/type/WeightTypeTest.php | 2 + 52 files changed, 221 insertions(+), 106 deletions(-) diff --git a/.gitattributes b/.gitattributes index 42c0858..4516d0f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11,4 +11,15 @@ # @link https://github.com/JBZoo/SimpleTypes # +/.phan export-ignore +/build export-ignore +/tests export-ignore +/.editorconfig export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.yml export-ignore +/demo.php export-ignore +/phpunit.xml.dist export-ignore +/Makefile export-ignore + * text eol=lf diff --git a/.phan/config.php b/.phan/config.php index 3b7cf03..f08f744 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + $default = include __DIR__ . '/../vendor/jbzoo/codestyle/src/phan/default.php'; return array_merge($default, [ diff --git a/README.md b/README.md index 04d33e3..5fa3698 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # JBZoo / SimpleTypes -[![Build Status](https://travis-ci.org/JBZoo/SimpleTypes.svg)](https://travis-ci.org/JBZoo/SimpleTypes) [![Coverage Status](https://coveralls.io/repos/JBZoo/SimpleTypes/badge.svg)](https://coveralls.io/github/JBZoo/SimpleTypes) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/SimpleTypes/coverage.svg)](https://shepherd.dev/github/JBZoo/SimpleTypes) +[![Build Status](https://travis-ci.org/JBZoo/SimpleTypes.svg)](https://travis-ci.org/JBZoo/SimpleTypes) [![Coverage Status](https://coveralls.io/repos/JBZoo/SimpleTypes/badge.svg)](https://coveralls.io/github/JBZoo/SimpleTypes) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/SimpleTypes/coverage.svg)](https://shepherd.dev/github/JBZoo/SimpleTypes) [![PHP Strict Types](https://img.shields.io/badge/strict__types-%3D1-brightgreen)](https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.strict) [![Stable Version](https://poser.pugx.org/jbzoo/simpletypes/version)](https://packagist.org/packages/jbzoo/simpletypes) [![Latest Unstable Version](https://poser.pugx.org/jbzoo/simpletypes/v/unstable)](https://packagist.org/packages/jbzoo/simpletypes) [![Dependents](https://poser.pugx.org/jbzoo/simpletypes/dependents)](https://packagist.org/packages/jbzoo/simpletypes/dependents?order_by=downloads) [![GitHub Issues](https://img.shields.io/github/issues/jbzoo/simpletypes)](https://github.com/JBZoo/SimpleTypes/issues) [![Total Downloads](https://poser.pugx.org/jbzoo/simpletypes/downloads)](https://packagist.org/packages/jbzoo/simpletypes/stats) [![GitHub License](https://img.shields.io/github/license/jbzoo/simpletypes)](https://github.com/JBZoo/SimpleTypes/blob/master/LICENSE) diff --git a/demo.php b/demo.php index d0dea36..12685ff 100644 --- a/demo.php +++ b/demo.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + require_once __DIR__ . '/vendor/autoload.php'; use JBZoo\SimpleTypes\Config\Config; diff --git a/src/Config/Area.php b/src/Config/Area.php index c9212ba..540efeb 100644 --- a/src/Config/Area.php +++ b/src/Config/Area.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Config; /** diff --git a/src/Config/Config.php b/src/Config/Config.php index 8024701..a45aa7f 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Config; use JBZoo\SimpleTypes\Formatter; diff --git a/src/Config/Degree.php b/src/Config/Degree.php index 9892ea3..0274bf7 100644 --- a/src/Config/Degree.php +++ b/src/Config/Degree.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Config; /** diff --git a/src/Config/Info.php b/src/Config/Info.php index 2ea252b..2b9a201 100644 --- a/src/Config/Info.php +++ b/src/Config/Info.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Config; use JBZoo\SimpleTypes\Formatter; @@ -81,8 +83,7 @@ public function getRules(): array 'bit' => [ 'symbol' => 'Bit', - 'rate' => static function (int $value, string $ruleTo) { - + 'rate' => static function (float $value, string $ruleTo) { if ($ruleTo === 'bit') { return $value * 8; } diff --git a/src/Config/Length.php b/src/Config/Length.php index 77a5d42..52d197d 100644 --- a/src/Config/Length.php +++ b/src/Config/Length.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Config; /** diff --git a/src/Config/Money.php b/src/Config/Money.php index 0deacbe..5d21602 100644 --- a/src/Config/Money.php +++ b/src/Config/Money.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Config; use JBZoo\SimpleTypes\Formatter; diff --git a/src/Config/Temp.php b/src/Config/Temp.php index 3ae5ecf..8c6cacf 100644 --- a/src/Config/Temp.php +++ b/src/Config/Temp.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Config; /** diff --git a/src/Config/Time.php b/src/Config/Time.php index 9a9defd..0413eca 100644 --- a/src/Config/Time.php +++ b/src/Config/Time.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Config; /** diff --git a/src/Config/Volume.php b/src/Config/Volume.php index 8a415b1..a842cca 100644 --- a/src/Config/Volume.php +++ b/src/Config/Volume.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Config; /** diff --git a/src/Config/Weight.php b/src/Config/Weight.php index 3a2b3a8..cc0e3c7 100644 --- a/src/Config/Weight.php +++ b/src/Config/Weight.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Config; /** diff --git a/src/Exception.php b/src/Exception.php index b51e25f..4cca70c 100644 --- a/src/Exception.php +++ b/src/Exception.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes; /** diff --git a/src/Formatter.php b/src/Formatter.php index dd1783f..355f825 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes; /** @@ -253,9 +255,9 @@ protected function format(float $value, string $rule): array $isPositive = ($value >= 0); $valueStr = number_format( abs($roundedValue), - $format['num_decimals'], - $format['decimal_sep'], - $format['thousands_sep'] + (int)($format['num_decimals'] ?? 0), + (string)($format['decimal_sep'] ?? '.'), + (string)($format['thousands_sep'] ?? '') ); $template = $isPositive ? $format['format_positive'] : $format['format_negative']; diff --git a/src/Parser.php b/src/Parser.php index b37682b..89c538a 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes; /** diff --git a/src/Type/AbstractType.php b/src/Type/AbstractType.php index 1d3a973..984ac35 100644 --- a/src/Type/AbstractType.php +++ b/src/Type/AbstractType.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Type; use JBZoo\SimpleTypes\Config\Config; diff --git a/src/Type/Area.php b/src/Type/Area.php index 696d592..c7a5ad2 100644 --- a/src/Type/Area.php +++ b/src/Type/Area.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Type; /** diff --git a/src/Type/Degree.php b/src/Type/Degree.php index e263bd0..d5dbba4 100644 --- a/src/Type/Degree.php +++ b/src/Type/Degree.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Type; /** diff --git a/src/Type/Info.php b/src/Type/Info.php index e145426..c13e300 100644 --- a/src/Type/Info.php +++ b/src/Type/Info.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Type; /** diff --git a/src/Type/Length.php b/src/Type/Length.php index 9600bb1..79f8bc7 100644 --- a/src/Type/Length.php +++ b/src/Type/Length.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Type; /** diff --git a/src/Type/Money.php b/src/Type/Money.php index a37fd65..f149608 100644 --- a/src/Type/Money.php +++ b/src/Type/Money.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Type; /** diff --git a/src/Type/Temp.php b/src/Type/Temp.php index 2f61ec2..78d5f57 100644 --- a/src/Type/Temp.php +++ b/src/Type/Temp.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Type; /** diff --git a/src/Type/Time.php b/src/Type/Time.php index 7c9547a..789c690 100644 --- a/src/Type/Time.php +++ b/src/Type/Time.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Type; /** diff --git a/src/Type/Volume.php b/src/Type/Volume.php index f083202..8a6a159 100644 --- a/src/Type/Volume.php +++ b/src/Type/Volume.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Type; /** diff --git a/src/Type/Weight.php b/src/Type/Weight.php index d5d634d..ba2ab14 100644 --- a/src/Type/Weight.php +++ b/src/Type/Weight.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\SimpleTypes\Type; /** diff --git a/tests/CalcTest.php b/tests/CalcTest.php index 5fec256..c4bae70 100644 --- a/tests/CalcTest.php +++ b/tests/CalcTest.php @@ -13,11 +13,13 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; +use JBZoo\SimpleTypes\Config\Money as ConfigMoney; use JBZoo\SimpleTypes\Type\Money; use JBZoo\SimpleTypes\Type\Weight; -use JBZoo\SimpleTypes\Config\Money as ConfigMoney; /** * Class calcTest @@ -29,52 +31,52 @@ public function testAdd() { $val = val(); - batchEqualDumps(array( - array('0 eur', $val->dump(false)), - array('1 eur', $val->add('1')->dump(false)), - array('0 eur', $val->add('-1')->dump(false)), - array('10 eur', $val->add('10')->dump(false)), - array('15 eur', $val->add('10 usd')->dump(false)), - array('16 eur', $val->add(1)->dump(false)), - array('15 eur', $val->add(-1)->dump(false)), - array('15.56 eur', $val->add(0.56)->dump(false)), - array('14.99 eur', $val->add(-0.57)->dump(false)), - )); + batchEqualDumps([ + ['0 eur', $val->dump(false)], + ['1 eur', $val->add('1')->dump(false)], + ['0 eur', $val->add('-1')->dump(false)], + ['10 eur', $val->add('10')->dump(false)], + ['15 eur', $val->add('10 usd')->dump(false)], + ['16 eur', $val->add(1)->dump(false)], + ['15 eur', $val->add(-1)->dump(false)], + ['15.56 eur', $val->add(0.56)->dump(false)], + ['14.99 eur', $val->add(-0.57)->dump(false)], + ]); } public function testSubtract() { $val = val(); - batchEqualDumps(array( - array('0 eur', $val->dump(false)), - array('-1 eur', $val->subtract('1')->dump(false)), - array('0 eur', $val->subtract('-1')->dump(false)), - array('-10 eur', $val->subtract('10')->dump(false)), - array('-15 eur', $val->subtract('10 usd')->dump(false)), - array('-16 eur', $val->subtract(1)->dump(false)), - array('-15 eur', $val->subtract(-1)->dump(false)), - array('-15.56 eur', $val->subtract(0.56)->dump(false)), - array('-16.13 eur', $val->subtract(0.57)->dump(false)), - )); + batchEqualDumps([ + ['0 eur', $val->dump(false)], + ['-1 eur', $val->subtract('1')->dump(false)], + ['0 eur', $val->subtract('-1')->dump(false)], + ['-10 eur', $val->subtract('10')->dump(false)], + ['-15 eur', $val->subtract('10 usd')->dump(false)], + ['-16 eur', $val->subtract(1)->dump(false)], + ['-15 eur', $val->subtract(-1)->dump(false)], + ['-15.56 eur', $val->subtract(0.56)->dump(false)], + ['-16.13 eur', $val->subtract(0.57)->dump(false)], + ]); } public function testPercentAddAndSubtract() { $val = val(100); - batchEqualDumps(array( - array('100 eur', $val->dump(false)), + batchEqualDumps([ + ['100 eur', $val->dump(false)], // plus - array('110 eur', $val->add('10%')->dump(false)), - array('99 eur', $val->add('-10%')->dump(false)), - array('108.9 eur', $val->add('+10%')->dump(false)), + ['110 eur', $val->add('10%')->dump(false)], + ['99 eur', $val->add('-10%')->dump(false)], + ['108.9 eur', $val->add('+10%')->dump(false)], // minus - array('-980.1 eur', $val->subtract('+1000%')->dump(false)), - array('-2411.046 eur', $val->add('146%')->dump(false)), - )); + ['-980.1 eur', $val->subtract('+1000%')->dump(false)], + ['-2411.046 eur', $val->add('146%')->dump(false)], + ]); } public function testAddAndSubtract() @@ -99,63 +101,63 @@ public function testInvert() { $val = val('1 eur'); - batchEqualDumps(array( - array('-1 eur', $val->invert()->dump(false)), - array('1 eur', $val->invert()->dump(false)), - )); + batchEqualDumps([ + ['-1 eur', $val->invert()->dump(false)], + ['1 eur', $val->invert()->dump(false)], + ]); $val = val(); - batchEqualDumps(array( - array('0 eur', $val->invert()->dump(false)), - array('0 eur', $val->invert()->dump(false)), - )); + batchEqualDumps([ + ['0 eur', $val->invert()->dump(false)], + ['0 eur', $val->invert()->dump(false)], + ]); } public function testPositiveAndNegative() { $val = val('1 eur'); - batchEqualDumps(array( - array('1 eur', $val->positive()->dump(false)), - array('-1 eur', $val->negative()->dump(false)), - array('-1 eur', $val->negative()->dump(false)), - array('1 eur', $val->positive()->dump(false)), - )); + batchEqualDumps([ + ['1 eur', $val->positive()->dump(false)], + ['-1 eur', $val->negative()->dump(false)], + ['-1 eur', $val->negative()->dump(false)], + ['1 eur', $val->positive()->dump(false)], + ]); } public function testMultiply() { $val = val('1 eur'); - batchEqualDumps(array( - array('1 eur', $val->multiply('1')->dump(false)), - array('10 eur', $val->multiply('10')->dump(false)), - array('-10 eur', $val->multiply('-1')->dump(false)), - array('5.6 eur', $val->multiply('-.56')->dump(false)), - )); + batchEqualDumps([ + ['1 eur', $val->multiply(1)->dump(false)], + ['10 eur', $val->multiply(10)->dump(false)], + ['-10 eur', $val->multiply(-1)->dump(false)], + ['5.6 eur', $val->multiply(-.56)->dump(false)], + ]); } public function testDivision() { $val = val('360 eur'); - batchEqualDumps(array( - array('3000 eur', $val->division(.12)->dump(false)), - array('100 eur', $val->division(30)->dump(false)), - )); + batchEqualDumps([ + ['3000 eur', $val->division(.12)->dump(false)], + ['100 eur', $val->division(30)->dump(false)], + ]); } public function testPercent() { $discountSave = val('20 eur'); - $itemPrice = val('100 eur'); + $itemPrice = val('100 eur'); - batchEqualDumps(array( - array('20 %', $discountSave->percent($itemPrice)->dump(false)), - array('40 %', val('10 eur')->percent('50 usd')->dump(false)), - array('60 %', val('10 eur')->percent('50 usd', true)->dump(false)), - )); + batchEqualDumps([ + ['20 %', $discountSave->percent($itemPrice)->dump(false)], + ['40 %', val('10 eur')->percent('50 usd')->dump(false)], + ['60 %', val('10 eur')->percent('50 usd', true)->dump(false)], + ]); } public function testFunction() @@ -167,11 +169,11 @@ public function testFunction() $value ->multiply(6.5) ->add('55%') - ->negative('55%'); + ->negative(true); }) ->customFunc(function ($value) { $value - ->add(array(50, 'usd')) + ->add([50, 'usd']) ->convert('byr'); }); @@ -215,7 +217,7 @@ public function testNoValidTypes() { $this->expectException(\JBZoo\SimpleTypes\Exception::class); - $money = new Money('1 usd', new ConfigMoney()); + $money = new Money('1 usd', new ConfigMoney()); $weight = new Weight('1 kg', new ConfigTestWeight()); $money->add($weight); } diff --git a/tests/CompareTest.php b/tests/CompareTest.php index 93c6e8f..5c47ea8 100644 --- a/tests/CompareTest.php +++ b/tests/CompareTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** @@ -23,18 +25,18 @@ class CompareTest extends PHPUnit { public function testSimple() { - isBatch(array( - array(true, val(1)->compare(1, '=')), - array(true, val(1)->compare(1, '==')), - array(true, val(1)->compare(1, '===')), - array(true, val(1)->compare(1, '>=')), - array(true, val(1)->compare(1, '<=')), + isBatch([ + [true, val(1)->compare(1, '=')], + [true, val(1)->compare(1, '==')], + [true, val(1)->compare(1, '===')], + [true, val(1)->compare(1, '>=')], + [true, val(1)->compare(1, '<=')], - array(false, val(1)->compare(1, '<')), - array(false, val(1)->compare(1, '!=')), - array(false, val(1)->compare(1, '!==')), - array(false, val(1)->compare(1, '>')), - )); + [false, val(1)->compare(1, '<')], + [false, val(1)->compare(1, '!=')], + [false, val(1)->compare(1, '!==')], + [false, val(1)->compare(1, '>')], + ]); } public function testComplex() @@ -42,13 +44,13 @@ public function testComplex() $v1 = val(1.5); $v2 = val('5.6'); - isBatch(array( - array(false, $v1->compare($v2, ' =')), - array(true, $v1->compare($v2, '< ')), - array(true, $v1->compare($v2, ' <= ')), - array(false, $v1->compare($v2, ' >= ')), - array(false, $v1->compare($v2, '>')), - )); + isBatch([ + [false, $v1->compare($v2, ' =')], + [true, $v1->compare($v2, '< ')], + [true, $v1->compare($v2, ' <= ')], + [false, $v1->compare($v2, ' >= ')], + [false, $v1->compare($v2, '>')], + ]); } public function testRules() @@ -56,27 +58,27 @@ public function testRules() $usd = val('1 usd'); $eur = val('1 eur'); - isBatch(array( - array(false, $usd->compare($eur, '=')), - array(true, $usd->compare($eur, '!=')), - array(true, $usd->compare($eur, '<')), - array(true, $usd->compare($eur, '<=')), - array(false, $usd->compare($eur, '>')), - array(false, $usd->compare($eur, '>=')), - )); + isBatch([ + [false, $usd->compare($eur, '=')], + [true, $usd->compare($eur, '!=')], + [true, $usd->compare($eur, '<')], + [true, $usd->compare($eur, '<=')], + [false, $usd->compare($eur, '>')], + [false, $usd->compare($eur, '>=')], + ]); // after convert $eur->convert('usd'); $usd->convert('eur'); - isBatch(array( - array(false, $usd->compare($eur, '==')), - array(true, $usd->compare($eur, '!==')), - array(true, $usd->compare($eur, '<')), - array(true, $usd->compare($eur, '<=')), - array(false, $usd->compare($eur, '>')), - array(false, $usd->compare($eur, '>=')), - )); + isBatch([ + [false, $usd->compare($eur, '==')], + [true, $usd->compare($eur, '!==')], + [true, $usd->compare($eur, '<')], + [true, $usd->compare($eur, '<=')], + [false, $usd->compare($eur, '>')], + [false, $usd->compare($eur, '>=')], + ]); } public function testUndefined() diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 3fe09c2..c4b37e4 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; use JBZoo\SimpleTypes\Config\Config; diff --git a/tests/ConverterTest.php b/tests/ConverterTest.php index 3cd992e..c057f2e 100644 --- a/tests/ConverterTest.php +++ b/tests/ConverterTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** @@ -31,7 +33,6 @@ public function testCheckExists() ['1 uah', val('1 uah')->dump(false)], ['1 byr', val('1 byr')->dump(false)], ]); - } public function testSimple() diff --git a/tests/InstancesTest.php b/tests/InstancesTest.php index 4f127a1..680a9a3 100644 --- a/tests/InstancesTest.php +++ b/tests/InstancesTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; use JBZoo\SimpleTypes\Config\Config; diff --git a/tests/MagicTest.php b/tests/MagicTest.php index a300e28..112d6a5 100644 --- a/tests/MagicTest.php +++ b/tests/MagicTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** diff --git a/tests/OutputTest.php b/tests/OutputTest.php index ec60562..b0376bd 100644 --- a/tests/OutputTest.php +++ b/tests/OutputTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 64e774d..8377eb2 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** diff --git a/tests/RoundingTest.php b/tests/RoundingTest.php index 0edbd4e..40544c3 100644 --- a/tests/RoundingTest.php +++ b/tests/RoundingTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; use JBZoo\SimpleTypes\Formatter; diff --git a/tests/RuleTest.php b/tests/RuleTest.php index 60aa9e6..f89acb2 100644 --- a/tests/RuleTest.php +++ b/tests/RuleTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** @@ -117,7 +119,6 @@ public function testIsRule() $val->convert('RUB'); is(false, $val->isRule('USD')); - } public function testGetRules() diff --git a/tests/SimpleTypesCodeStyleTest.php b/tests/SimpleTypesCodeStyleTest.php index 8bb27af..0b7a133 100644 --- a/tests/SimpleTypesCodeStyleTest.php +++ b/tests/SimpleTypesCodeStyleTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; use Symfony\Component\Finder\Finder; diff --git a/tests/SimpleTypesComposerTest.php b/tests/SimpleTypesComposerTest.php index 2de599b..4230629 100644 --- a/tests/SimpleTypesComposerTest.php +++ b/tests/SimpleTypesComposerTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** diff --git a/tests/SimpleTypesCopyrightTest.php b/tests/SimpleTypesCopyrightTest.php index 8cc342d..fbba48d 100644 --- a/tests/SimpleTypesCopyrightTest.php +++ b/tests/SimpleTypesCopyrightTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** @@ -26,4 +28,5 @@ class SimpleTypesCopyrightTest extends AbstractCopyrightTest * @var string */ protected $packageName = 'SimpleTypes'; + protected $isPhpStrictType = true; } diff --git a/tests/SimpleTypesReadmeTest.php b/tests/SimpleTypesReadmeTest.php index df3b3de..48b3369 100644 --- a/tests/SimpleTypesReadmeTest.php +++ b/tests/SimpleTypesReadmeTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** @@ -23,4 +25,10 @@ class SimpleTypesReadmeTest extends AbstractReadmeTest { protected $packageName = 'SimpleTypes'; + + protected function setUp(): void + { + parent::setUp(); + $this->params['strict_types'] = true; + } } diff --git a/tests/autoload.php b/tests/autoload.php index f670ce7..4fc31d5 100644 --- a/tests/autoload.php +++ b/tests/autoload.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + if (!defined('ROOT_PATH')) { // for PHPUnit process isolation define('ROOT_PATH', realpath('.')); } diff --git a/tests/phpunit-functions.php b/tests/phpunit-functions.php index 45b71a7..cdb6e07 100644 --- a/tests/phpunit-functions.php +++ b/tests/phpunit-functions.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; use JBZoo\SimpleTypes\Config\Config; diff --git a/tests/type/AreaTypeTest.php b/tests/type/AreaTypeTest.php index 6e6fc78..c744ac9 100644 --- a/tests/type/AreaTypeTest.php +++ b/tests/type/AreaTypeTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** diff --git a/tests/type/DegreeTypeTest.php b/tests/type/DegreeTypeTest.php index 954d59d..692580c 100644 --- a/tests/type/DegreeTypeTest.php +++ b/tests/type/DegreeTypeTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** diff --git a/tests/type/InfoTypeTest.php b/tests/type/InfoTypeTest.php index 4316630..da49b35 100644 --- a/tests/type/InfoTypeTest.php +++ b/tests/type/InfoTypeTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** diff --git a/tests/type/LengthTypeTest.php b/tests/type/LengthTypeTest.php index f638861..8ea3ba0 100644 --- a/tests/type/LengthTypeTest.php +++ b/tests/type/LengthTypeTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** diff --git a/tests/type/TempTypeTest.php b/tests/type/TempTypeTest.php index 3f0e4f0..f54a622 100644 --- a/tests/type/TempTypeTest.php +++ b/tests/type/TempTypeTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** diff --git a/tests/type/TimeTypeTest.php b/tests/type/TimeTypeTest.php index 24d0577..f102450 100644 --- a/tests/type/TimeTypeTest.php +++ b/tests/type/TimeTypeTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** diff --git a/tests/type/TypeTest.php b/tests/type/TypeTest.php index 85cd31e..47983cb 100644 --- a/tests/type/TypeTest.php +++ b/tests/type/TypeTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; use JBZoo\SimpleTypes\Config\Config; diff --git a/tests/type/VolumeTypeTest.php b/tests/type/VolumeTypeTest.php index ecb265c..b110e32 100644 --- a/tests/type/VolumeTypeTest.php +++ b/tests/type/VolumeTypeTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** diff --git a/tests/type/WeightTypeTest.php b/tests/type/WeightTypeTest.php index ae04dfd..7205e85 100644 --- a/tests/type/WeightTypeTest.php +++ b/tests/type/WeightTypeTest.php @@ -13,6 +13,8 @@ * @link https://github.com/JBZoo/SimpleTypes */ +declare(strict_types=1); + namespace JBZoo\PHPUnit; /** From 327f0ca59d1c398ae57a319e0c2ec4c6482f5dbb Mon Sep 17 00:00:00 2001 From: Denis Smetannikov Date: Wed, 21 Apr 2021 21:22:53 +0300 Subject: [PATCH 2/4] PHP 8 in Travis-CI (experimental) --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index f5db28b..8c2e0ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,14 @@ php: - 7.2 - 7.3 - 7.4 + - 8.0 + - nightly + +jobs: + fast_finish: true + allow_failures: + - php: 8.0 + - php: nightly env: matrix: From df53fc76166f95705197d9c2d6c47523b7c131bd Mon Sep 17 00:00:00 2001 From: Denis Smetannikov Date: Wed, 21 Apr 2021 21:23:20 +0300 Subject: [PATCH 3/4] update deps --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 89c467f..b8dc6e7 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,8 @@ }, "require-dev" : { - "jbzoo/toolbox-dev" : "^2.6.2", - "jbzoo/utils" : "^4.2.3" + "jbzoo/toolbox-dev" : "^2.10.0", + "jbzoo/utils" : "^4.3.0" }, "autoload" : { From 2f2f7acb41e22fd880e919ee7064fd0833b1749c Mon Sep 17 00:00:00 2001 From: Denis Smetannikov Date: Wed, 21 Apr 2021 21:47:07 +0300 Subject: [PATCH 4/4] Fixes --- tests/autoload.php | 2 +- tests/phpunit-functions.php | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/autoload.php b/tests/autoload.php index 4fc31d5..73df355 100644 --- a/tests/autoload.php +++ b/tests/autoload.php @@ -16,7 +16,7 @@ declare(strict_types=1); if (!defined('ROOT_PATH')) { // for PHPUnit process isolation - define('ROOT_PATH', realpath('.')); + define('ROOT_PATH', dirname(__DIR__)); } // main autoload diff --git a/tests/phpunit-functions.php b/tests/phpunit-functions.php index cdb6e07..96ffed2 100644 --- a/tests/phpunit-functions.php +++ b/tests/phpunit-functions.php @@ -22,7 +22,7 @@ use JBZoo\SimpleTypes\Type\Money; /** - * @param null $arg + * @param mixed $arg * @return Money */ function val($arg = null): Money @@ -35,10 +35,8 @@ function val($arg = null): Money /** * @param array $testList */ -function batchEqualDumps($testList) +function batchEqualDumps(array $testList) { - $testList = (array)$testList; - foreach ($testList as $test) { $result = $test[0] ?? null; $arg = $test[1] ?? null;