From c11c023796f010a3853db347da8751ae6b50702a Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Thu, 9 Jan 2020 17:57:07 -0600 Subject: [PATCH] Address static analysis issues and add additional tests --- .travis.yml | 8 +- composer.json | 2 +- phpstan-tests.neon | 2 + phpstan.neon | 11 +- psalm-baseline.xml | 96 +++--------- src/Generator/DefaultTimeGenerator.php | 2 +- src/Generator/RandomBytesGenerator.php | 2 +- src/Math/BrickMathCalculator.php | 2 +- src/Math/RoundingMode.php | 102 ++++++++----- src/Provider/Node/RandomNodeProvider.php | 2 +- src/Provider/Node/SystemNodeProvider.php | 5 +- src/Uuid.php | 11 +- .../Time/GenericTimeConverterTest.php | 26 +++- tests/Converter/Time/PhpTimeConverterTest.php | 143 +++++++++++++++++- tests/Math/BrickMathCalculatorTest.php | 14 +- tests/Type/HexadecimalTest.php | 8 +- tests/UuidTest.php | 4 +- 17 files changed, 278 insertions(+), 162 deletions(-) diff --git a/.travis.yml b/.travis.yml index ff7410c..08c0315 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,10 +51,10 @@ before_script: - mkdir -p build/logs script: - - ./resources/scripts/cmd-proxy.sh composer run lint - - ./resources/scripts/cmd-proxy.sh composer run phpcs - - ./resources/scripts/cmd-proxy.sh composer run phpstan - - ./resources/scripts/cmd-proxy.sh ./vendor/bin/psalm --show-info=false + - ./resources/scripts/cmd-proxy.sh composer lint + - ./resources/scripts/cmd-proxy.sh composer phpcs + - ./resources/scripts/cmd-proxy.sh composer phpstan + - ./resources/scripts/cmd-proxy.sh composer psalm - travis_wait ./resources/scripts/cmd-proxy.sh ./vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml after_success: diff --git a/composer.json b/composer.json index 75f4dbe..d8ab5a7 100644 --- a/composer.json +++ b/composer.json @@ -79,7 +79,7 @@ "phpstan analyse -c phpstan.neon src --level max --no-progress", "phpstan analyse -c phpstan-tests.neon tests --level max --no-progress" ], - "psalm": "psalm", + "psalm": "psalm --show-info=false", "phpunit": "phpunit --verbose --colors=always", "phpunit-coverage": "phpunit --verbose --colors=always --coverage-html build/coverage", "test": [ diff --git a/phpstan-tests.neon b/phpstan-tests.neon index 5d582f1..34f6318 100644 --- a/phpstan-tests.neon +++ b/phpstan-tests.neon @@ -3,6 +3,8 @@ parameters: - tests/phpstan-bootstrap.php checkMissingIterableValueType: false reportUnmatchedIgnoredErrors: false + excludes_analyse: + - tests/ExpectedBehaviorTest.php ignoreErrors: - message: "#^Function uuid_create\\(\\) has no return typehint specified\\.$#" diff --git a/phpstan.neon b/phpstan.neon index 24bd048..b288b7b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,12 +1,17 @@ parameters: checkMissingIterableValueType: false + reportUnmatchedIgnoredErrors: false autoload_files: - tests/phpstan-bootstrap.php ignoreErrors: - - message: "#^Negated boolean expression is always false\\.$#" - count: 1 - path: src/Uuid.php + message: '#^Call to function is_int\(\) with float will always evaluate to false\.$#' + count: 2 + path: src/Converter/Time/PhpTimeConverter.php + - + message: '#^Unreachable statement - code above always terminates\.$#' + count: 2 + path: src/Converter/Time/PhpTimeConverter.php - message: '#^Comparison operation "<" between int<6, max> and 0 is always false\.$#' count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index fcfa11b..ffcd94b 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,26 +1,26 @@ - - - - $hexUuid[1] - + + + + new DegradedTimeConverter() + DegradedUuid + - - - fromHex - convertTime - - - $exception->getCode() - + + + BigNumberConverter + - - - $exception->getCode() - - - $node - + + + BigNumberTimeConverter + + + + + $uuidTime + $uuidTime + @@ -32,10 +32,6 @@ uuid_parse($uuid) - - uuid_create(UUID_TYPE_RANDOM) - uuid_parse($uuid) - @@ -47,32 +43,12 @@ uuid_parse($uuid) - - uuid_create(UUID_TYPE_TIME) - uuid_parse($uuid) - - - - - $exception->getCode() - - - - - $exception->getCode() - hexdec(bin2hex($nodeMsb)) | 0x010000 - - - $addressPath - - + $node constant('PHP_OS') constant('PHP_OS') - $addressPath - $addressPath $macs @@ -87,39 +63,11 @@ - - self::$factory - - - encodeBinary - convertTime - fromHex - fromHex - fromHex - encode + getFactory - fromBytes getFactory - fromString getFactory - fromInteger getFactory - getValidator - validate - - $exception->getCode() - - - null - - - - - $hash - - - $hash - diff --git a/src/Generator/DefaultTimeGenerator.php b/src/Generator/DefaultTimeGenerator.php index 0e16583..74251bc 100644 --- a/src/Generator/DefaultTimeGenerator.php +++ b/src/Generator/DefaultTimeGenerator.php @@ -69,7 +69,7 @@ class DefaultTimeGenerator implements TimeGeneratorInterface } catch (\Throwable $exception) { throw new RandomSourceException( $exception->getMessage(), - $exception->getCode(), + (int) $exception->getCode(), $exception ); } diff --git a/src/Generator/RandomBytesGenerator.php b/src/Generator/RandomBytesGenerator.php index 888199a..e6e9a19 100644 --- a/src/Generator/RandomBytesGenerator.php +++ b/src/Generator/RandomBytesGenerator.php @@ -36,7 +36,7 @@ class RandomBytesGenerator implements RandomGeneratorInterface } catch (\Throwable $exception) { throw new RandomSourceException( $exception->getMessage(), - $exception->getCode(), + (int) $exception->getCode(), $exception ); } diff --git a/src/Math/BrickMathCalculator.php b/src/Math/BrickMathCalculator.php index 043e442..3ffd07a 100644 --- a/src/Math/BrickMathCalculator.php +++ b/src/Math/BrickMathCalculator.php @@ -133,6 +133,6 @@ final class BrickMathCalculator implements CalculatorInterface */ private function getBrickRoundingMode(int $roundingMode): int { - return (int) self::ROUNDING_MODE_MAP[$roundingMode] ?? 0; + return self::ROUNDING_MODE_MAP[$roundingMode] ?? 0; } } diff --git a/src/Math/RoundingMode.php b/src/Math/RoundingMode.php index c16e75b..82f1cb7 100644 --- a/src/Math/RoundingMode.php +++ b/src/Math/RoundingMode.php @@ -5,22 +5,23 @@ * * Copyright (c) 2013-present Benjamin Morel * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. * * @link https://github.com/brick/math brick/math at GitHub */ @@ -30,13 +31,16 @@ declare(strict_types=1); namespace Ramsey\Uuid\Math; /** - * Specifies a rounding behavior for numerical operations capable of discarding precision. + * Specifies a rounding behavior for numerical operations capable of discarding + * precision. * - * Each rounding mode indicates how the least significant returned digit of a rounded result - * is to be calculated. If fewer digits are returned than the digits needed to represent the - * exact numerical result, the discarded digits will be referred to as the discarded fraction - * regardless the digits' contribution to the value of the number. In other words, considered - * as a numerical value, the discarded fraction could have an absolute value greater than one. + * Each rounding mode indicates how the least significant returned digit of a + * rounded result is to be calculated. If fewer digits are returned than the + * digits needed to represent the exact numerical result, the discarded digits + * will be referred to as the discarded fraction regardless the digits' + * contribution to the value of the number. In other words, considered as a + * numerical value, the discarded fraction could have an absolute value greater + * than one. */ final class RoundingMode { @@ -50,10 +54,12 @@ final class RoundingMode } /** - * Asserts that the requested operation has an exact result, hence no rounding is necessary. + * Asserts that the requested operation has an exact result, hence no + * rounding is necessary. * - * If this rounding mode is specified on an operation that yields a result that - * cannot be represented at the requested scale, a RoundingNecessaryException is thrown. + * If this rounding mode is specified on an operation that yields a result + * that cannot be represented at the requested scale, a + * RoundingNecessaryException is thrown. */ public const UNNECESSARY = 0; @@ -61,72 +67,84 @@ final class RoundingMode * Rounds away from zero. * * Always increments the digit prior to a nonzero discarded fraction. - * Note that this rounding mode never decreases the magnitude of the calculated value. + * Note that this rounding mode never decreases the magnitude of the + * calculated value. */ public const UP = 1; /** * Rounds towards zero. * - * Never increments the digit prior to a discarded fraction (i.e., truncates). - * Note that this rounding mode never increases the magnitude of the calculated value. + * Never increments the digit prior to a discarded fraction (i.e., + * truncates). Note that this rounding mode never increases the magnitude of + * the calculated value. */ public const DOWN = 2; /** * Rounds towards positive infinity. * - * If the result is positive, behaves as for UP; if negative, behaves as for DOWN. - * Note that this rounding mode never decreases the calculated value. + * If the result is positive, behaves as for UP; if negative, behaves as for + * DOWN. Note that this rounding mode never decreases the calculated value. */ public const CEILING = 3; /** * Rounds towards negative infinity. * - * If the result is positive, behave as for DOWN; if negative, behave as for UP. - * Note that this rounding mode never increases the calculated value. + * If the result is positive, behave as for DOWN; if negative, behave as for + * UP. Note that this rounding mode never increases the calculated value. */ public const FLOOR = 4; /** - * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round up. + * Rounds towards "nearest neighbor" unless both neighbors are equidistant, + * in which case round up. * - * Behaves as for UP if the discarded fraction is >= 0.5; otherwise, behaves as for DOWN. - * Note that this is the rounding mode commonly taught at school. + * Behaves as for UP if the discarded fraction is >= 0.5; otherwise, behaves + * as for DOWN. Note that this is the rounding mode commonly taught at + * school. */ public const HALF_UP = 5; /** - * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round down. + * Rounds towards "nearest neighbor" unless both neighbors are equidistant, + * in which case round down. * - * Behaves as for UP if the discarded fraction is > 0.5; otherwise, behaves as for DOWN. + * Behaves as for UP if the discarded fraction is > 0.5; otherwise, behaves + * as for DOWN. */ public const HALF_DOWN = 6; /** - * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round towards positive infinity. + * Rounds towards "nearest neighbor" unless both neighbors are equidistant, + * in which case round towards positive infinity. * - * If the result is positive, behaves as for HALF_UP; if negative, behaves as for HALF_DOWN. + * If the result is positive, behaves as for HALF_UP; if negative, behaves + * as for HALF_DOWN. */ public const HALF_CEILING = 7; /** - * Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round towards negative infinity. + * Rounds towards "nearest neighbor" unless both neighbors are equidistant, + * in which case round towards negative infinity. * - * If the result is positive, behaves as for HALF_DOWN; if negative, behaves as for HALF_UP. + * If the result is positive, behaves as for HALF_DOWN; if negative, behaves + * as for HALF_UP. */ public const HALF_FLOOR = 8; /** - * Rounds towards the "nearest neighbor" unless both neighbors are equidistant, in which case rounds towards the even neighbor. + * Rounds towards the "nearest neighbor" unless both neighbors are + * equidistant, in which case rounds towards the even neighbor. * - * Behaves as for HALF_UP if the digit to the left of the discarded fraction is odd; - * behaves as for HALF_DOWN if it's even. + * Behaves as for HALF_UP if the digit to the left of the discarded fraction + * is odd; behaves as for HALF_DOWN if it's even. * * Note that this is the rounding mode that statistically minimizes * cumulative error when applied repeatedly over a sequence of calculations. - * It is sometimes known as "Banker's rounding", and is chiefly used in the USA. + * It is sometimes known as "Banker's rounding", and is chiefly used in the + * USA. */ public const HALF_EVEN = 9; } diff --git a/src/Provider/Node/RandomNodeProvider.php b/src/Provider/Node/RandomNodeProvider.php index dfa5244..26c3768 100644 --- a/src/Provider/Node/RandomNodeProvider.php +++ b/src/Provider/Node/RandomNodeProvider.php @@ -31,7 +31,7 @@ class RandomNodeProvider implements NodeProviderInterface } catch (\Throwable $exception) { throw new RandomSourceException( $exception->getMessage(), - $exception->getCode(), + (int) $exception->getCode(), $exception ); } diff --git a/src/Provider/Node/SystemNodeProvider.php b/src/Provider/Node/SystemNodeProvider.php index 25f28e3..dba0ad1 100644 --- a/src/Provider/Node/SystemNodeProvider.php +++ b/src/Provider/Node/SystemNodeProvider.php @@ -114,7 +114,8 @@ class SystemNodeProvider implements NodeProviderInterface } $macs = []; - array_walk($addressPaths, function ($addressPath) use (&$macs): void { + + array_walk($addressPaths, function (string $addressPath) use (&$macs): void { if (is_readable($addressPath)) { $macs[] = file_get_contents($addressPath); } @@ -123,7 +124,7 @@ class SystemNodeProvider implements NodeProviderInterface $macs = array_map('trim', $macs); // Remove invalid entries. - $macs = array_filter($macs, function ($address) { + $macs = array_filter($macs, function (string $address) { return $address !== '00:00:00:00:00:00' && preg_match('/^([0-9a-f]{2}:){5}[0-9a-f]{2}$/i', $address); }); diff --git a/src/Uuid.php b/src/Uuid.php index 981759e..66c0964 100644 --- a/src/Uuid.php +++ b/src/Uuid.php @@ -144,7 +144,7 @@ class Uuid implements UuidInterface public const UUID_TYPE_HASH_SHA1 = 5; /** - * @var UuidFactoryInterface + * @var UuidFactoryInterface|null */ private static $factory = null; @@ -355,7 +355,7 @@ class Uuid implements UuidInterface } catch (\Throwable $exception) { throw new DateTimeException( $exception->getMessage(), - $exception->getCode(), + (int) $exception->getCode(), $exception ); } @@ -412,11 +412,6 @@ class Uuid implements UuidInterface return str_replace('-', '', $this->toString()); } - /** - * @throws UnsatisfiedDependencyException if large integer support is not available - * - * @inheritDoc - */ public function getInteger(): string { return $this->numberConverter->fromHex($this->getHex()); @@ -593,7 +588,7 @@ class Uuid implements UuidInterface */ public static function getFactory(): UuidFactoryInterface { - if (!self::$factory) { + if (self::$factory === null) { self::$factory = new UuidFactory(); } diff --git a/tests/Converter/Time/GenericTimeConverterTest.php b/tests/Converter/Time/GenericTimeConverterTest.php index 6f7080f..ceebed1 100644 --- a/tests/Converter/Time/GenericTimeConverterTest.php +++ b/tests/Converter/Time/GenericTimeConverterTest.php @@ -11,6 +11,8 @@ use Ramsey\Uuid\Test\TestCase; class GenericTimeConverterTest extends TestCase { /** + * @param string[] $expected + * * @dataProvider provideCalculateTime */ public function testCalculateTime(string $seconds, string $microSeconds, array $expected): void @@ -47,6 +49,15 @@ class GenericTimeConverterTest extends TestCase 'hi' => '0fff', ], ], + [ + 'seconds' => '1578612359', + 'microseconds' => '521023', + 'expected' => [ + 'low' => '64c71df6', + 'mid' => '3337', + 'hi' => '01ea', + ], + ], // This is the earliest possible date supported by v1 UUIDs: // 1582-10-15 00:00:00.000000 @@ -70,7 +81,7 @@ class GenericTimeConverterTest extends TestCase 'mid' => 'ffff', 'hi' => 'ffff', ], - ] + ], ]; } @@ -93,6 +104,19 @@ class GenericTimeConverterTest extends TestCase public function provideConvertTime(): array { return [ + [ + 'uuidTimestamp' => '135606608744910000', + 'unixTimestamp' => '1341368074', + ], + [ + 'uuidTimestamp' => '137979051595210230', + 'unixTimestamp' => '1578612359', + ], + [ + 'uuidTimestamp' => '1152921504599999990', + 'unixTimestamp' => '103072857659', + ], + // This is the last possible time supported by v1 UUIDs. When // converted to a Unix timestamp, the microseconds are lost. // 60038-03-11 05:36:10.955161 diff --git a/tests/Converter/Time/PhpTimeConverterTest.php b/tests/Converter/Time/PhpTimeConverterTest.php index 668de5f..d36a6e3 100644 --- a/tests/Converter/Time/PhpTimeConverterTest.php +++ b/tests/Converter/Time/PhpTimeConverterTest.php @@ -6,8 +6,10 @@ namespace Ramsey\Uuid\Test\Converter\Time; use Brick\Math\BigInteger; use Mockery; +use Ramsey\Uuid\Converter\Time\GenericTimeConverter; use Ramsey\Uuid\Converter\Time\PhpTimeConverter; use Ramsey\Uuid\Exception\InvalidArgumentException; +use Ramsey\Uuid\Math\BrickMathCalculator; use Ramsey\Uuid\Test\TestCase; class PhpTimeConverterTest extends TestCase @@ -38,14 +40,6 @@ class PhpTimeConverterTest extends TestCase $this->assertSame($expectedArray, $returned); } - public function testConvertTime(): void - { - $converter = new PhpTimeConverter(); - $returned = $converter->convertTime('135606608744910000'); - - $this->assertSame('1341368074', $returned); - } - public function testCalculateTimeThrowsExceptionWhenSecondsIsNotOnlyDigits(): void { /** @var Mockery\MockInterface & PhpTimeConverter $converter */ @@ -87,4 +81,137 @@ class PhpTimeConverterTest extends TestCase $converter->convertTime('1234.56'); } + + /** + * @dataProvider provideConvertTime + */ + public function testConvertTime(string $uuidTimestamp, string $unixTimestamp): void + { + $calculator = new BrickMathCalculator(); + $fallbackConverter = new GenericTimeConverter($calculator); + $converter = new PhpTimeConverter($fallbackConverter); + + $result = $converter->convertTime($uuidTimestamp); + + $this->assertSame($unixTimestamp, $result); + } + + /** + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification + */ + public function provideConvertTime(): array + { + return [ + [ + 'uuidTimestamp' => '135606608744910000', + 'unixTimestamp' => '1341368074', + ], + [ + 'uuidTimestamp' => '137979051595210230', + 'unixTimestamp' => '1578612359', + ], + [ + 'uuidTimestamp' => '1152921504599999990', + 'unixTimestamp' => '103072857659', + ], + + // This is the last possible time supported by v1 UUIDs. When + // converted to a Unix timestamp, the microseconds are lost. + // 60038-03-11 05:36:10.955161 + [ + 'uuidTimestamp' => '18446744073709551610', + 'unixTimestamp' => '1832455114570', + ], + + // This is the earliest possible date supported by v1 UUIDs: + // 1582-10-15 00:00:00.000000 + [ + 'uuidTimestamp' => '0', + 'unixTimestamp' => '-12219292800', + ], + + // This is the Unix epoch: + // 1970-01-01 00:00:00.000000 + [ + 'uuidTimestamp' => '122192928000000000', + 'unixTimestamp' => '0', + ], + ]; + } + + /** + * @param string[] $expected + * + * @dataProvider provideCalculateTime + */ + public function testCalculateTime(string $seconds, string $microSeconds, array $expected): void + { + $calculator = new BrickMathCalculator(); + $fallbackConverter = new GenericTimeConverter($calculator); + $converter = new PhpTimeConverter($fallbackConverter); + + $result = $converter->calculateTime($seconds, $microSeconds); + + $this->assertSame($expected, $result); + } + + /** + * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification + */ + public function provideCalculateTime(): array + { + return [ + [ + 'seconds' => '-12219146756', + 'microSeconds' => '0', + 'expected' => [ + 'low' => '0901e600', + 'mid' => '0154', + 'hi' => '0000', + ], + ], + [ + 'seconds' => '103072857659', + 'microseconds' => '999999', + 'expected' => [ + 'low' => 'ff9785f6', + 'mid' => 'ffff', + 'hi' => '0fff', + ], + ], + [ + 'seconds' => '1578612359', + 'microseconds' => '521023', + 'expected' => [ + 'low' => '64c71df6', + 'mid' => '3337', + 'hi' => '01ea', + ], + ], + + // This is the earliest possible date supported by v1 UUIDs: + // 1582-10-15 00:00:00.000000 + [ + 'seconds' => '-12219292800', + 'microSeconds' => '0', + 'expected' => [ + 'low' => '00000000', + 'mid' => '0000', + 'hi' => '0000', + ], + ], + + // This is the last possible time supported by v1 UUIDs: + // 60038-03-11 05:36:10.955161 + [ + 'seconds' => '1832455114570', + 'microseconds' => '955161', + 'expected' => [ + 'low' => 'fffffffa', + 'mid' => 'ffff', + 'hi' => 'ffff', + ], + ], + ]; + } } diff --git a/tests/Math/BrickMathCalculatorTest.php b/tests/Math/BrickMathCalculatorTest.php index e40f00a..77ae7de 100644 --- a/tests/Math/BrickMathCalculatorTest.php +++ b/tests/Math/BrickMathCalculatorTest.php @@ -12,7 +12,7 @@ use Ramsey\Uuid\Type\IntegerValue; class BrickMathCalculatorTest extends TestCase { - public function testAdd() + public function testAdd(): void { $int1 = new IntegerValue(5); $int2 = new IntegerValue(6); @@ -25,7 +25,7 @@ class BrickMathCalculatorTest extends TestCase $this->assertSame('18', $result->toString()); } - public function testSubtract() + public function testSubtract(): void { $int1 = new IntegerValue(5); $int2 = new IntegerValue(6); @@ -38,7 +38,7 @@ class BrickMathCalculatorTest extends TestCase $this->assertSame('-8', $result->toString()); } - public function testMultiply() + public function testMultiply(): void { $int1 = new IntegerValue(5); $int2 = new IntegerValue(6); @@ -51,7 +51,7 @@ class BrickMathCalculatorTest extends TestCase $this->assertSame('210', $result->toString()); } - public function testDivide() + public function testDivide(): void { $int1 = new IntegerValue(1023); $int2 = new IntegerValue(6); @@ -64,7 +64,7 @@ class BrickMathCalculatorTest extends TestCase $this->assertSame('24', $result->toString()); } - public function testFromBase() + public function testFromBase(): void { $calculator = new BrickMathCalculator(); @@ -74,7 +74,7 @@ class BrickMathCalculatorTest extends TestCase $this->assertSame('1208925819614629174706175', $result->toString()); } - public function testToBase() + public function testToBase(): void { $intValue = new IntegerValue('1208925819614629174706175'); $calculator = new BrickMathCalculator(); @@ -82,7 +82,7 @@ class BrickMathCalculatorTest extends TestCase $this->assertSame('ffffffffffffffffffff', $calculator->toBase($intValue, 16)); } - public function testToHexadecimal() + public function testToHexadecimal(): void { $intValue = new IntegerValue('1208925819614629174706175'); $calculator = new BrickMathCalculator(); diff --git a/tests/Type/HexadecimalTest.php b/tests/Type/HexadecimalTest.php index 9281361..01b8033 100644 --- a/tests/Type/HexadecimalTest.php +++ b/tests/Type/HexadecimalTest.php @@ -11,11 +11,9 @@ use Ramsey\Uuid\Type\Hexadecimal; class HexadecimalTest extends TestCase { /** - * @param int|float|string $value - * * @dataProvider provideHex */ - public function testHexadecimalType($value, string $expected): void + public function testHexadecimalType(string $value, string $expected): void { $hexadecimal = new Hexadecimal($value); @@ -45,11 +43,9 @@ class HexadecimalTest extends TestCase } /** - * @param int|float|string $value - * * @dataProvider provideHexBadValues */ - public function testHexadecimalTypeThrowsExceptionForBadValues($value): void + public function testHexadecimalTypeThrowsExceptionForBadValues(string $value): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( diff --git a/tests/UuidTest.php b/tests/UuidTest.php index ec47ff8..2fa6936 100644 --- a/tests/UuidTest.php +++ b/tests/UuidTest.php @@ -164,7 +164,7 @@ class UuidTest extends TestCase // Check a future date $uuid = Uuid::fromString('ff9785f6-ffff-1fff-9669-00007ffffffe'); $this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime()); - $this->assertEquals('5236-03-31T21:21:00+00:00', $uuid->getDateTime()->format('c')); + $this->assertEquals('5236-03-31T21:20:59+00:00', $uuid->getDateTime()->format('c')); // Check the oldest date $uuid = Uuid::fromString('00000000-0000-1000-9669-00007ffffffe'); @@ -855,7 +855,7 @@ class UuidTest extends TestCase // Assert that the time matches $usecAdd = BigDecimal::of($usec)->dividedBy('1000000', 14, RoundingMode::HALF_UP); - $testTime = BigDecimal::of($currentTime)->plus($usecAdd)->toScale(0, RoundingMode::HALF_UP); + $testTime = BigDecimal::of($currentTime)->plus($usecAdd)->toScale(0, RoundingMode::DOWN); $this->assertEquals((string) $testTime, $uuid64->getDateTime()->getTimestamp()); $this->assertEquals((string) $testTime, $uuid32->getDateTime()->getTimestamp()); }