mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-16 16:17:43 +03:00
Clean-up tests and use PHPStan max level for tests
This commit is contained in:
+1
-1
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Ramsey\Uuid\Test\Encoder;
|
||||
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
@@ -16,7 +17,7 @@ class TimestampFirstCombCodecTest extends TestCase
|
||||
private $codec;
|
||||
|
||||
/**
|
||||
* @var MockObject
|
||||
* @var MockObject & UuidBuilderInterface
|
||||
*/
|
||||
private $builderMock;
|
||||
|
||||
@@ -26,8 +27,9 @@ class TimestampFirstCombCodecTest extends TestCase
|
||||
$this->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'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
+12
-8
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Ramsey\Uuid\Test\Generator;
|
||||
|
||||
use Ramsey\Uuid\Generator\PeclUuidRandomGenerator;
|
||||
use AspectMock\Test as AspectMock;
|
||||
use Ramsey\Uuid\Generator\PeclUuidRandomGenerator;
|
||||
|
||||
/**
|
||||
* Class PeclUuidRandomGeneratorTest
|
||||
* @package Ramsey\Uuid\Test\Generator
|
||||
* @covers Ramsey\Uuid\Generator\PeclUuidRandomGenerator
|
||||
*/
|
||||
class PeclUuidRandomGeneratorTest extends PeclUuidTestCase
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $length = 10;
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testGenerateCreatesUuidUsingPeclUuidMethods()
|
||||
public function testGenerateCreatesUuidUsingPeclUuidMethods(): void
|
||||
{
|
||||
$create = AspectMock::func('Ramsey\Uuid\Generator', 'uuid_create', $this->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);
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Ramsey\Uuid\Test\Generator;
|
||||
|
||||
use Ramsey\Uuid\Generator\PeclUuidTimeGenerator;
|
||||
use AspectMock\Test as AspectMock;
|
||||
use Ramsey\Uuid\Generator\PeclUuidTimeGenerator;
|
||||
|
||||
/**
|
||||
* Class PeclUuidTimeGeneratorTest
|
||||
* @package Ramsey\Uuid\Test\Generator
|
||||
* @covers Ramsey\Uuid\Generator\PeclUuidTimeGenerator
|
||||
*/
|
||||
class PeclUuidTimeGeneratorTest extends PeclUuidTestCase
|
||||
{
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testGenerateCreatesUuidUsingPeclUuidMethods()
|
||||
public function testGenerateCreatesUuidUsingPeclUuidMethods(): void
|
||||
{
|
||||
$create = AspectMock::func('Ramsey\Uuid\Generator', 'uuid_create', $this->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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 /*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
+8
-8
@@ -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;
|
||||
}
|
||||
|
||||
+17
-12
@@ -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());
|
||||
|
||||
+124
-244
File diff suppressed because it is too large
Load Diff
@@ -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'));
|
||||
}
|
||||
|
||||
+6
-25
@@ -1,5 +1,10 @@
|
||||
<?php
|
||||
// @codingStandardsIgnoreFile
|
||||
|
||||
/**
|
||||
* Test bootstrap
|
||||
*
|
||||
* @codingStandardsIgnoreFile
|
||||
*/
|
||||
|
||||
error_reporting(E_ALL & ~E_DEPRECATED);
|
||||
|
||||
@@ -8,30 +13,6 @@ use AspectMock\Kernel;
|
||||
require_once __DIR__ . '/../vendor/autoload.php'; // composer autoload
|
||||
require_once __DIR__ . '/phpstan-bootstrap.php';
|
||||
|
||||
if (!function_exists('uuid_create')) {
|
||||
// Create stub of method so AspectMock can mock this function
|
||||
// if it doesn't exist in PHP.
|
||||
function uuid_create()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('uuid_parse')) {
|
||||
// Create stub of method so AspectMock can mock this function
|
||||
// if it doesn't exist in PHP.
|
||||
function uuid_parse()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined('UUID_TYPE_TIME')) {
|
||||
define('UUID_TYPE_TIME', 1);
|
||||
}
|
||||
|
||||
if (!defined('UUID_TYPE_RANDOM')) {
|
||||
define('UUID_TYPE_RANDOM', 4);
|
||||
}
|
||||
|
||||
$kernel = Kernel::getInstance();
|
||||
$kernel->init([
|
||||
'debug' => true,
|
||||
|
||||
Reference in New Issue
Block a user