From 81f0f9a9b43f3f27ebdcef86b09119fcd54526c4 Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Sun, 15 Dec 2019 00:44:18 -0600 Subject: [PATCH] Clean-up tests and use PHPStan max level for tests --- composer.json | 2 +- phpstan-tests.neon | 18 + tests/Builder/DefaultUuidBuilderTest.php | 15 +- tests/Builder/DegradedUuidBuilderTest.php | 15 +- tests/Codec/GuidStringCodecTest.php | 35 +- tests/Codec/OrderedTimeCodecTest.php | 40 +- tests/Codec/StringCodecTest.php | 40 +- .../Number/DegradedNumberConverterTest.php | 9 +- .../Time/DegradedTimeConverterTest.php | 8 +- tests/Converter/Time/PhpTimeConverterTest.php | 8 +- tests/Encoder/TimestampFirstCombCodecTest.php | 15 +- tests/Encoder/TimestampLastCombCodecTest.php | 14 +- tests/FunctionsTest.php | 20 +- tests/Generator/CombGeneratorTest.php | 51 ++- tests/Generator/DefaultTimeGeneratorTest.php | 81 ++-- .../Generator/PeclUuidRandomGeneratorTest.php | 15 +- tests/Generator/PeclUuidTestCase.php | 7 + tests/Generator/PeclUuidTimeGeneratorTest.php | 12 +- tests/Generator/RandomBytesGeneratorTest.php | 21 +- .../Generator/RandomGeneratorFactoryTest.php | 4 +- tests/Generator/RandomLibAdapterTest.php | 22 +- tests/Generator/TimeGeneratorFactoryTest.php | 14 +- .../Node/FallbackNodeProviderTest.php | 10 +- .../Provider/Node/RandomNodeProviderTest.php | 14 +- .../Provider/Node/SystemNodeProviderTest.php | 63 +-- tests/Provider/Time/FixedTimeProviderTest.php | 7 +- .../Provider/Time/SystemTimeProviderTest.php | 7 +- tests/TestCase.php | 16 +- tests/UuidFactoryTest.php | 29 +- tests/UuidTest.php | 368 ++++++------------ tests/Validator/ValidatorTest.php | 67 +--- tests/bootstrap.php | 31 +- 32 files changed, 487 insertions(+), 591 deletions(-) diff --git a/composer.json b/composer.json index 5965dab..636a02d 100644 --- a/composer.json +++ b/composer.json @@ -71,7 +71,7 @@ "phpcs": "phpcs src tests --standard=psr2 -sp --colors", "phpstan": [ "phpstan analyse -c phpstan.neon src --level max --no-progress", - "phpstan analyse -c phpstan-tests.neon tests --level 5 --no-progress" + "phpstan analyse -c phpstan-tests.neon tests --level max --no-progress" ], "phpunit": "phpunit --verbose --colors=always", "phpunit-coverage": "phpunit --verbose --colors=always --coverage-html build/coverage", diff --git a/phpstan-tests.neon b/phpstan-tests.neon index e574e17..b075903 100644 --- a/phpstan-tests.neon +++ b/phpstan-tests.neon @@ -1,3 +1,21 @@ parameters: autoload_files: - tests/phpstan-bootstrap.php + reportUnmatchedIgnoredErrors: false + ignoreErrors: + - + message: "#^Function uuid_create\\(\\) has no return typehint specified\\.$#" + count: 1 + path: tests/phpstan-bootstrap.php + - + message: "#^Function uuid_create\\(\\) has parameter \\$uuid_type with no typehint specified\\.$#" + count: 1 + path: tests/phpstan-bootstrap.php + - + message: "#^Function uuid_parse\\(\\) has no return typehint specified\\.$#" + count: 1 + path: tests/phpstan-bootstrap.php + - + message: "#^Function uuid_parse\\(\\) has parameter \\$uuid with no typehint specified\\.$#" + count: 1 + path: tests/phpstan-bootstrap.php diff --git a/tests/Builder/DefaultUuidBuilderTest.php b/tests/Builder/DefaultUuidBuilderTest.php index 580d50f..26aaf8b 100644 --- a/tests/Builder/DefaultUuidBuilderTest.php +++ b/tests/Builder/DefaultUuidBuilderTest.php @@ -2,6 +2,7 @@ namespace Ramsey\Uuid\Test\Builder; +use PHPUnit\Framework\MockObject\MockObject; use Ramsey\Uuid\Builder\DefaultUuidBuilder; use Ramsey\Uuid\Codec\CodecInterface; use Ramsey\Uuid\Converter\NumberConverterInterface; @@ -9,19 +10,19 @@ use Ramsey\Uuid\Converter\TimeConverterInterface; use Ramsey\Uuid\Test\TestCase; use Ramsey\Uuid\Uuid; -/** - * Class DefaultUuidBuilderTest - * @package Ramsey\Uuid\Test\Builder - * @covers Ramsey\Uuid\Builder\DefaultUuidBuilder - */ class DefaultUuidBuilderTest extends TestCase { - - public function testBuildCreatesUuid() + public function testBuildCreatesUuid(): void { + /** @var MockObject & NumberConverterInterface $numberConverter */ $numberConverter = $this->getMockBuilder(NumberConverterInterface::class)->getMock(); + + /** @var MockObject & TimeConverterInterface $timeConverter */ $timeConverter = $this->getMockBuilder(TimeConverterInterface::class)->getMock(); + $builder = new DefaultUuidBuilder($numberConverter, $timeConverter); + + /** @var MockObject & CodecInterface $codec */ $codec = $this->getMockBuilder(CodecInterface::class)->getMock(); $fields = [ diff --git a/tests/Builder/DegradedUuidBuilderTest.php b/tests/Builder/DegradedUuidBuilderTest.php index 1e25a0c..b8668f6 100644 --- a/tests/Builder/DegradedUuidBuilderTest.php +++ b/tests/Builder/DegradedUuidBuilderTest.php @@ -2,6 +2,7 @@ namespace Ramsey\Uuid\Test\Builder; +use PHPUnit\Framework\MockObject\MockObject; use Ramsey\Uuid\Builder\DegradedUuidBuilder; use Ramsey\Uuid\Codec\CodecInterface; use Ramsey\Uuid\Converter\NumberConverterInterface; @@ -9,19 +10,19 @@ use Ramsey\Uuid\Converter\TimeConverterInterface; use Ramsey\Uuid\DegradedUuid; use Ramsey\Uuid\Test\TestCase; -/** - * Class DegradedUuidBuilderTest - * @package Ramsey\Uuid\Test\Builder - * @covers Ramsey\Uuid\Builder\DegradedUuidBuilder - */ class DegradedUuidBuilderTest extends TestCase { - - public function testBuildCreatesUuid() + public function testBuildCreatesUuid(): void { + /** @var MockObject & NumberConverterInterface $numberConverter */ $numberConverter = $this->getMockBuilder(NumberConverterInterface::class)->getMock(); + + /** @var MockObject & TimeConverterInterface $timeConverter */ $timeConverter = $this->getMockBuilder(TimeConverterInterface::class)->getMock(); + $builder = new DegradedUuidBuilder($numberConverter, $timeConverter); + + /** @var MockObject & CodecInterface $codec */ $codec = $this->getMockBuilder(CodecInterface::class)->getMock(); $fields = [ diff --git a/tests/Codec/GuidStringCodecTest.php b/tests/Codec/GuidStringCodecTest.php index dd6b087..6b46398 100644 --- a/tests/Codec/GuidStringCodecTest.php +++ b/tests/Codec/GuidStringCodecTest.php @@ -8,20 +8,21 @@ use Ramsey\Uuid\Codec\GuidStringCodec; use Ramsey\Uuid\Test\TestCase; use Ramsey\Uuid\UuidInterface; -/** - * Class GuidStringCodecTest - * @package Ramsey\Uuid\Test\Codec - * @covers Ramsey\Uuid\Codec\GuidStringCodec - */ class GuidStringCodecTest extends TestCase { - /** @var UuidBuilderInterface&MockObject */ + /** + * @var UuidBuilderInterface & MockObject + */ private $builder; - /** @var UuidInterface&MockObject */ + /** + * @var UuidInterface & MockObject + */ private $uuid; - /** @var array */ + /** + * @var string[] + */ private $fields; protected function setUp(): void @@ -43,7 +44,7 @@ class GuidStringCodecTest extends TestCase unset($this->builder, $this->fields, $this->uuid); } - public function testEncodeUsesFieldsArray() + public function testEncodeUsesFieldsArray(): void { $this->uuid->expects($this->once()) ->method('getFieldsHex') @@ -52,7 +53,7 @@ class GuidStringCodecTest extends TestCase $codec->encode($this->uuid); } - public function testEncodeReturnsFormattedString() + public function testEncodeReturnsFormattedString(): void { $this->skipIfBigEndianHost(); $this->uuid->method('getFieldsHex') @@ -62,7 +63,7 @@ class GuidStringCodecTest extends TestCase $this->assertEquals('78563412-3412-cdab-abef-1234abcd4321', $result); } - public function testEncodeReturnsFormattedStringOnBigEndian() + public function testEncodeReturnsFormattedStringOnBigEndian(): void { $this->skipIfLittleEndianHost(); $this->uuid->method('getFieldsHex') @@ -73,7 +74,7 @@ class GuidStringCodecTest extends TestCase } - public function testEncodeBinaryUsesFieldsArray() + public function testEncodeBinaryUsesFieldsArray(): void { $this->uuid->expects($this->once()) ->method('getFieldsHex') @@ -82,7 +83,7 @@ class GuidStringCodecTest extends TestCase $codec->encodeBinary($this->uuid); } - public function testEncodeBinaryReturnsBinaryString() + public function testEncodeBinaryReturnsBinaryString(): void { $expected = hex2bin('123456781234abcdabef1234abcd4321'); $this->uuid->method('getFieldsHex') @@ -92,7 +93,7 @@ class GuidStringCodecTest extends TestCase $this->assertEquals($expected, $result); } - public function testDecodeUsesBuilderOnFields() + public function testDecodeUsesBuilderOnFields(): void { $this->skipIfBigEndianHost(); $string = 'uuid:78563412-3412-cdab-abef-1234abcd4321'; @@ -103,7 +104,7 @@ class GuidStringCodecTest extends TestCase $codec->decode($string); } - public function testDecodeUsesBuilderOnFieldsOnBigEndian() + public function testDecodeUsesBuilderOnFieldsOnBigEndian(): void { $this->skipIfLittleEndianHost(); $string = 'uuid:12345678-1234-abcd-abef-1234abcd4321'; @@ -114,7 +115,7 @@ class GuidStringCodecTest extends TestCase $codec->decode($string); } - public function testDecodeReturnsUuidFromBuilder() + public function testDecodeReturnsUuidFromBuilder(): void { $string = 'uuid:78563412-3412-cdab-abef-1234abcd4321'; $this->builder->method('build') @@ -125,7 +126,7 @@ class GuidStringCodecTest extends TestCase $this->assertEquals($this->uuid, $result); } - public function testDecodeBytesReturnsUuid() + public function testDecodeBytesReturnsUuid(): void { $string = '123456781234abcdabef1234abcd4321'; $bytes = pack('H*', $string); diff --git a/tests/Codec/OrderedTimeCodecTest.php b/tests/Codec/OrderedTimeCodecTest.php index b2c1a2e..5464c22 100644 --- a/tests/Codec/OrderedTimeCodecTest.php +++ b/tests/Codec/OrderedTimeCodecTest.php @@ -8,27 +8,31 @@ use Ramsey\Uuid\Codec\OrderedTimeCodec; use Ramsey\Uuid\Test\TestCase; use Ramsey\Uuid\UuidInterface; -/** - * Class OrderedTimeCodecTest - * @package Ramsey\Uuid\Test\Codec - * @covers Ramsey\Uuid\Codec\OrderedTimeCodec - */ class OrderedTimeCodecTest extends TestCase { - - /** @var UuidBuilderInterface&MockObject */ + /** + * @var UuidBuilderInterface & MockObject + */ private $builder; - /** @var UuidInterface&MockObject */ + /** + * @var UuidInterface & MockObject + */ private $uuid; - /** @var array */ + /** + * @var string[] + */ private $fields; - /** @var string */ + /** + * @var string + */ private $uuidString = '58e0a7d7-eebc-11d8-9669-0800200c9a66'; - /** @var string */ + /** + * @var string + */ private $optimizedHex = '11d8eebc58e0a7d796690800200c9a66'; protected function setUp(): void @@ -50,7 +54,7 @@ class OrderedTimeCodecTest extends TestCase unset($this->builder, $this->uuid, $this->fields); } - public function testEncodeUsesFieldsArray() + public function testEncodeUsesFieldsArray(): void { $this->uuid->expects($this->once()) ->method('getFieldsHex') @@ -59,7 +63,7 @@ class OrderedTimeCodecTest extends TestCase $codec->encode($this->uuid); } - public function testEncodeReturnsFormattedString() + public function testEncodeReturnsFormattedString(): void { $this->uuid->method('getFieldsHex') ->willReturn($this->fields); @@ -68,7 +72,7 @@ class OrderedTimeCodecTest extends TestCase $this->assertEquals($this->uuidString, $result); } - public function testEncodeBinaryUsesFieldsHex() + public function testEncodeBinaryUsesFieldsHex(): void { $this->uuid->expects($this->once()) ->method('getFieldsHex') @@ -77,7 +81,7 @@ class OrderedTimeCodecTest extends TestCase $codec->encodeBinary($this->uuid); } - public function testEncodeBinaryReturnsBinaryString() + public function testEncodeBinaryReturnsBinaryString(): void { $expected = hex2bin($this->optimizedHex); $this->uuid->method('getFieldsHex') @@ -87,7 +91,7 @@ class OrderedTimeCodecTest extends TestCase $this->assertEquals($expected, $result); } - public function testDecodeBytesThrowsExceptionWhenBytesStringNotSixteenCharacters() + public function testDecodeBytesThrowsExceptionWhenBytesStringNotSixteenCharacters(): void { $string = '61'; $bytes = pack('H*', $string); @@ -98,7 +102,7 @@ class OrderedTimeCodecTest extends TestCase $codec->decodeBytes($bytes); } - public function testDecodeReturnsUuidFromBuilder() + public function testDecodeReturnsUuidFromBuilder(): void { $string = 'uuid:58e0a7d7-eebc-11d8-9669-0800200c9a66'; $this->builder->method('build') @@ -108,7 +112,7 @@ class OrderedTimeCodecTest extends TestCase $this->assertEquals($this->uuid, $result); } - public function testDecodeBytesRearrangesFields() + public function testDecodeBytesRearrangesFields(): void { $bytes = pack('H*', $this->optimizedHex); $codec = new OrderedTimeCodec($this->builder); diff --git a/tests/Codec/StringCodecTest.php b/tests/Codec/StringCodecTest.php index 0309a14..6d2ca24 100644 --- a/tests/Codec/StringCodecTest.php +++ b/tests/Codec/StringCodecTest.php @@ -8,24 +8,26 @@ use Ramsey\Uuid\Codec\StringCodec; use Ramsey\Uuid\Test\TestCase; use Ramsey\Uuid\UuidInterface; -/** - * Class StringCodecTest - * @package Ramsey\Uuid\Test\Codec - * @covers Ramsey\Uuid\Codec\StringCodec - */ class StringCodecTest extends TestCase { - - /** @var UuidBuilderInterface&MockObject */ + /** + * @var UuidBuilderInterface & MockObject + */ private $builder; - /** @var UuidInterface&MockObject */ + /** + * @var UuidInterface & MockObject + */ private $uuid; - /** @var array */ + /** + * @var string[] + */ private $fields; - /** @var string */ + /** + * @var string + */ private $uuidString = '12345678-1234-abcd-abef-1234abcd4321'; protected function setUp(): void @@ -47,7 +49,7 @@ class StringCodecTest extends TestCase unset($this->builder, $this->uuid, $this->fields); } - public function testEncodeUsesFieldsArray() + public function testEncodeUsesFieldsArray(): void { $this->uuid->expects($this->once()) ->method('getFieldsHex') @@ -56,7 +58,7 @@ class StringCodecTest extends TestCase $codec->encode($this->uuid); } - public function testEncodeReturnsFormattedString() + public function testEncodeReturnsFormattedString(): void { $this->uuid->method('getFieldsHex') ->willReturn($this->fields); @@ -65,7 +67,7 @@ class StringCodecTest extends TestCase $this->assertEquals($this->uuidString, $result); } - public function testEncodeBinaryUsesHexadecimalValue() + public function testEncodeBinaryUsesHexadecimalValue(): void { $this->uuid->expects($this->once()) ->method('getHex') @@ -74,7 +76,7 @@ class StringCodecTest extends TestCase $codec->encodeBinary($this->uuid); } - public function testEncodeBinaryReturnsBinaryString() + public function testEncodeBinaryReturnsBinaryString(): void { $expected = hex2bin('123456781234abcdabef1234abcd4321'); $this->uuid->method('getHex') @@ -84,7 +86,7 @@ class StringCodecTest extends TestCase $this->assertEquals($expected, $result); } - public function testDecodeUsesBuilderOnFields() + public function testDecodeUsesBuilderOnFields(): void { $string = 'uuid:12345678-1234-abcd-abef-1234abcd4321'; $this->builder->expects($this->once()) @@ -94,7 +96,7 @@ class StringCodecTest extends TestCase $codec->decode($string); } - public function testDecodeThrowsExceptionOnInvalidUuid() + public function testDecodeThrowsExceptionOnInvalidUuid(): void { $string = 'invalid-uuid'; $codec = new StringCodec($this->builder); @@ -103,7 +105,7 @@ class StringCodecTest extends TestCase $codec->decode($string); } - public function testDecodeReturnsUuidFromBuilder() + public function testDecodeReturnsUuidFromBuilder(): void { $string = 'uuid:12345678-1234-abcd-abef-1234abcd4321'; $this->builder->method('build') @@ -113,7 +115,7 @@ class StringCodecTest extends TestCase $this->assertEquals($this->uuid, $result); } - public function testDecodeBytesThrowsExceptionWhenBytesStringNotSixteenCharacters() + public function testDecodeBytesThrowsExceptionWhenBytesStringNotSixteenCharacters(): void { $string = '61'; $bytes = pack('H*', $string); @@ -124,7 +126,7 @@ class StringCodecTest extends TestCase $codec->decodeBytes($bytes); } - public function testDecodeBytesReturnsUuid() + public function testDecodeBytesReturnsUuid(): void { $string = '123456781234abcdabef1234abcd4321'; $bytes = pack('H*', $string); diff --git a/tests/Converter/Number/DegradedNumberConverterTest.php b/tests/Converter/Number/DegradedNumberConverterTest.php index 0bbcea1..379a42a 100644 --- a/tests/Converter/Number/DegradedNumberConverterTest.php +++ b/tests/Converter/Number/DegradedNumberConverterTest.php @@ -6,14 +6,9 @@ use Ramsey\Uuid\Converter\Number\DegradedNumberConverter; use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; use Ramsey\Uuid\Test\TestCase; -/** - * Class DegradedNumberConverterTest - * @package Ramsey\Uuid\Test\Converter\Number - * @covers Ramsey\Uuid\Converter\Number\DegradedNumberConverter - */ class DegradedNumberConverterTest extends TestCase { - public function testConvertingFromHexThrowsException() + public function testConvertingFromHexThrowsException(): void { $converter = new DegradedNumberConverter(); @@ -22,7 +17,7 @@ class DegradedNumberConverterTest extends TestCase $converter->fromHex('ffff'); } - public function testConvertingToHexThrowsException() + public function testConvertingToHexThrowsException(): void { $converter = new DegradedNumberConverter(); diff --git a/tests/Converter/Time/DegradedTimeConverterTest.php b/tests/Converter/Time/DegradedTimeConverterTest.php index e70862d..8b50070 100644 --- a/tests/Converter/Time/DegradedTimeConverterTest.php +++ b/tests/Converter/Time/DegradedTimeConverterTest.php @@ -6,13 +6,9 @@ use Ramsey\Uuid\Converter\Time\DegradedTimeConverter; use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; use Ramsey\Uuid\Test\TestCase; -/** - * Class DegradedTimeConverterTest - * @covers DegradedTimeConverter - */ class DegradedTimeConverterTest extends TestCase { - public function testConvertingFromHexThrowsException() + public function testConvertingFromHexThrowsException(): void { $converter = new DegradedTimeConverter(); @@ -21,7 +17,7 @@ class DegradedTimeConverterTest extends TestCase $converter->calculateTime('123', '123'); } - public function testConvertingToHexThrowsException() + public function testConvertingToHexThrowsException(): void { $converter = new DegradedTimeConverter(); diff --git a/tests/Converter/Time/PhpTimeConverterTest.php b/tests/Converter/Time/PhpTimeConverterTest.php index d96b182..e5108dd 100644 --- a/tests/Converter/Time/PhpTimeConverterTest.php +++ b/tests/Converter/Time/PhpTimeConverterTest.php @@ -5,15 +5,9 @@ namespace Ramsey\Uuid\Test\Converter\Time; use Ramsey\Uuid\Converter\Time\PhpTimeConverter; use Ramsey\Uuid\Test\TestCase; -/** - * Class PhpTimeConverterTest - * @package Ramsey\Uuid\Test\Converter - * @covers \Ramsey\Uuid\Converter\Time\PhpTimeConverter - */ class PhpTimeConverterTest extends TestCase { - - public function testCalculateTimeReturnsArrayOfTimeSegments() + public function testCalculateTimeReturnsArrayOfTimeSegments(): void { $seconds = 5; $microSeconds = 3; diff --git a/tests/Encoder/TimestampFirstCombCodecTest.php b/tests/Encoder/TimestampFirstCombCodecTest.php index ed57fd9..2c7ad75 100644 --- a/tests/Encoder/TimestampFirstCombCodecTest.php +++ b/tests/Encoder/TimestampFirstCombCodecTest.php @@ -1,4 +1,5 @@ codec = new TimestampFirstCombCodec($this->builderMock); } - public function testEncoding() + public function testEncoding(): void { + /** @var MockObject & UuidInterface $uuidMock */ $uuidMock = $this->getMockBuilder(UuidInterface::class)->getMock(); $uuidMock->expects($this->any()) ->method('getFieldsHex') @@ -37,8 +39,9 @@ class TimestampFirstCombCodecTest extends TestCase $this->assertSame('0800200c-9a66-11e1-9b21-ff6f8cb0c57d', $encodedUuid); } - public function testBinaryEncoding() + public function testBinaryEncoding(): void { + /** @var MockObject & UuidInterface $uuidMock */ $uuidMock = $this->getMockBuilder(UuidInterface::class)->getMock(); $uuidMock->expects($this->any()) ->method('getFieldsHex') @@ -48,7 +51,7 @@ class TimestampFirstCombCodecTest extends TestCase $this->assertSame(hex2bin('0800200c9a6611e19b21ff6f8cb0c57d'), $encodedUuid); } - public function testDecoding() + public function testDecoding(): void { $this->builderMock->expects($this->exactly(1)) ->method('build') @@ -66,7 +69,7 @@ class TimestampFirstCombCodecTest extends TestCase $this->codec->decode('0800200c-9a66-11e1-9b21-ff6f8cb0c57d'); } - public function testBinaryDecoding() + public function testBinaryDecoding(): void { $this->builderMock->expects($this->exactly(1)) ->method('build') @@ -81,6 +84,6 @@ class TimestampFirstCombCodecTest extends TestCase 'node' => '0800200c9a66' ] ); - $this->codec->decodeBytes(hex2bin('0800200c9a6611e19b21ff6f8cb0c57d')); + $this->codec->decodeBytes((string) hex2bin('0800200c9a6611e19b21ff6f8cb0c57d')); } } diff --git a/tests/Encoder/TimestampLastCombCodecTest.php b/tests/Encoder/TimestampLastCombCodecTest.php index 047ad8a..475d7dd 100644 --- a/tests/Encoder/TimestampLastCombCodecTest.php +++ b/tests/Encoder/TimestampLastCombCodecTest.php @@ -16,7 +16,7 @@ class TimestampLastCombCodecTest extends TestCase private $codec; /** - * @var MockObject + * @var MockObject & UuidBuilderInterface */ private $builderMock; @@ -26,8 +26,9 @@ class TimestampLastCombCodecTest extends TestCase $this->codec = new TimestampLastCombCodec($this->builderMock); } - public function testEncoding() + public function testEncoding(): void { + /** @var MockObject & UuidInterface $uuidMock */ $uuidMock = $this->getMockBuilder(UuidInterface::class)->getMock(); $uuidMock->expects($this->any()) ->method('getFieldsHex') @@ -37,8 +38,9 @@ class TimestampLastCombCodecTest extends TestCase $this->assertSame('0800200c-9a66-11e1-9b21-ff6f8cb0c57d', $encodedUuid); } - public function testBinaryEncoding() + public function testBinaryEncoding(): void { + /** @var MockObject & UuidInterface $uuidMock */ $uuidMock = $this->getMockBuilder(UuidInterface::class)->getMock(); $uuidMock->expects($this->any()) ->method('getHex') @@ -48,7 +50,7 @@ class TimestampLastCombCodecTest extends TestCase $this->assertSame(hex2bin('0800200c9a6611e19b21ff6f8cb0c57d'), $encodedUuid); } - public function testDecoding() + public function testDecoding(): void { $this->builderMock->expects($this->exactly(1)) ->method('build') @@ -66,7 +68,7 @@ class TimestampLastCombCodecTest extends TestCase $this->codec->decode('0800200c-9a66-11e1-9b21-ff6f8cb0c57d'); } - public function testBinaryDecoding() + public function testBinaryDecoding(): void { $this->builderMock->expects($this->exactly(1)) ->method('build') @@ -81,6 +83,6 @@ class TimestampLastCombCodecTest extends TestCase 'node' => 'ff6f8cb0c57d' ] ); - $this->codec->decodeBytes(hex2bin('0800200c9a6611e19b21ff6f8cb0c57d')); + $this->codec->decodeBytes((string) hex2bin('0800200c9a6611e19b21ff6f8cb0c57d')); } } diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 1fc59fd..e8590bf 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -3,38 +3,42 @@ namespace Ramsey\Uuid\Test; use Ramsey\Uuid\Uuid; +use function Ramsey\Uuid\v1; +use function Ramsey\Uuid\v3; +use function Ramsey\Uuid\v4; +use function Ramsey\Uuid\v5; class FunctionsTest extends TestCase { - public function testV1ReturnsVersion1UuidString() + public function testV1ReturnsVersion1UuidString(): void { - $v1 = \Ramsey\Uuid\v1(); + $v1 = v1(); $this->assertIsString($v1); $this->assertSame(Uuid::UUID_TYPE_TIME, Uuid::fromString($v1)->getVersion()); } - public function testV3ReturnsVersion3UuidString() + public function testV3ReturnsVersion3UuidString(): void { $ns = Uuid::fromString(Uuid::NAMESPACE_URL); - $v3 = \Ramsey\Uuid\v3($ns, 'https://example.com/foo'); + $v3 = v3($ns, 'https://example.com/foo'); $this->assertIsString($v3); $this->assertSame(Uuid::UUID_TYPE_HASH_MD5, Uuid::fromString($v3)->getVersion()); } - public function testV4ReturnsVersion4UuidString() + public function testV4ReturnsVersion4UuidString(): void { - $v4 = \Ramsey\Uuid\v4(); + $v4 = v4(); $this->assertIsString($v4); $this->assertSame(Uuid::UUID_TYPE_RANDOM, Uuid::fromString($v4)->getVersion()); } - public function testV5ReturnsVersion5UuidString() + public function testV5ReturnsVersion5UuidString(): void { $ns = Uuid::fromString(Uuid::NAMESPACE_URL); - $v5 = \Ramsey\Uuid\v5($ns, 'https://example.com/foo'); + $v5 = v5($ns, 'https://example.com/foo'); $this->assertIsString($v5); $this->assertSame(Uuid::UUID_TYPE_HASH_SHA1, Uuid::fromString($v5)->getVersion()); diff --git a/tests/Generator/CombGeneratorTest.php b/tests/Generator/CombGeneratorTest.php index 9a34524..62e261d 100644 --- a/tests/Generator/CombGeneratorTest.php +++ b/tests/Generator/CombGeneratorTest.php @@ -2,56 +2,68 @@ namespace Ramsey\Uuid\Test\Generator; +use Exception; +use InvalidArgumentException; use PHPUnit\Framework\Error\Error as PHPUnitError; +use PHPUnit\Framework\MockObject\MockObject; use Ramsey\Uuid\Converter\NumberConverterInterface; use Ramsey\Uuid\Generator\CombGenerator; use Ramsey\Uuid\Generator\RandomGeneratorInterface; use Ramsey\Uuid\Test\TestCase; -/** - * Class CombGeneratorTest - * @package Ramsey\Uuid\Test\Generator - * @covers Ramsey\Uuid\Generator\CombGenerator - */ class CombGeneratorTest extends TestCase { + /** + * @var int + */ private $timestampBytes = 6; - public function testGenerateUsesRandomGeneratorWithLengthMinusTimestampBytes() + public function testGenerateUsesRandomGeneratorWithLengthMinusTimestampBytes(): void { $length = 10; $expectedLength = ($length - $this->timestampBytes); + + /** @var MockObject & RandomGeneratorInterface $randomGenerator */ $randomGenerator = $this->getMockBuilder(RandomGeneratorInterface::class)->getMock(); $randomGenerator->expects($this->once()) ->method('generate') ->with($expectedLength); + + /** @var MockObject & NumberConverterInterface $converter */ $converter = $this->getMockBuilder(NumberConverterInterface::class)->getMock(); + $generator = new CombGenerator($randomGenerator, $converter); $generator->generate($length); } - public function testGenerateCalculatesPaddedHexStringFromCurrentTimestamp() + public function testGenerateCalculatesPaddedHexStringFromCurrentTimestamp(): void { + /** @var MockObject & RandomGeneratorInterface $randomGenerator */ $randomGenerator = $this->getMockBuilder(RandomGeneratorInterface::class)->getMock(); + + /** @var MockObject & NumberConverterInterface $converter */ $converter = $this->getMockBuilder(NumberConverterInterface::class)->getMock(); $converter->expects($this->once()) ->method('toHex') ->with($this->isType('string')); + $generator = new CombGenerator($randomGenerator, $converter); $generator->generate(10); } - public function testGenerateReturnsBinaryStringCreatedFromGeneratorAndConverter() + public function testGenerateReturnsBinaryStringCreatedFromGeneratorAndConverter(): void { $length = 20; $hash = dechex(1234567891); $timeHash = dechex(1458147405); + /** @var MockObject & RandomGeneratorInterface $randomGenerator */ $randomGenerator = $this->getMockBuilder(RandomGeneratorInterface::class)->getMock(); $randomGenerator->method('generate') ->with(($length - $this->timestampBytes)) ->willReturn($hash); + /** @var MockObject & NumberConverterInterface $converter */ $converter = $this->getMockBuilder(NumberConverterInterface::class)->getMock(); $converter->method('toHex') ->with($this->isType('string')) @@ -66,7 +78,10 @@ class CombGeneratorTest extends TestCase $this->assertEquals($expected, $returned); } - public function lengthLessThanSix() + /** + * @return array[] + */ + public function lengthLessThanSix(): array { return [[0], [1], [2], [3], [4], [5]]; } @@ -74,25 +89,33 @@ class CombGeneratorTest extends TestCase /** * @dataProvider lengthLessThanSix * @param int $length - * @throws \Exception + * @throws Exception */ - public function testGenerateWithLessThanTimestampBytesThrowsException($length) + public function testGenerateWithLessThanTimestampBytesThrowsException($length): void { + /** @var MockObject & RandomGeneratorInterface $randomGenerator */ $randomGenerator = $this->getMockBuilder(RandomGeneratorInterface::class)->getMock(); + + /** @var MockObject & NumberConverterInterface $converter */ $converter = $this->getMockBuilder(NumberConverterInterface::class)->getMock(); + $generator = new CombGenerator($randomGenerator, $converter); - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $generator->generate($length); } /** - * PHP Unit converts the error to an exception so we can test it. + * @throws Exception */ - public function testGenerateWithOddNumberOverTimestampBytesCausesError() + public function testGenerateWithOddNumberOverTimestampBytesCausesError(): void { + /** @var MockObject & RandomGeneratorInterface $randomGenerator */ $randomGenerator = $this->getMockBuilder(RandomGeneratorInterface::class)->getMock(); + + /** @var MockObject & NumberConverterInterface $converter */ $converter = $this->getMockBuilder(NumberConverterInterface::class)->getMock(); + $generator = new CombGenerator($randomGenerator, $converter); $this->expectException(PHPUnitError::class); diff --git a/tests/Generator/DefaultTimeGeneratorTest.php b/tests/Generator/DefaultTimeGeneratorTest.php index 802d53f..8ce1e9f 100644 --- a/tests/Generator/DefaultTimeGeneratorTest.php +++ b/tests/Generator/DefaultTimeGeneratorTest.php @@ -14,25 +14,39 @@ use Ramsey\Uuid\Test\TestCase; class DefaultTimeGeneratorTest extends TestCase { - /** @var TimeProviderInterface&MockObject */ + /** + * @var TimeProviderInterface & MockObject + */ private $timeProvider; - /** @var NodeProviderInterface&MockObject */ + /** + * @var NodeProviderInterface & MockObject + */ private $nodeProvider; - /** @var TimeConverterInterface&MockObject */ + /** + * @var TimeConverterInterface & MockObject + */ private $timeConverter; - /** @var string */ + /** + * @var string + */ private $nodeId = '122f80ca9e06'; - /** @var int[] */ + /** + * @var int[] + */ private $currentTime; - /** @var string[] */ + /** + * @var string[] + */ private $calculatedTime; - /** @var int */ + /** + * @var int + */ private $clockSeq = 4066; protected function setUp(): void @@ -41,8 +55,8 @@ class DefaultTimeGeneratorTest extends TestCase $this->timeProvider = $this->getMockBuilder(TimeProviderInterface::class)->getMock(); $this->nodeProvider = $this->getMockBuilder(NodeProviderInterface::class)->getMock(); $this->timeConverter = $this->getMockBuilder(TimeConverterInterface::class)->getMock(); - $this->currentTime = ["sec" => 1458733431, "usec" => 877449]; - $this->calculatedTime = ["low" => "83cb98e0", "mid" => "98e0", "hi" => "03cb"]; + $this->currentTime = ['sec' => 1458733431, 'usec' => 877449]; + $this->calculatedTime = ['low' => '83cb98e0', 'mid' => '98e0', 'hi' => '03cb']; } protected function tearDown(): void @@ -53,7 +67,7 @@ class DefaultTimeGeneratorTest extends TestCase AspectMock::clean(); } - public function testGenerateUsesNodeProviderWhenNodeIsNull() + public function testGenerateUsesNodeProviderWhenNodeIsNull(): void { $this->nodeProvider->expects($this->once()) ->method('getNode') @@ -72,7 +86,7 @@ class DefaultTimeGeneratorTest extends TestCase $defaultTimeGenerator->generate(null, $this->clockSeq); } - public function testGenerateUsesTimeProvidersCurrentTime() + public function testGenerateUsesTimeProvidersCurrentTime(): void { $this->timeProvider->expects($this->once()) ->method('currentTime') @@ -89,7 +103,7 @@ class DefaultTimeGeneratorTest extends TestCase $defaultTimeGenerator->generate($this->nodeId, $this->clockSeq); } - public function testGenerateCalculatesTimeWithConverter() + public function testGenerateCalculatesTimeWithConverter(): void { $this->timeProvider->method('currentTime') ->willReturn($this->currentTime); @@ -109,7 +123,7 @@ class DefaultTimeGeneratorTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testGenerateAppliesVersionAndVariant() + public function testGenerateAppliesVersionAndVariant(): void { $expectedBytes = hex2bin('83cb98e098e003cb8fe2122f80ca9e06'); @@ -140,7 +154,7 @@ class DefaultTimeGeneratorTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testGenerateReturnsBinaryStringInUuidFormat() + public function testGenerateReturnsBinaryStringInUuidFormat(): void { $this->timeProvider->method('currentTime')->willReturn($this->currentTime); $this->timeConverter->method('calculateTime')->willReturn($this->calculatedTime); @@ -154,22 +168,27 @@ class DefaultTimeGeneratorTest extends TestCase $this->timeProvider ); $result = $defaultTimeGenerator->generate($this->nodeId, $this->clockSeq); - /** - * // Given we use values: - * $low = '83cb98e0'; - * $mid = '98e0'; - * $timeHi = 971; - * $clockSeqHi = 143; - * $clockSeq = 4066; - * $node = '122f80ca9e06'; - * - * $values = [$low, $mid, - * sprintf('%04x', $timeHi), sprintf('%02x', $clockSeqHi), - * sprintf('%02x', $clockSeq & 0xff), $node]; - * - * // then: - * $hex = vsprintf('%08s%04s%04s%02s%02s%012s', $values); - */ + + // Given we use values: + // $low = '83cb98e0'; + // $mid = '98e0'; + // $timeHi = 971; + // $clockSeqHi = 143; + // $clockSeq = 4066; + // $node = '122f80ca9e06'; + // + // $values = [ + // $low, + // $mid, + // sprintf('%04x', $timeHi), + // sprintf('%02x', $clockSeqHi), + // sprintf('%02x', $clockSeq & 0xff), + // $node + // ]; + // + // then: + // $hex = vsprintf('%08s%04s%04s%02s%02s%012s', $values); + $hex = '83cb98e098e003cb8fe2122f80ca9e06'; $binary = hex2bin($hex); $this->assertEquals($binary, $result); @@ -179,7 +198,7 @@ class DefaultTimeGeneratorTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testGenerateUsesRandomSequenceWhenClockSeqNull() + public function testGenerateUsesRandomSequenceWhenClockSeqNull(): void { $random_int = AspectMock::func('Ramsey\Uuid\Generator', 'random_int', 9622); $this->timeProvider->method('currentTime') diff --git a/tests/Generator/PeclUuidRandomGeneratorTest.php b/tests/Generator/PeclUuidRandomGeneratorTest.php index fa28854..7841ebd 100644 --- a/tests/Generator/PeclUuidRandomGeneratorTest.php +++ b/tests/Generator/PeclUuidRandomGeneratorTest.php @@ -1,23 +1,22 @@ uuidString); $parse = AspectMock::func('Ramsey\Uuid\Generator', 'uuid_parse', $this->uuidBinary); @@ -34,7 +33,7 @@ class PeclUuidRandomGeneratorTest extends PeclUuidTestCase * This test is for the return type of the generate method * It ensures that the generate method returns whatever value uuid_parse returns. */ - public function testGenerateReturnsUuidString() + public function testGenerateReturnsUuidString(): void { $create = AspectMock::func('Ramsey\Uuid\Generator', 'uuid_create', $this->uuidString); $parse = AspectMock::func('Ramsey\Uuid\Generator', 'uuid_parse', $this->uuidBinary); diff --git a/tests/Generator/PeclUuidTestCase.php b/tests/Generator/PeclUuidTestCase.php index 9cc2055..c0dbff6 100644 --- a/tests/Generator/PeclUuidTestCase.php +++ b/tests/Generator/PeclUuidTestCase.php @@ -6,6 +6,13 @@ use Ramsey\Uuid\Test\TestCase; class PeclUuidTestCase extends TestCase { + /** + * @var string + */ protected $uuidString = 'b08c6fff-7dc5-e111-9b21-0800200c9a66'; + + /** + * @var string + */ protected $uuidBinary = '62303863366666662d376463352d653131312d396232312d303830303230306339613636'; } diff --git a/tests/Generator/PeclUuidTimeGeneratorTest.php b/tests/Generator/PeclUuidTimeGeneratorTest.php index 0694888..4a0cb56 100644 --- a/tests/Generator/PeclUuidTimeGeneratorTest.php +++ b/tests/Generator/PeclUuidTimeGeneratorTest.php @@ -1,21 +1,17 @@ uuidString); $parse = AspectMock::func('Ramsey\Uuid\Generator', 'uuid_parse', $this->uuidBinary); @@ -32,7 +28,7 @@ class PeclUuidTimeGeneratorTest extends PeclUuidTestCase * This test is for the return type of the generate method * It ensures that the generate method returns whatever value uuid_parse returns. */ - public function testGenerateReturnsUuidString() + public function testGenerateReturnsUuidString(): void { $create = AspectMock::func('Ramsey\Uuid\Generator', 'uuid_create', $this->uuidString); $parse = AspectMock::func('Ramsey\Uuid\Generator', 'uuid_parse', $this->uuidBinary); diff --git a/tests/Generator/RandomBytesGeneratorTest.php b/tests/Generator/RandomBytesGeneratorTest.php index b72376d..67c34b9 100644 --- a/tests/Generator/RandomBytesGeneratorTest.php +++ b/tests/Generator/RandomBytesGeneratorTest.php @@ -2,18 +2,17 @@ namespace Ramsey\Uuid\Test\Generator; +use AspectMock\Test as AspectMock; +use Exception; use Ramsey\Uuid\Generator\RandomBytesGenerator; use Ramsey\Uuid\Test\TestCase; -use AspectMock\Test as AspectMock; -/** - * Class RandomBytesGeneratorTest - * @package Ramsey\Uuid\Test\Generator - * @covers Ramsey\Uuid\Generator\RandomBytesGenerator - */ class RandomBytesGeneratorTest extends TestCase { - public function lengthAndHexDataProvider() + /** + * @return array[] + */ + public function lengthAndHexDataProvider(): array { return [ [6, '4f17dd046fb8'], @@ -28,9 +27,9 @@ class RandomBytesGeneratorTest extends TestCase * @preserveGlobalState disabled * @param int $length * @param string $hex - * @throws \Exception + * @throws Exception */ - public function testGenerateUsesOpenSsl($length, $hex) + public function testGenerateUsesOpenSsl($length, $hex): void { $bytes = hex2bin($hex); $openSsl = AspectMock::func('Ramsey\Uuid\Generator', 'random_bytes', $bytes); @@ -46,9 +45,9 @@ class RandomBytesGeneratorTest extends TestCase * @preserveGlobalState disabled * @param int $length * @param string $hex - * @throws \Exception + * @throws Exception */ - public function testGenerateReturnsRandomBytes($length, $hex) + public function testGenerateReturnsRandomBytes($length, $hex): void { $bytes = hex2bin($hex); AspectMock::func('Ramsey\Uuid\Generator', 'random_bytes', $bytes); diff --git a/tests/Generator/RandomGeneratorFactoryTest.php b/tests/Generator/RandomGeneratorFactoryTest.php index d00d768..e9fa93a 100644 --- a/tests/Generator/RandomGeneratorFactoryTest.php +++ b/tests/Generator/RandomGeneratorFactoryTest.php @@ -3,12 +3,12 @@ namespace Ramsey\Uuid\Test\Generator; use Ramsey\Uuid\Generator\RandomBytesGenerator; -use Ramsey\Uuid\Test\TestCase; use Ramsey\Uuid\Generator\RandomGeneratorFactory; +use Ramsey\Uuid\Test\TestCase; class RandomGeneratorFactoryTest extends TestCase { - public function testFactoryReturnsRandomBytesGenerator() + public function testFactoryReturnsRandomBytesGenerator(): void { $generator = RandomGeneratorFactory::getGenerator(); diff --git a/tests/Generator/RandomLibAdapterTest.php b/tests/Generator/RandomLibAdapterTest.php index b146360..967d356 100644 --- a/tests/Generator/RandomLibAdapterTest.php +++ b/tests/Generator/RandomLibAdapterTest.php @@ -2,28 +2,22 @@ namespace Ramsey\Uuid\Test\Generator; +use Mockery; use Ramsey\Uuid\Generator\RandomLibAdapter; use Ramsey\Uuid\Test\TestCase; -use Mockery; use RandomLib\Factory as RandomLibFactory; use RandomLib\Generator; -/** - * Class RandomLibAdapterTest - * @package Ramsey\Uuid\Test\Generator - * @covers Ramsey\Uuid\Generator\RandomLibAdapter - */ class RandomLibAdapterTest extends TestCase { /** * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testAdapterWithGeneratorDoesNotCreateGenerator() + public function testAdapterWithGeneratorDoesNotCreateGenerator(): void { $factory = Mockery::mock('overload:' . RandomLibFactory::class); - $factory->shouldNotReceive('getHighStrengthGenerator') - ->getMock(); + $factory->shouldNotReceive('getHighStrengthGenerator'); $generator = $this->getMockBuilder(Generator::class) ->disableOriginalConstructor() @@ -36,17 +30,15 @@ class RandomLibAdapterTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testAdapterWithoutGeneratorGreatesGenerator() + public function testAdapterWithoutGeneratorGreatesGenerator(): void { $factory = Mockery::mock('overload:' . RandomLibFactory::class); - $factory->shouldReceive('getHighStrengthGenerator') - ->once() - ->getMock(); + $factory->shouldReceive('getHighStrengthGenerator')->once(); $this->assertInstanceOf(RandomLibAdapter::class, new RandomLibAdapter()); } - public function testGenerateUsesGenerator() + public function testGenerateUsesGenerator(): void { $length = 10; $generator = $this->getMockBuilder(Generator::class) @@ -60,7 +52,7 @@ class RandomLibAdapterTest extends TestCase $adapter->generate($length); } - public function testGenerateReturnsString() + public function testGenerateReturnsString(): void { $generator = $this->getMockBuilder(Generator::class) ->disableOriginalConstructor() diff --git a/tests/Generator/TimeGeneratorFactoryTest.php b/tests/Generator/TimeGeneratorFactoryTest.php index f5a5620..0b7a0c8 100644 --- a/tests/Generator/TimeGeneratorFactoryTest.php +++ b/tests/Generator/TimeGeneratorFactoryTest.php @@ -2,6 +2,7 @@ namespace Ramsey\Uuid\Test\Generator; +use PHPUnit\Framework\MockObject\MockObject; use Ramsey\Uuid\Converter\TimeConverterInterface; use Ramsey\Uuid\Generator\TimeGeneratorFactory; use Ramsey\Uuid\Generator\TimeGeneratorInterface; @@ -9,21 +10,22 @@ use Ramsey\Uuid\Provider\NodeProviderInterface; use Ramsey\Uuid\Provider\TimeProviderInterface; use Ramsey\Uuid\Test\TestCase; -/** - * Class TimeGeneratorFactoryTest - * @package Ramsey\Uuid\Test\Generator - * @covers Ramsey\Uuid\Generator\TimeGeneratorFactory - */ class TimeGeneratorFactoryTest extends TestCase { - public function testGeneratorReturnsNewGenerator() + public function testGeneratorReturnsNewGenerator(): void { + /** @var MockObject & TimeProviderInterface $timeProvider */ $timeProvider = $this->getMockBuilder(TimeProviderInterface::class)->getMock(); + + /** @var MockObject & NodeProviderInterface $nodeProvider */ $nodeProvider = $this->getMockBuilder(NodeProviderInterface::class)->getMock(); + + /** @var MockObject & TimeConverterInterface $timeConverter */ $timeConverter = $this->getMockBuilder(TimeConverterInterface::class)->getMock(); $factory = new TimeGeneratorFactory($nodeProvider, $timeConverter, $timeProvider); $generator = $factory->getGenerator(); + $this->assertInstanceOf(TimeGeneratorInterface::class, $generator); } } diff --git a/tests/Provider/Node/FallbackNodeProviderTest.php b/tests/Provider/Node/FallbackNodeProviderTest.php index 5a60bf5..f95927b 100644 --- a/tests/Provider/Node/FallbackNodeProviderTest.php +++ b/tests/Provider/Node/FallbackNodeProviderTest.php @@ -2,13 +2,13 @@ namespace Ramsey\Uuid\Test\Provider\Node; -use Ramsey\Uuid\Provider\Node\FallbackNodeProvider; use Ramsey\Uuid\Provider\NodeProviderInterface; +use Ramsey\Uuid\Provider\Node\FallbackNodeProvider; use Ramsey\Uuid\Test\TestCase; class FallbackNodeProviderTest extends TestCase { - public function testGetNodeCallsGetNodeOnEachProviderUntilNodeFound() + public function testGetNodeCallsGetNodeOnEachProviderUntilNodeFound(): void { $providerWithNode = $this->getMockBuilder(NodeProviderInterface::class)->getMock(); $providerWithNode->expects($this->once()) @@ -23,7 +23,7 @@ class FallbackNodeProviderTest extends TestCase $provider->getNode(); } - public function testGetNodeReturnsNodeFromFirstProviderWithNode() + public function testGetNodeReturnsNodeFromFirstProviderWithNode(): void { $providerWithoutNode = $this->getMockBuilder(NodeProviderInterface::class)->getMock(); $providerWithoutNode->expects($this->once()) @@ -39,10 +39,11 @@ class FallbackNodeProviderTest extends TestCase $provider = new FallbackNodeProvider([$providerWithoutNode, $providerWithNode, $anotherProviderWithoutNode]); $node = $provider->getNode(); + $this->assertEquals('57764a07f756', $node); } - public function testGetNodeReturnsNullWhenNoNodesFound() + public function testGetNodeReturnsNullWhenNoNodesFound(): void { $providerWithoutNode = $this->getMockBuilder(NodeProviderInterface::class)->getMock(); $providerWithoutNode->method('getNode') @@ -50,6 +51,7 @@ class FallbackNodeProviderTest extends TestCase $provider = new FallbackNodeProvider([$providerWithoutNode]); $node = $provider->getNode(); + $this->assertNull($node); } } diff --git a/tests/Provider/Node/RandomNodeProviderTest.php b/tests/Provider/Node/RandomNodeProviderTest.php index fea2fe5..6cad34f 100644 --- a/tests/Provider/Node/RandomNodeProviderTest.php +++ b/tests/Provider/Node/RandomNodeProviderTest.php @@ -2,9 +2,9 @@ namespace Ramsey\Uuid\Test\Provider\Node; +use AspectMock\Test as AspectMock; use Ramsey\Uuid\Provider\Node\RandomNodeProvider; use Ramsey\Uuid\Test\TestCase; -use AspectMock\Test as AspectMock; class RandomNodeProviderTest extends TestCase { @@ -18,7 +18,7 @@ class RandomNodeProviderTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testGetNodeUsesRandomBytes() + public function testGetNodeUsesRandomBytes(): void { $bytes = hex2bin('38a675685d50'); $expectedNode = '39a675685d50'; @@ -35,7 +35,7 @@ class RandomNodeProviderTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testGetNodeSetsMulticastBit() + public function testGetNodeSetsMulticastBit(): void { $bytes = hex2bin('38a675685d50'); @@ -53,7 +53,7 @@ class RandomNodeProviderTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testGetNodeAlreadyHasMulticastBit() + public function testGetNodeAlreadyHasMulticastBit(): void { $bytesHex = '4161a1ff5d50'; $bytes = hex2bin($bytesHex); @@ -72,7 +72,7 @@ class RandomNodeProviderTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testGetNodeSetsMulticastBitForLowNodeValue() + public function testGetNodeSetsMulticastBitForLowNodeValue(): void { $bytes = hex2bin('100000000001'); $expectedNode = '110000000001'; @@ -84,7 +84,7 @@ class RandomNodeProviderTest extends TestCase $randomBytes->verifyInvoked([6]); } - public function testGetNodeAlwaysSetsMulticastBit() + public function testGetNodeAlwaysSetsMulticastBit(): void { $provider = new RandomNodeProvider(); $nodeHex = $provider->getNode(); @@ -92,7 +92,7 @@ class RandomNodeProviderTest extends TestCase // Convert what we got into bytes so that we can mask out everything // except the multicast bit. If the multicast bit doesn't exist, this // test will fail appropriately. - $nodeBytes = hex2bin($nodeHex); + $nodeBytes = (string) hex2bin($nodeHex); // Split the node bytes for math on 32-bit systems. $nodeMsb = substr($nodeBytes, 0, 3); diff --git a/tests/Provider/Node/SystemNodeProviderTest.php b/tests/Provider/Node/SystemNodeProviderTest.php index e71caa1..8827d7f 100644 --- a/tests/Provider/Node/SystemNodeProviderTest.php +++ b/tests/Provider/Node/SystemNodeProviderTest.php @@ -3,10 +3,10 @@ namespace Ramsey\Uuid\Test\Provider\Node; use AspectMock\Proxy\FuncProxy; +use AspectMock\Test as AspectMock; use InvalidArgumentException; use Ramsey\Uuid\Provider\Node\SystemNodeProvider; use Ramsey\Uuid\Test\TestCase; -use AspectMock\Test as AspectMock; /** * Tests for the SystemNodeProvider class @@ -44,7 +44,9 @@ class SystemNodeProviderTest extends TestCase const PROVIDER_NAMESPACE = 'Ramsey\\Uuid\\Provider\\Node'; - /** @var FuncProxy[] */ + /** + * @var FuncProxy[] + */ private $functionProxies = []; /** @@ -56,7 +58,7 @@ class SystemNodeProviderTest extends TestCase * @param string $netstatOutput * @param string $expected */ - public function testGetNodeReturnsSystemNodeFromMacAddress($netstatOutput, $expected) + public function testGetNodeReturnsSystemNodeFromMacAddress($netstatOutput, $expected): void { /*/ Arrange mocks for native functions /*/ $this->arrangeMockFunctions( @@ -93,7 +95,7 @@ class SystemNodeProviderTest extends TestCase * * @param string $netstatOutput */ - public function testGetNodeShouldNotReturnsSystemNodeForInvalidMacAddress($netstatOutput) + public function testGetNodeShouldNotReturnsSystemNodeForInvalidMacAddress($netstatOutput): void { /*/ Arrange /*/ $this->arrangeMockFunctions( @@ -125,7 +127,7 @@ class SystemNodeProviderTest extends TestCase * @param string $formatted * @param string $expected */ - public function testGetNodeReturnsNodeStrippedOfNotationalFormatting($formatted, $expected) + public function testGetNodeReturnsNodeStrippedOfNotationalFormatting($formatted, $expected): void { /*/ Arrange /*/ $this->arrangeMockFunctions( @@ -156,7 +158,7 @@ class SystemNodeProviderTest extends TestCase * * @param string $formatted */ - public function testGetNodeDoesNotAcceptIncorrectNotationalFormatting($formatted) + public function testGetNodeDoesNotAcceptIncorrectNotationalFormatting($formatted): void { /*/ Arrange /*/ $this->arrangeMockFunctions( @@ -183,7 +185,7 @@ class SystemNodeProviderTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testGetNodeReturnsFirstMacAddressFound() + public function testGetNodeReturnsFirstMacAddressFound(): void { /*/ Arrange /*/ $this->arrangeMockFunctions( @@ -210,7 +212,7 @@ class SystemNodeProviderTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testGetNodeReturnsFalseWhenNodeIsNotFound() + public function testGetNodeReturnsFalseWhenNodeIsNotFound(): void { /*/ Arrange /*/ $this->arrangeMockFunctions( @@ -237,7 +239,7 @@ class SystemNodeProviderTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testGetNodeWillNotExecuteSystemCallIfFailedFirstTime() + public function testGetNodeWillNotExecuteSystemCallIfFailedFirstTime(): void { /*/ Arrange /*/ $this->arrangeMockFunctions( @@ -270,7 +272,7 @@ class SystemNodeProviderTest extends TestCase * @param string $os * @param string $command */ - public function testGetNodeGetsNetworkInterfaceConfig($os, $command) + public function testGetNodeGetsNetworkInterfaceConfig($os, $command): void { /*/ Arrange /*/ $this->arrangeMockFunctions( @@ -311,7 +313,7 @@ class SystemNodeProviderTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testGetNodeReturnsSameNodeUponSubsequentCalls() + public function testGetNodeReturnsSameNodeUponSubsequentCalls(): void { /*/ Arrange /*/ $this->arrangeMockFunctions( @@ -339,7 +341,7 @@ class SystemNodeProviderTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testSubsequentCallsToGetNodeDoNotRecallIfconfig() + public function testSubsequentCallsToGetNodeDoNotRecallIfconfig(): void { /*/ Arrange /*/ $this->arrangeMockFunctions( @@ -372,7 +374,7 @@ class SystemNodeProviderTest extends TestCase * @param string $os * @param string $command */ - public function testCallGetsysfsOnLinux($os, $command) + public function testCallGetsysfsOnLinux($os, $command): void { /*/ Arrange /*/ $this->arrangeMockFunctions( @@ -425,7 +427,7 @@ class SystemNodeProviderTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testCallGetsysfsOnLinuxWhenGlobReturnsFalse() + public function testCallGetsysfsOnLinuxWhenGlobReturnsFalse(): void { /*/ Arrange /*/ $this->arrangeMockFunctions( @@ -458,7 +460,7 @@ class SystemNodeProviderTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testCallGetsysfsOnLinuxWhenGlobReturnsEmptyArray() + public function testCallGetsysfsOnLinuxWhenGlobReturnsEmptyArray(): void { /*/ Arrange /*/ $this->arrangeMockFunctions( @@ -491,7 +493,7 @@ class SystemNodeProviderTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testCallGetsysfsOnLinuxWhenGlobFilesAreNotReadable() + public function testCallGetsysfsOnLinuxWhenGlobFilesAreNotReadable(): void { /*/ Arrange /*/ $this->arrangeMockFunctions( @@ -527,7 +529,7 @@ class SystemNodeProviderTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testGetNodeReturnsFalseWhenPassthruIsDisabled() + public function testGetNodeReturnsFalseWhenPassthruIsDisabled(): void { /*/ Arrange /*/ $this->arrangeMockFunctions( @@ -562,6 +564,7 @@ class SystemNodeProviderTest extends TestCase * @param callback|mixed|null $passthruBody * @param callback|mixed|null $constantBody * @param callback|mixed|null $iniGetDisableFunctionsBody + * @param callback|mixed|null $isReadableBody */ private function arrangeMockFunctions( $fileGetContentsBody, @@ -570,7 +573,7 @@ class SystemNodeProviderTest extends TestCase $constantBody, $iniGetDisableFunctionsBody, $isReadableBody = true - ) { + ): void { $mockFunction = [ self::MOCK_FILE_GET_CONTENTS => $fileGetContentsBody, self::MOCK_GLOB => $globBody, @@ -590,12 +593,12 @@ class SystemNodeProviderTest extends TestCase * * Provide a NULL to assert a function is never called. * - * @param array|null $fileGetContentsAssert - * @param array|null $globBodyAssert - * @param array|null $passthruBodyAssert - * @param array|null $constantBodyAssert - * @param array|null $iniGetDisableFunctionsAssert - * @param array|null $isReadableAssert + * @param string[]|array[]|null $fileGetContentsAssert + * @param string[]|array[]|null $globBodyAssert + * @param string[]|array[]|null $passthruBodyAssert + * @param string[]|array[]|null $constantBodyAssert + * @param string[]|array[]|null $iniGetDisableFunctionsAssert + * @param string[]|array[]|null $isReadableAssert */ private function assertMockFunctions( $fileGetContentsAssert, @@ -604,7 +607,7 @@ class SystemNodeProviderTest extends TestCase $constantBodyAssert, $iniGetDisableFunctionsAssert, $isReadableAssert = null - ) { + ): void { $mockFunctionAsserts = [ self::MOCK_FILE_GET_CONTENTS => $fileGetContentsAssert, self::MOCK_GLOB => $globBodyAssert, @@ -639,7 +642,7 @@ class SystemNodeProviderTest extends TestCase * * @return array[] */ - public function provideCommandPerOs() + public function provideCommandPerOs(): array { return [ 'windows' => ['Windows', 'ipconfig /all 2>&1'], @@ -656,7 +659,7 @@ class SystemNodeProviderTest extends TestCase * * @return array[] */ - public function provideInvalidNetStatOutput() + public function provideInvalidNetStatOutput(): array { return [ 'Not an octal value' => [ @@ -681,7 +684,7 @@ class SystemNodeProviderTest extends TestCase * * @return array[] */ - public function provideInvalidNotationalFormats() + public function provideInvalidNotationalFormats(): array { return [ ['01:23-45-67-89-ab'], @@ -700,7 +703,7 @@ class SystemNodeProviderTest extends TestCase * * @return array[] */ - public function provideNotationalFormats() + public function provideNotationalFormats(): array { return [ ['01-23-45-67-89-ab', '0123456789ab'], @@ -713,7 +716,7 @@ class SystemNodeProviderTest extends TestCase * * @return array[] */ - public function provideValidNetStatOutput() + public function provideValidNetStatOutput(): array { return [ /*/ Full output of related command /*/ diff --git a/tests/Provider/Time/FixedTimeProviderTest.php b/tests/Provider/Time/FixedTimeProviderTest.php index b4d6468..5c8295a 100644 --- a/tests/Provider/Time/FixedTimeProviderTest.php +++ b/tests/Provider/Time/FixedTimeProviderTest.php @@ -7,21 +7,20 @@ use Ramsey\Uuid\Test\TestCase; class FixedTimeProviderTest extends TestCase { - - public function testConstructorRequiresSecAndUsec() + public function testConstructorRequiresSecAndUsec(): void { $this->expectException(\InvalidArgumentException::class); $provider = new FixedTimeProvider([]); } - public function testCurrentTimeReturnsTimestamp() + public function testCurrentTimeReturnsTimestamp(): void { $timestamp = ['sec' => 1458844556, 'usec' => 200997]; $provider = new FixedTimeProvider($timestamp); $this->assertEquals($timestamp, $provider->currentTime()); } - public function testCurrentTimeReturnsTimestampAfterChange() + public function testCurrentTimeReturnsTimestampAfterChange(): void { $timestamp = ['sec' => 1458844556, 'usec' => 200997]; $provider = new FixedTimeProvider($timestamp); diff --git a/tests/Provider/Time/SystemTimeProviderTest.php b/tests/Provider/Time/SystemTimeProviderTest.php index ef3ff76..ddc34a8 100644 --- a/tests/Provider/Time/SystemTimeProviderTest.php +++ b/tests/Provider/Time/SystemTimeProviderTest.php @@ -2,14 +2,13 @@ namespace Ramsey\Uuid\Test\Provider\Time; +use AspectMock\Test as AspectMock; use Ramsey\Uuid\Provider\Time\SystemTimeProvider; use Ramsey\Uuid\Test\TestCase; -use AspectMock\Test as AspectMock; class SystemTimeProviderTest extends TestCase { - - public function testCurrentTimeReturnsTimestampArray() + public function testCurrentTimeReturnsTimestampArray(): void { $provider = new SystemTimeProvider(); $time = $provider->currentTime(); @@ -21,7 +20,7 @@ class SystemTimeProviderTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testCurrentTimeUsesGettimeofday() + public function testCurrentTimeUsesGettimeofday(): void { $timestamp = ['sec' => 1458844556, 'usec' => 200997]; $func = AspectMock::func('Ramsey\Uuid\Provider\Time', 'gettimeofday', $timestamp); diff --git a/tests/TestCase.php b/tests/TestCase.php index 52a1980..f626db4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -14,7 +14,7 @@ class TestCase extends PhpUnitTestCase Mockery::close(); } - protected function skip64BitTest() + protected function skip64BitTest(): void { if (PHP_INT_SIZE == 4) { $this->markTestSkipped( @@ -23,7 +23,7 @@ class TestCase extends PhpUnitTestCase } } - protected function skipIfNoMoontoastMath() + protected function skipIfNoMoontoastMath(): void { if (!$this->hasMoontoastMath()) { $this->markTestSkipped( @@ -32,7 +32,7 @@ class TestCase extends PhpUnitTestCase } } - protected function skipIfNoGmp() + protected function skipIfNoGmp(): void { if (!$this->hasGmp()) { $this->markTestSkipped( @@ -41,17 +41,17 @@ class TestCase extends PhpUnitTestCase } } - protected function hasMoontoastMath() + protected function hasMoontoastMath(): bool { return class_exists('Moontoast\\Math\\BigNumber'); } - protected function hasGmp() + protected function hasGmp(): bool { return extension_loaded('gmp'); } - protected function skipIfLittleEndianHost() + protected function skipIfLittleEndianHost(): void { if (self::isLittleEndianSystem()) { $this->markTestSkipped( @@ -60,7 +60,7 @@ class TestCase extends PhpUnitTestCase } } - protected function skipIfBigEndianHost() + protected function skipIfBigEndianHost(): void { if (!self::isLittleEndianSystem()) { $this->markTestSkipped( @@ -69,7 +69,7 @@ class TestCase extends PhpUnitTestCase } } - public static function isLittleEndianSystem() + public static function isLittleEndianSystem(): bool { return current(unpack('v', pack('S', 0x00FF))) === 0x00FF; } diff --git a/tests/UuidFactoryTest.php b/tests/UuidFactoryTest.php index f722d0e..b5b37a2 100644 --- a/tests/UuidFactoryTest.php +++ b/tests/UuidFactoryTest.php @@ -2,18 +2,19 @@ namespace Ramsey\Uuid\Test; -use Ramsey\Uuid\FeatureSet; -use Ramsey\Uuid\UuidFactory; -use Ramsey\Uuid\Codec\CodecInterface; -use Ramsey\Uuid\Generator\RandomGeneratorInterface; -use Ramsey\Uuid\Provider\NodeProviderInterface; -use Ramsey\Uuid\Generator\TimeGeneratorInterface; -use Ramsey\Uuid\Converter\NumberConverterInterface; +use PHPUnit\Framework\MockObject\MockObject; use Ramsey\Uuid\Builder\UuidBuilderInterface; +use Ramsey\Uuid\Codec\CodecInterface; +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\FeatureSet; +use Ramsey\Uuid\Generator\RandomGeneratorInterface; +use Ramsey\Uuid\Generator\TimeGeneratorInterface; +use Ramsey\Uuid\Provider\NodeProviderInterface; +use Ramsey\Uuid\UuidFactory; class UuidFactoryTest extends TestCase { - public function testParsesUuidCorrectly() + public function testParsesUuidCorrectly(): void { $factory = new UuidFactory(); @@ -22,7 +23,7 @@ class UuidFactoryTest extends TestCase $this->assertEquals('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->toString()); } - public function testParsesGuidCorrectly() + public function testParsesGuidCorrectly(): void { $factory = new UuidFactory(new FeatureSet(true)); @@ -31,7 +32,7 @@ class UuidFactoryTest extends TestCase $this->assertEquals('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->toString()); } - public function testFromStringParsesUuidInLowercase() + public function testFromStringParsesUuidInLowercase(): void { $uuidString = 'ff6f8cb0-c57d-11e1-9b21-0800200c9a66'; $uuidUpper = strtoupper($uuidString); @@ -42,7 +43,7 @@ class UuidFactoryTest extends TestCase $this->assertEquals($uuidString, $uuid->toString()); } - public function testGettersReturnValueFromFeatureSet() + public function testGettersReturnValueFromFeatureSet(): void { $codec = $this->getMockBuilder(CodecInterface::class)->getMock(); $nodeProvider = $this->getMockBuilder(NodeProviderInterface::class)->getMock(); @@ -81,22 +82,26 @@ class UuidFactoryTest extends TestCase ); } - public function testSettersSetValueForGetters() + public function testSettersSetValueForGetters(): void { $uuidFactory = new UuidFactory(); + /** @var MockObject & CodecInterface $codec */ $codec = $this->getMockBuilder(CodecInterface::class)->getMock(); $uuidFactory->setCodec($codec); $this->assertEquals($codec, $uuidFactory->getCodec()); + /** @var MockObject & TimeGeneratorInterface $timeGenerator */ $timeGenerator = $this->getMockBuilder(TimeGeneratorInterface::class)->getMock(); $uuidFactory->setTimeGenerator($timeGenerator); $this->assertEquals($timeGenerator, $uuidFactory->getTimeGenerator()); + /** @var MockObject & NumberConverterInterface $numberConverter */ $numberConverter = $this->getMockBuilder(NumberConverterInterface::class)->getMock(); $uuidFactory->setNumberConverter($numberConverter); $this->assertEquals($numberConverter, $uuidFactory->getNumberConverter()); + /** @var MockObject & UuidBuilderInterface $uuidBuilder */ $uuidBuilder = $this->getMockBuilder(UuidBuilderInterface::class)->getMock(); $uuidFactory->setUuidBuilder($uuidBuilder); $this->assertEquals($uuidBuilder, $uuidFactory->getUuidBuilder()); diff --git a/tests/UuidTest.php b/tests/UuidTest.php index 121e069..189744e 100644 --- a/tests/UuidTest.php +++ b/tests/UuidTest.php @@ -30,9 +30,7 @@ class UuidTest extends TestCase Uuid::setFactory(new UuidFactory()); } - /** - */ - public function testFromString() + public function testFromString(): void { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertInstanceOf(Uuid::class, $uuid); @@ -42,7 +40,7 @@ class UuidTest extends TestCase /** * Tests that UUID and GUID's have the same textual representation but not the same binary representation. */ - public function testFromGuidStringOnLittleEndianHost() + public function testFromGuidStringOnLittleEndianHost(): void { $this->skipIfBigEndianHost(); @@ -64,7 +62,7 @@ class UuidTest extends TestCase * Tests that UUID and GUID's have the same textual representation and the same binary representation. * This test is only valid on big endian hosts. */ - public function testFromGuidStringOnBigEndianHost() + public function testFromGuidStringOnBigEndianHost(): void { $this->skipIfLittleEndianHost(); @@ -82,14 +80,14 @@ class UuidTest extends TestCase $this->assertEquals(bin2hex($uuid->getBytes()), bin2hex($guid->getBytes())); } - public function testFromStringWithCurlyBraces() + public function testFromStringWithCurlyBraces(): void { $uuid = Uuid::fromString('{ff6f8cb0-c57d-11e1-9b21-0800200c9a66}'); $this->assertInstanceOf(Uuid::class, $uuid); $this->assertEquals('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->toString()); } - public function testFromStringWithInvalidUuidString() + public function testFromStringWithInvalidUuidString(): void { $this->expectException(InvalidUuidStringException::class); $this->expectExceptionMessage('Invalid UUID string:'); @@ -97,7 +95,7 @@ class UuidTest extends TestCase $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21'); } - public function testFromStringWithTrailingNewLine() + public function testFromStringWithTrailingNewLine(): void { $this->expectException(InvalidUuidStringException::class); $this->expectExceptionMessage('Invalid UUID string:'); @@ -105,81 +103,63 @@ class UuidTest extends TestCase Uuid::fromString("d0d5f586-21d1-470c-8088-55c8857728dc\n"); } - /** - */ - public function testFromStringWithUrn() + public function testFromStringWithUrn(): void { $uuid = Uuid::fromString('urn:uuid:ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertInstanceOf(Uuid::class, $uuid); $this->assertEquals('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->toString()); } - /** - */ - public function testGetBytes() + public function testGetBytes(): void { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals(16, \strlen($uuid->getBytes())); $this->assertEquals('/2+MsMV9EeGbIQgAIAyaZg==', base64_encode($uuid->getBytes())); } - /** - */ - public function testGetClockSeqHiAndReserved() + public function testGetClockSeqHiAndReserved(): void { /** @var Uuid $uuid */ $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals(155, $uuid->getClockSeqHiAndReserved()); } - /** - */ - public function testGetClockSeqHiAndReservedHex() + public function testGetClockSeqHiAndReservedHex(): void { /** @var Uuid $uuid */ $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals('9b', $uuid->getClockSeqHiAndReservedHex()); } - /** - */ - public function testGetClockSeqLow() + public function testGetClockSeqLow(): void { /** @var Uuid $uuid */ $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals(33, $uuid->getClockSeqLow()); } - /** - */ - public function testGetClockSeqLowHex() + public function testGetClockSeqLowHex(): void { /** @var Uuid $uuid */ $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals('21', $uuid->getClockSeqLowHex()); } - /** - */ - public function testGetClockSequence() + public function testGetClockSequence(): void { /** @var Uuid $uuid */ $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals(6945, $uuid->getClockSequence()); } - /** - */ - public function testGetClockSequenceHex() + public function testGetClockSequenceHex(): void { /** @var Uuid $uuid */ $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals('1b21', $uuid->getClockSequenceHex()); } - /** - */ - public function testGetDateTime() + public function testGetDateTime(): void { // Check a recent date $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); @@ -202,9 +182,7 @@ class UuidTest extends TestCase $this->assertEquals('1582-10-15T00:00:00+00:00', $uuid->getDateTime()->format('c')); } - /** - */ - public function testGetDateTime32BitMoontoast() + public function testGetDateTime32BitMoontoast(): void { $this->skipIfNoMoontoastMath(); Uuid::setFactory(new UuidFactory(new FeatureSet(false, true, false, false, false, true))); @@ -230,9 +208,7 @@ class UuidTest extends TestCase $this->assertEquals('1582-10-15T00:00:00+00:00', $uuid->getDateTime()->format('c')); } - /** - */ - public function testGetDateTime32BitGmp() + public function testGetDateTime32BitGmp(): void { $this->skipIfNoGmp(); Uuid::setFactory(new UuidFactory(new FeatureSet(false, true))); @@ -258,7 +234,7 @@ class UuidTest extends TestCase $this->assertEquals('1582-10-15T00:00:00+00:00', $uuid->getDateTime()->format('c')); } - public function testGetDateTimeThrownException() + public function testGetDateTimeThrownException(): void { Uuid::setFactory(new UuidFactory(new FeatureSet(false, true, true, false, true, true))); @@ -272,7 +248,7 @@ class UuidTest extends TestCase $date = $uuid->getDateTime(); } - public function testGetDateTimeFromNonVersion1Uuid() + public function testGetDateTimeFromNonVersion1Uuid(): void { // Using a version 4 UUID to test $uuid = Uuid::fromString('bf17b594-41f2-474f-bf70-4c90220f75de'); @@ -283,9 +259,7 @@ class UuidTest extends TestCase $date = $uuid->getDateTime(); } - /** - */ - public function testGetFields() + public function testGetFields(): void { $this->skip64BitTest(); @@ -304,7 +278,7 @@ class UuidTest extends TestCase $this->assertEquals($fields, $uuid->getFields()); } - public function testGetFields32Bit() + public function testGetFields32Bit(): void { Uuid::setFactory(new UuidFactory(new FeatureSet(false, true))); @@ -316,9 +290,7 @@ class UuidTest extends TestCase $fields = $uuid->getFields(); } - /** - */ - public function testGetFieldsHex() + public function testGetFieldsHex(): void { $fields = [ 'time_low' => 'ff6f8cb0', @@ -334,9 +306,7 @@ class UuidTest extends TestCase $this->assertEquals($fields, $uuid->getFieldsHex()); } - /** - */ - public function testGetLeastSignificantBitsMoontoast() + public function testGetLeastSignificantBitsMoontoast(): void { $this->skipIfNoMoontoastMath(); Uuid::setFactory(new UuidFactory(new FeatureSet(false, false, false, false, false, true))); @@ -347,9 +317,7 @@ class UuidTest extends TestCase $this->assertEquals('11178224546741000806', $uuid->getLeastSignificantBits()->getValue()); } - /** - */ - public function testGetLeastSignificantBitsGmp() + public function testGetLeastSignificantBitsGmp(): void { $this->skipIfNoGmp(); @@ -359,7 +327,7 @@ class UuidTest extends TestCase $this->assertEquals('11178224546741000806', $uuid->getLeastSignificantBits()); } - public function testGetLeastSignificantBitsException() + public function testGetLeastSignificantBitsException(): void { Uuid::setFactory(new UuidFactory(new FeatureSet(false, false, true, false, false, true))); @@ -371,17 +339,13 @@ class UuidTest extends TestCase $bn = $uuid->getLeastSignificantBits(); } - /** - */ - public function testGetLeastSignificantBitsHex() + public function testGetLeastSignificantBitsHex(): void { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals('9b210800200c9a66', $uuid->getLeastSignificantBitsHex()); } - /** - */ - public function testGetMostSignificantBitsMoontoast() + public function testGetMostSignificantBitsMoontoast(): void { $this->skipIfNoMoontoastMath(); Uuid::setFactory(new UuidFactory(new FeatureSet(false, false, false, false, false, true))); @@ -392,9 +356,7 @@ class UuidTest extends TestCase $this->assertEquals('18406084892941947361', $uuid->getMostSignificantBits()->getValue()); } - /** - */ - public function testGetMostSignificantBitsGmp() + public function testGetMostSignificantBitsGmp(): void { $this->skipIfNoGmp(); @@ -404,7 +366,7 @@ class UuidTest extends TestCase $this->assertEquals('18406084892941947361', $uuid->getMostSignificantBits()); } - public function testGetMostSignificantBitsException() + public function testGetMostSignificantBitsException(): void { Uuid::setFactory(new UuidFactory(new FeatureSet(false, false, true, false, false, true))); @@ -416,17 +378,13 @@ class UuidTest extends TestCase $bn = $uuid->getMostSignificantBits(); } - /** - */ - public function testGetMostSignificantBitsHex() + public function testGetMostSignificantBitsHex(): void { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals('ff6f8cb0c57d11e1', $uuid->getMostSignificantBitsHex()); } - /** - */ - public function testGetNode() + public function testGetNode(): void { $this->skip64BitTest(); @@ -435,7 +393,7 @@ class UuidTest extends TestCase $this->assertEquals(8796630719078, $uuid->getNode()); } - public function testGetNode32Bit() + public function testGetNode32Bit(): void { Uuid::setFactory(new UuidFactory(new FeatureSet(false, true))); @@ -447,34 +405,26 @@ class UuidTest extends TestCase $node = $uuid->getNode(); } - /** - */ - public function testGetNodeHex() + public function testGetNodeHex(): void { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals('0800200c9a66', $uuid->getNodeHex()); } - /** - */ - public function testGetTimeHiAndVersion() + public function testGetTimeHiAndVersion(): void { /** @var Uuid $uuid */ $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals(4577, $uuid->getTimeHiAndVersion()); } - /** - */ - public function testGetTimeHiAndVersionHex() + public function testGetTimeHiAndVersionHex(): void { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals('11e1', $uuid->getTimeHiAndVersionHex()); } - /** - */ - public function testGetTimeLow() + public function testGetTimeLow(): void { $this->skip64BitTest(); @@ -483,7 +433,7 @@ class UuidTest extends TestCase $this->assertEquals(4285500592, $uuid->getTimeLow()); } - public function testGetTimeLow32Bit() + public function testGetTimeLow32Bit(): void { Uuid::setFactory(new UuidFactory(new FeatureSet(false, true))); @@ -495,34 +445,26 @@ class UuidTest extends TestCase $timeLow = $uuid->getTimeLow(); } - /** - */ - public function testGetTimeLowHex() + public function testGetTimeLowHex(): void { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals('ff6f8cb0', $uuid->getTimeLowHex()); } - /** - */ - public function testGetTimeMid() + public function testGetTimeMid(): void { /** @var Uuid $uuid */ $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals(50557, $uuid->getTimeMid()); } - /** - */ - public function testGetTimeMidHex() + public function testGetTimeMidHex(): void { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals('c57d', $uuid->getTimeMidHex()); } - /** - */ - public function testGetTimestamp() + public function testGetTimestamp(): void { $this->skip64BitTest(); @@ -537,9 +479,7 @@ class UuidTest extends TestCase $this->assertEquals(1460440000000, $uuid->getTimestamp()); } - /** - */ - public function testGetTimestampHex() + public function testGetTimestampHex(): void { // Check for a recent date $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); @@ -550,7 +490,7 @@ class UuidTest extends TestCase $this->assertEquals('00001540901e600', $uuid->getTimestampHex()); } - public function testGetTimestampFromNonVersion1Uuid() + public function testGetTimestampFromNonVersion1Uuid(): void { // Using a version 4 UUID to test /** @var Uuid $uuid */ @@ -562,7 +502,7 @@ class UuidTest extends TestCase $ts = $uuid->getTimestamp(); } - public function testGetTimestampHexFromNonVersion1Uuid() + public function testGetTimestampHexFromNonVersion1Uuid(): void { // Using a version 4 UUID to test $uuid = Uuid::fromString('bf17b594-41f2-474f-bf70-4c90220f75de'); @@ -573,7 +513,7 @@ class UuidTest extends TestCase $ts = $uuid->getTimestampHex(); } - public function testGetTimestamp32Bit() + public function testGetTimestamp32Bit(): void { Uuid::setFactory(new UuidFactory(new FeatureSet(false, true))); @@ -585,17 +525,13 @@ class UuidTest extends TestCase $ts = $uuid->getTimestamp(); } - /** - */ - public function testGetUrn() + public function testGetUrn(): void { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals('urn:uuid:ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->getUrn()); } - /** - */ - public function testGetVariantForReservedNcs() + public function testGetVariantForReservedNcs(): void { $uuid1 = Uuid::fromString('ff6f8cb0-c57d-11e1-0b21-0800200c9a66'); $this->assertEquals(0, $uuid1->getVariant()); @@ -622,9 +558,7 @@ class UuidTest extends TestCase $this->assertEquals(0, $uuid8->getVariant()); } - /** - */ - public function testGetVariantForRfc4122() + public function testGetVariantForRfc4122(): void { $uuid1 = Uuid::fromString('ff6f8cb0-c57d-11e1-8b21-0800200c9a66'); $this->assertEquals(2, $uuid1->getVariant()); @@ -639,9 +573,7 @@ class UuidTest extends TestCase $this->assertEquals(2, $uuid4->getVariant()); } - /** - */ - public function testGetVariantForReservedMicrosoft() + public function testGetVariantForReservedMicrosoft(): void { $uuid1 = Uuid::fromString('ff6f8cb0-c57d-11e1-cb21-0800200c9a66'); $this->assertEquals(6, $uuid1->getVariant()); @@ -650,9 +582,7 @@ class UuidTest extends TestCase $this->assertEquals(6, $uuid2->getVariant()); } - /** - */ - public function testGetVariantForReservedFuture() + public function testGetVariantForReservedFuture(): void { $uuid1 = Uuid::fromString('ff6f8cb0-c57d-11e1-eb21-0800200c9a66'); $this->assertEquals(7, $uuid1->getVariant()); @@ -661,49 +591,37 @@ class UuidTest extends TestCase $this->assertEquals(7, $uuid2->getVariant()); } - /** - */ - public function testGetVersionForVersion1() + public function testGetVersionForVersion1(): void { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals(1, $uuid->getVersion()); } - /** - */ - public function testGetVersionForVersion2() + public function testGetVersionForVersion2(): void { $uuid = Uuid::fromString('6fa459ea-ee8a-2ca4-894e-db77e160355e'); $this->assertEquals(2, $uuid->getVersion()); } - /** - */ - public function testGetVersionForVersion3() + public function testGetVersionForVersion3(): void { $uuid = Uuid::fromString('6fa459ea-ee8a-3ca4-894e-db77e160355e'); $this->assertEquals(3, $uuid->getVersion()); } - /** - */ - public function testGetVersionForVersion4() + public function testGetVersionForVersion4(): void { $uuid = Uuid::fromString('6fabf0bc-603a-42f2-925b-d9f779bd0032'); $this->assertEquals(4, $uuid->getVersion()); } - /** - */ - public function testGetVersionForVersion5() + public function testGetVersionForVersion5(): void { $uuid = Uuid::fromString('886313e1-3b8a-5372-9b90-0c9aee199e5d'); $this->assertEquals(5, $uuid->getVersion()); } - /** - */ - public function testToString() + public function testToString(): void { // Check with a recent date $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); @@ -716,9 +634,7 @@ class UuidTest extends TestCase $this->assertEquals('0901e600-0154-1000-9b21-0800200c9a66', sprintf('%s', (string) $uuid)); } - /** - */ - public function testUuid1() + public function testUuid1(): void { $uuid = Uuid::uuid1(); $this->assertInstanceOf(Uuid::class, $uuid); @@ -727,14 +643,12 @@ class UuidTest extends TestCase $this->assertEquals(1, $uuid->getVersion()); } - /** - */ - public function testUuid1WithNodeAndClockSequence() + public function testUuid1WithNodeAndClockSequence(): void { $this->skip64BitTest(); /** @var Uuid $uuid */ - $uuid = Uuid::uuid1(0x0800200c9a66, 0x1669); + $uuid = Uuid::uuid1((int) 0x0800200c9a66, 0x1669); $this->assertInstanceOf(Uuid::class, $uuid); $this->assertInstanceOf(\DateTimeInterface::class, $uuid->getDateTime()); $this->assertEquals(2, $uuid->getVariant()); @@ -744,9 +658,7 @@ class UuidTest extends TestCase $this->assertEquals('9669-0800200c9a66', substr($uuid->toString(), 19)); } - /** - */ - public function testUuid1WithHexadecimalNode() + public function testUuid1WithHexadecimalNode(): void { /** @var Uuid $uuid */ $uuid = Uuid::uuid1('7160355e'); @@ -762,9 +674,7 @@ class UuidTest extends TestCase } } - /** - */ - public function testUuid1WithMixedCaseHexadecimalNode() + public function testUuid1WithMixedCaseHexadecimalNode(): void { /** @var Uuid $uuid */ $uuid = Uuid::uuid1('71B0aD5e'); @@ -780,9 +690,7 @@ class UuidTest extends TestCase } } - /** - */ - public function testUuid1WithNodeAndClockSequence32Bit() + public function testUuid1WithNodeAndClockSequence32Bit(): void { /** @var Uuid $uuid */ $uuid = Uuid::uuid1(0x7fffffff, 0x1669); @@ -799,7 +707,7 @@ class UuidTest extends TestCase } } - public function testUuid1WithOutOfBoundsNode() + public function testUuid1WithOutOfBoundsNode(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid node value'); @@ -807,7 +715,7 @@ class UuidTest extends TestCase $uuid = Uuid::uuid1('9223372036854775808'); } - public function testUuid1WithNonHexadecimalNode() + public function testUuid1WithNonHexadecimalNode(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid node value'); @@ -815,7 +723,7 @@ class UuidTest extends TestCase $uuid = Uuid::uuid1('db77e160355g'); } - public function testUuid1WithNon48bitNumber() + public function testUuid1WithNon48bitNumber(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid node value'); @@ -823,7 +731,7 @@ class UuidTest extends TestCase $uuid = Uuid::uuid1('db77e160355ef'); } - public function testUuid1WithRandomNode() + public function testUuid1WithRandomNode(): void { Uuid::setFactory(new UuidFactory(new FeatureSet(false, false, false, true))); @@ -840,7 +748,7 @@ class UuidTest extends TestCase * @see http://docs.python.org/library/uuid.html * */ - public function testUuid3WithNamespaceAsUuidObject() + public function testUuid3WithNamespaceAsUuidObject(): void { $nsUuid = Uuid::fromString(Uuid::NAMESPACE_DNS); $uuid = Uuid::uuid3($nsUuid, 'python.org'); @@ -855,7 +763,7 @@ class UuidTest extends TestCase * @see http://docs.python.org/library/uuid.html * */ - public function testUuid3WithNamespaceAsUuidString() + public function testUuid3WithNamespaceAsUuidString(): void { $uuid = Uuid::uuid3(Uuid::NAMESPACE_DNS, 'python.org'); $this->assertEquals('6fa459ea-ee8a-3ca4-894e-db77e160355e', $uuid->toString()); @@ -870,7 +778,7 @@ class UuidTest extends TestCase * http://hg.python.org/cpython/file/2f4c4db9aee5/Lib/test/test_uuid.py * */ - public function testUuid3WithKnownUuids() + public function testUuid3WithKnownUuids(): void { $uuids = [ '6fa459ea-ee8a-3ca4-894e-db77e160355e' => Uuid::uuid3(Uuid::NAMESPACE_DNS, 'python.org'), @@ -887,9 +795,7 @@ class UuidTest extends TestCase } } - /** - */ - public function testUuid4() + public function testUuid4(): void { $uuid = Uuid::uuid4(); $this->assertInstanceOf(Uuid::class, $uuid); @@ -900,7 +806,7 @@ class UuidTest extends TestCase /** * Tests that generated UUID's using timestamp last COMB are sequential */ - public function testUuid4TimestampLastComb() + public function testUuid4TimestampLastComb(): void { $mock = $this->getMockBuilder(RandomGeneratorInterface::class)->getMock(); $mock->expects($this->any()) @@ -931,7 +837,7 @@ class UuidTest extends TestCase /** * Tests that generated UUID's using timestamp first COMB are sequential */ - public function testUuid4TimestampFirstComb() + public function testUuid4TimestampFirstComb(): void { $mock = $this->getMockBuilder(RandomGeneratorInterface::class)->getMock(); $mock->expects($this->any()) @@ -962,7 +868,7 @@ class UuidTest extends TestCase /** * Test that COMB UUID's have a version 4 flag */ - public function testUuid4CombVersion() + public function testUuid4CombVersion(): void { $factory = new UuidFactory(); $generator = new CombGenerator( @@ -983,7 +889,7 @@ class UuidTest extends TestCase * @see http://docs.python.org/library/uuid.html * */ - public function testUuid5WithNamespaceAsUuidObject() + public function testUuid5WithNamespaceAsUuidObject(): void { $nsUuid = Uuid::fromString(Uuid::NAMESPACE_DNS); $uuid = Uuid::uuid5($nsUuid, 'python.org'); @@ -998,7 +904,7 @@ class UuidTest extends TestCase * @see http://docs.python.org/library/uuid.html * */ - public function testUuid5WithNamespaceAsUuidString() + public function testUuid5WithNamespaceAsUuidString(): void { $uuid = Uuid::uuid5(Uuid::NAMESPACE_DNS, 'python.org'); $this->assertEquals('886313e1-3b8a-5372-9b90-0c9aee199e5d', $uuid->toString()); @@ -1013,7 +919,7 @@ class UuidTest extends TestCase * http://hg.python.org/cpython/file/2f4c4db9aee5/Lib/test/test_uuid.py * */ - public function testUuid5WithKnownUuids() + public function testUuid5WithKnownUuids(): void { $uuids = [ '886313e1-3b8a-5372-9b90-0c9aee199e5d' => Uuid::uuid5(Uuid::NAMESPACE_DNS, 'python.org'), @@ -1030,9 +936,7 @@ class UuidTest extends TestCase } } - /** - */ - public function testCompareTo() + public function testCompareTo(): void { // $uuid1 and $uuid2 are identical $uuid1 = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); @@ -1058,7 +962,7 @@ class UuidTest extends TestCase $this->assertEquals(1, $uuid3->compareTo($uuid5)); } - public function testCompareToReturnsZeroWhenDifferentCases() + public function testCompareToReturnsZeroWhenDifferentCases(): void { $uuidString = 'ff6f8cb0-c57d-11e1-9b21-0800200c9a66'; // $uuid1 and $uuid2 are identical @@ -1069,7 +973,7 @@ class UuidTest extends TestCase $this->assertEquals(0, $uuid2->compareTo($uuid1)); } - public function testEqualsReturnsTrueWhenDifferentCases() + public function testEqualsReturnsTrueWhenDifferentCases(): void { $uuidString = 'ff6f8cb0-c57d-11e1-9b21-0800200c9a66'; // $uuid1 and $uuid2 are identical @@ -1080,9 +984,7 @@ class UuidTest extends TestCase $this->assertTrue($uuid2->equals($uuid1)); } - /** - */ - public function testEquals() + public function testEquals(): void { $uuid1 = Uuid::uuid5(Uuid::NAMESPACE_DNS, 'python.org'); $uuid2 = Uuid::uuid5(Uuid::NAMESPACE_DNS, 'python.org'); @@ -1093,9 +995,7 @@ class UuidTest extends TestCase $this->assertFalse($uuid1->equals(new stdClass())); } - /** - */ - public function testCalculateUuidTime() + public function testCalculateUuidTime(): void { $timeOfDay = new FixedTimeProvider([ 'sec' => 1348845514, @@ -1135,9 +1035,7 @@ class UuidTest extends TestCase $this->assertEquals('11e2', $uuidC->getTimeHiAndVersionHex()); } - /** - */ - public function testCalculateUuidTimeForce32BitMoontoastPath() + public function testCalculateUuidTimeForce32BitMoontoastPath(): void { $this->skipIfNoMoontoastMath(); @@ -1180,9 +1078,7 @@ class UuidTest extends TestCase $this->assertEquals('11e2', $uuidC->getTimeHiAndVersionHex()); } - /** - */ - public function testCalculateUuidTimeForce32BitGmpPath() + public function testCalculateUuidTimeForce32BitGmpPath(): void { $this->skipIfNoGmp(); @@ -1225,15 +1121,13 @@ class UuidTest extends TestCase $this->assertEquals('11e2', $uuidC->getTimeHiAndVersionHex()); } - /** - */ - public function testCalculateUuidTimeUpperLowerBounds64Bit() + public function testCalculateUuidTimeUpperLowerBounds64Bit(): void { $this->skip64BitTest(); // 5235-03-31T21:20:59+00:00 $timeOfDay = new FixedTimeProvider([ - 'sec' => 103072857659, + 'sec' => (int) 103072857659, 'usec' => 999999, 'minuteswest' => 0, 'dsttime' => 0, @@ -1252,7 +1146,7 @@ class UuidTest extends TestCase // 1582-10-15T00:00:00+00:00 $timeOfDay = new FixedTimeProvider([ - 'sec' => -12219292800, + 'sec' => (int) -12219292800, 'usec' => 0, 'minuteswest' => 0, 'dsttime' => 0, @@ -1274,7 +1168,7 @@ class UuidTest extends TestCase * those generated by the 64-bit path, given the same 64-bit time values. * */ - public function testCalculateUuidTimeUpperLowerBounds64BitThrough32BitGmpPath() + public function testCalculateUuidTimeUpperLowerBounds64BitThrough32BitGmpPath(): void { $this->skipIfNoGmp(); $this->skip64BitTest(); @@ -1283,7 +1177,7 @@ class UuidTest extends TestCase // 5235-03-31T21:20:59+00:00 $timeOfDay = new FixedTimeProvider([ - 'sec' => 103072857659, + 'sec' => (int) 103072857659, 'usec' => 999999, 'minuteswest' => 0, 'dsttime' => 0, @@ -1302,7 +1196,7 @@ class UuidTest extends TestCase // 1582-10-15T00:00:00+00:00 $timeOfDay = new FixedTimeProvider([ - 'sec' => -12219292800, + 'sec' => (int) -12219292800, 'usec' => 0, 'minuteswest' => 0, 'dsttime' => 0, @@ -1325,7 +1219,7 @@ class UuidTest extends TestCase * those generated by the 64-bit path, given the same 64-bit time values. * */ - public function testCalculateUuidTimeUpperLowerBounds64BitThrough32BitMoontoastPath() + public function testCalculateUuidTimeUpperLowerBounds64BitThrough32BitMoontoastPath(): void { $this->skipIfNoMoontoastMath(); $this->skip64BitTest(); @@ -1334,7 +1228,7 @@ class UuidTest extends TestCase // 5235-03-31T21:20:59+00:00 $timeOfDay = new FixedTimeProvider(array( - 'sec' => 103072857659, + 'sec' => (int) 103072857659, 'usec' => 999999, 'minuteswest' => 0, 'dsttime' => 0, @@ -1353,7 +1247,7 @@ class UuidTest extends TestCase // 1582-10-15T00:00:00+00:00 $timeOfDay = new FixedTimeProvider(array( - 'sec' => -12219292800, + 'sec' => (int) -12219292800, 'usec' => 0, 'minuteswest' => 0, 'dsttime' => 0, @@ -1371,9 +1265,7 @@ class UuidTest extends TestCase $this->assertEquals('1000', $uuidB->getTimeHiAndVersionHex()); } - /** - */ - public function testCalculateUuidTimeUpperLowerBounds32BitGmp() + public function testCalculateUuidTimeUpperLowerBounds32BitGmp(): void { $this->skipIfNoGmp(); @@ -1417,9 +1309,7 @@ class UuidTest extends TestCase $this->assertEquals('1165', $uuidB->getTimeHiAndVersionHex()); } - /** - */ - public function testCalculateUuidTimeUpperLowerBounds32BitMoontoast() + public function testCalculateUuidTimeUpperLowerBounds32BitMoontoast(): void { $this->skipIfNoMoontoastMath(); @@ -1468,7 +1358,7 @@ class UuidTest extends TestCase * those generated by the 32-bit path, given the same 32-bit time values. * */ - public function testCalculateUuidTimeUpperLowerBounds32BitThrough64BitPath() + public function testCalculateUuidTimeUpperLowerBounds32BitThrough64BitPath(): void { $this->skip64BitTest(); @@ -1515,7 +1405,7 @@ class UuidTest extends TestCase * Iterates over a 3600-second period and tests to ensure that, for each * second in the period, the 32-bit-Moontoast and 64-bit versions of the UUID match */ - public function test32BitMoontoastMatch64BitForOneHourPeriod() + public function test32BitMoontoastMatch64BitForOneHourPeriod(): void { $this->skipIfNoMoontoastMath(); $this->skip64BitTest(); @@ -1568,7 +1458,7 @@ class UuidTest extends TestCase * Iterates over a 3600-second period and tests to ensure that, for each * second in the period, the 32-bit-GMP and 64-bit versions of the UUID match */ - public function test32BitGmpMatch64BitForOneHourPeriod() + public function test32BitGmpMatch64BitForOneHourPeriod(): void { $this->skipIfNoGmp(); $this->skip64BitTest(); @@ -1617,7 +1507,7 @@ class UuidTest extends TestCase } } - public function testCalculateUuidTimeThrownException() + public function testCalculateUuidTimeThrownException(): void { Uuid::setFactory(new UuidFactory(new FeatureSet(false, true, true, false, false, true))); @@ -1629,7 +1519,7 @@ class UuidTest extends TestCase /** * This method should respond to the result of the factory */ - public function testIsValid() + public function testIsValid(): void { $argument = uniqid('passed argument '); @@ -1647,17 +1537,13 @@ class UuidTest extends TestCase $factory->setValidator(new Validator); } - /** - */ - public function testUsingNilAsValidUuid() + public function testUsingNilAsValidUuid(): void { $this->assertInstanceOf(Uuid::class, Uuid::uuid3(Uuid::NIL, 'randomtext')); $this->assertInstanceOf(Uuid::class, Uuid::uuid5(Uuid::NIL, 'randomtext')); } - /** - */ - public function testFromBytes() + public function testFromBytes(): void { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $bytes = $uuid->getBytes(); @@ -1667,7 +1553,7 @@ class UuidTest extends TestCase $this->assertTrue($uuid->equals($fromBytesUuid)); } - public function testFromGuidBytesOnLittleEndianHost() + public function testFromGuidBytesOnLittleEndianHost(): void { $this->skipIfBigEndianHost(); @@ -1692,7 +1578,7 @@ class UuidTest extends TestCase $this->assertEquals($guid->toString(), $parsedGuid->toString()); } - public function testFromGuidBytesOnBigEndianHost() + public function testFromGuidBytesOnBigEndianHost(): void { $this->skipIfLittleEndianHost(); @@ -1715,23 +1601,21 @@ class UuidTest extends TestCase $this->assertEquals($guid->toString(), $parsedGuid->toString()); } - public function testFromBytesArgumentTooShort() + public function testFromBytesArgumentTooShort(): void { $this->expectException(InvalidArgumentException::class); Uuid::fromBytes('thisisveryshort'); } - public function testFromBytesArgumentTooLong() + public function testFromBytesArgumentTooLong(): void { $this->expectException(InvalidArgumentException::class); Uuid::fromBytes('thisisabittoolong'); } - /** - */ - public function testFromIntegerMoontoast() + public function testFromIntegerMoontoast(): void { $this->skipIfNoMoontoastMath(); Uuid::setFactory(new UuidFactory(new FeatureSet(false, false, false, false, false, true))); @@ -1744,9 +1628,7 @@ class UuidTest extends TestCase $this->assertTrue($uuid->equals($fromIntegerUuid)); } - /** - */ - public function testFromIntegerStringMoontoast() + public function testFromIntegerStringMoontoast(): void { $this->skipIfNoMoontoastMath(); Uuid::setFactory(new UuidFactory(new FeatureSet(false, false, false, false, false, true))); @@ -1759,9 +1641,7 @@ class UuidTest extends TestCase $this->assertTrue($uuid->equals($fromIntegerUuid)); } - /** - */ - public function testFromIntegerGmp() + public function testFromIntegerGmp(): void { $this->skipIfNoGmp(); @@ -1773,7 +1653,7 @@ class UuidTest extends TestCase $this->assertTrue($uuid->equals($fromIntegerUuid)); } - public function testFromIntegerException() + public function testFromIntegerException(): void { Uuid::setFactory(new UuidFactory(new FeatureSet(false, false, true, false, false, true))); @@ -1792,7 +1672,7 @@ class UuidTest extends TestCase * http://hg.python.org/cpython/file/2f4c4db9aee5/Lib/test/test_uuid.py * */ - public function testUuidPassesPythonTests() + public function testUuidPassesPythonTests(): void { // This array is taken directly from the Python tests, more or less $tests = [ @@ -2112,7 +1992,7 @@ class UuidTest extends TestCase } } - public function testGetInteger() + public function testGetInteger(): void { Uuid::setFactory(new UuidFactory(new FeatureSet(false, false, true, false, false, true))); @@ -2126,14 +2006,14 @@ class UuidTest extends TestCase /** * @covers Ramsey\Uuid\Uuid::jsonSerialize */ - public function testJsonSerialize() + public function testJsonSerialize(): void { $uuid = Uuid::uuid1(); $this->assertEquals('"' . $uuid->toString() . '"', json_encode($uuid)); } - public function testSerialize() + public function testSerialize(): void { $uuid = Uuid::uuid4(); $serialized = serialize($uuid); @@ -2141,7 +2021,7 @@ class UuidTest extends TestCase $this->assertTrue($uuid->equals($unserializedUuid)); } - public function testUuid3WithEmptyNamespace() + public function testUuid3WithEmptyNamespace(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid UUID string:'); @@ -2149,21 +2029,21 @@ class UuidTest extends TestCase $uuid = Uuid::uuid3('', ''); } - public function testUuid3WithEmptyName() + public function testUuid3WithEmptyName(): void { $uuid = Uuid::uuid3(Uuid::NIL, ''); $this->assertEquals('4ae71336-e44b-39bf-b9d2-752e234818a5', $uuid->toString()); } - public function testUuid3WithZeroName() + public function testUuid3WithZeroName(): void { $uuid = Uuid::uuid3(Uuid::NIL, '0'); $this->assertEquals('19826852-5007-3022-a72a-212f66e9fac3', $uuid->toString()); } - public function testUuid5WithEmptyNamespace() + public function testUuid5WithEmptyNamespace(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid UUID string:'); @@ -2171,14 +2051,14 @@ class UuidTest extends TestCase $uuid = Uuid::uuid5('', ''); } - public function testUuid5WithEmptyName() + public function testUuid5WithEmptyName(): void { $uuid = Uuid::uuid5(Uuid::NIL, ''); $this->assertEquals('e129f27c-5103-5c5c-844b-cdf0a15e160d', $uuid->toString()); } - public function testUuid5WithZeroName() + public function testUuid5WithZeroName(): void { $uuid = Uuid::uuid5(Uuid::NIL, '0'); @@ -2188,7 +2068,7 @@ class UuidTest extends TestCase /** * @depends testGetVersionForVersion1 */ - public function testUuidVersionConstantForVersion1() + public function testUuidVersionConstantForVersion1(): void { $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertEquals($uuid->getVersion(), Uuid::UUID_TYPE_TIME); @@ -2197,7 +2077,7 @@ class UuidTest extends TestCase /** * @depends testGetVersionForVersion2 */ - public function testUuidVersionConstantForVersion2() + public function testUuidVersionConstantForVersion2(): void { $uuid = Uuid::fromString('6fa459ea-ee8a-2ca4-894e-db77e160355e'); $this->assertEquals($uuid->getVersion(), Uuid::UUID_TYPE_IDENTIFIER); @@ -2206,7 +2086,7 @@ class UuidTest extends TestCase /** * @depends testGetVersionForVersion3 */ - public function testUuidVersionConstantForVersion3() + public function testUuidVersionConstantForVersion3(): void { $uuid = Uuid::fromString('6fa459ea-ee8a-3ca4-894e-db77e160355e'); $this->assertEquals($uuid->getVersion(), Uuid::UUID_TYPE_HASH_MD5); @@ -2215,7 +2095,7 @@ class UuidTest extends TestCase /** * @depends testGetVersionForVersion4 */ - public function testUuidVersionConstantForVersion4() + public function testUuidVersionConstantForVersion4(): void { $uuid = Uuid::fromString('6fabf0bc-603a-42f2-925b-d9f779bd0032'); $this->assertEquals($uuid->getVersion(), Uuid::UUID_TYPE_RANDOM); @@ -2224,7 +2104,7 @@ class UuidTest extends TestCase /** * @depends testGetVersionForVersion5 */ - public function testUuidVersionConstantForVersion5() + public function testUuidVersionConstantForVersion5(): void { $uuid = Uuid::fromString('886313e1-3b8a-5372-9b90-0c9aee199e5d'); $this->assertEquals($uuid->getVersion(), Uuid::UUID_TYPE_HASH_SHA1); diff --git a/tests/Validator/ValidatorTest.php b/tests/Validator/ValidatorTest.php index e7fcce1..3a05093 100644 --- a/tests/Validator/ValidatorTest.php +++ b/tests/Validator/ValidatorTest.php @@ -2,108 +2,77 @@ namespace Ramsey\Uuid\Test\Validator; +use PHPUnit\Framework\MockObject\MockObject; use Ramsey\Uuid\Test\TestCase; +use Ramsey\Uuid\Validator\Validator; -/** - * @coversDefaultClass \Ramsey\Uuid\Validator\Validator - */ class ValidatorTest extends TestCase { + /** + * @var MockObject & Validator + */ private $validator = null; public function setUp(): void { // Disable calls to the constructor, but do not override any methods - $this->validator = $this->getMockBuilder('Ramsey\Uuid\Validator\Validator') + $this->validator = $this->getMockBuilder(Validator::class) ->disableOriginalConstructor() - ->setMethods(null) + ->onlyMethods([]) ->getMock(); } - /** - * @covers ::validate - */ - public function testValidateGoodVersion1() + public function testValidateGoodVersion1(): void { $this->assertTrue($this->validator->validate('ff6f8cb0-c57d-11e1-9b21-0800200c9a66')); } - /** - * @covers ::validate - */ - public function testValidateGoodVersion2() + public function testValidateGoodVersion2(): void { $this->assertTrue($this->validator->validate('ff6f8cb0-c57d-21e1-9b21-0800200c9a66')); } - /** - * @covers ::validate - */ - public function testValidateGoodVersion3() + public function testValidateGoodVersion3(): void { $this->assertTrue($this->validator->validate('ff6f8cb0-c57d-31e1-9b21-0800200c9a66')); } - /** - * @covers ::validate - */ - public function testValidateGoodVersion4() + public function testValidateGoodVersion4(): void { $this->assertTrue($this->validator->validate('ff6f8cb0-c57d-41e1-9b21-0800200c9a66')); } - /** - * @covers ::validate - */ - public function testValidateGoodVersion5() + public function testValidateGoodVersion5(): void { $this->assertTrue($this->validator->validate('ff6f8cb0-c57d-51e1-9b21-0800200c9a66')); } - /** - * @covers ::validate - */ - public function testValidateGoodUpperCase() + public function testValidateGoodUpperCase(): void { $this->assertTrue($this->validator->validate('FF6F8CB0-C57D-11E1-9B21-0800200C9A66')); } - /** - * @covers ::validate - */ - public function testValidateBadHex() + public function testValidateBadHex(): void { $this->assertFalse($this->validator->validate('zf6f8cb0-c57d-11e1-9b21-0800200c9a66')); } - /** - * @covers ::validate - */ - public function testValidateTooShort1() + public function testValidateTooShort1(): void { $this->assertFalse($this->validator->validate('3f6f8cb0-c57d-11e1-9b21-0800200c9a6')); } - /** - * @covers ::validate - */ - public function testValidateTooShort2() + public function testValidateTooShort2(): void { $this->assertFalse($this->validator->validate('af6f8cb-c57d-11e1-9b21-0800200c9a66')); } - /** - * @covers ::validate - */ - public function testValidateNoDashes() + public function testValidateNoDashes(): void { $this->assertFalse($this->validator->validate('af6f8cb0c57d11e19b210800200c9a66')); } - /** - * @covers ::validate - */ - public function testValidateTooLong() + public function testValidateTooLong(): void { $this->assertFalse($this->validator->validate('ff6f8cb0-c57da-51e1-9b21-0800200c9a66')); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9f95a84..90f337f 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,10 @@ init([ 'debug' => true,