From 26a02a93dbfabbd77f9db22e757423d4f0556af8 Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Thu, 9 Jan 2020 17:02:26 -0600 Subject: [PATCH] Restore ExpectedBehaviorTest as close to 3.x version as possible --- tests/ExpectedBehaviorTest.php | 160 +++++++++++++-------------------- 1 file changed, 62 insertions(+), 98 deletions(-) diff --git a/tests/ExpectedBehaviorTest.php b/tests/ExpectedBehaviorTest.php index 00ffbe5..2772ea9 100644 --- a/tests/ExpectedBehaviorTest.php +++ b/tests/ExpectedBehaviorTest.php @@ -1,37 +1,23 @@ assertInstanceOf(UuidInterface::class, $uuid); + $this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid); $this->assertIsInt($uuid->compareTo(Uuid::uuid1())); $this->assertNotSame(0, $uuid->compareTo(Uuid::uuid4())); $this->assertSame(0, $uuid->compareTo(clone $uuid)); $this->assertFalse($uuid->equals(new stdClass())); $this->assertTrue($uuid->equals(clone $uuid)); $this->assertIsString($uuid->getBytes()); - $this->assertInstanceOf(NumberConverterInterface::class, $uuid->getNumberConverter()); + $this->assertInstanceOf('Ramsey\Uuid\Converter\NumberConverterInterface', $uuid->getNumberConverter()); $this->assertIsString($uuid->getHex()); $this->assertIsArray($uuid->getFieldsHex()); $this->assertArrayHasKey('time_low', $uuid->getFieldsHex()); @@ -135,10 +121,7 @@ class ExpectedBehaviorTest extends TestCase $this->assertTrue(ctype_digit((string) $uuid->getInteger())); } - /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification - */ - public function provideStaticCreationMethods(): array + public function provideStaticCreationMethods() { return [ ['uuid1', []], @@ -155,25 +138,21 @@ class ExpectedBehaviorTest extends TestCase ]; } - public function testUuidVersion1MethodBehavior(): void + public function testUuidVersion1MethodBehavior() { - /** @var Uuid $uuid */ $uuid = Uuid::uuid1('00000fffffff', 0xffff); - $this->assertInstanceOf(DateTimeImmutable::class, $uuid->getDateTime()); + $this->assertInstanceOf('DateTimeInterface', $uuid->getDateTime()); $this->assertSame('00000fffffff', $uuid->getNodeHex()); $this->assertSame('3fff', $uuid->getClockSequenceHex()); $this->assertSame('16383', (string) $uuid->getClockSequence()); } - public function testUuidVersion1MethodBehavior64Bit(): void + public function testUuidVersion1MethodBehavior64Bit() { - $this->skip64BitTest(); - - /** @var Uuid $uuid */ $uuid = Uuid::uuid1('ffffffffffff', 0xffff); - $this->assertInstanceOf(DateTimeImmutable::class, $uuid->getDateTime()); + $this->assertInstanceOf('DateTimeInterface', $uuid->getDateTime()); $this->assertSame('ffffffffffff', $uuid->getNodeHex()); $this->assertSame('281474976710655', (string) $uuid->getNode()); $this->assertSame('3fff', $uuid->getClockSequenceHex()); @@ -182,24 +161,15 @@ class ExpectedBehaviorTest extends TestCase } /** - * @param mixed $uuid - * * @dataProvider provideIsValid */ - public function testIsValid($uuid, bool $expected): void + public function testIsValid($uuid, $expected) { - $this->assertSame($expected, Uuid::isValid((string) $uuid), "{$uuid} is not a valid UUID"); - $this->assertSame( - $expected, - Uuid::isValid(strtoupper((string) $uuid)), - strtoupper((string) $uuid) . ' is not a valid UUID' - ); + $this->assertSame($expected, Uuid::isValid($uuid), "{$uuid} is not a valid UUID"); + $this->assertSame($expected, Uuid::isValid(strtoupper($uuid)), strtoupper($uuid) . ' is not a valid UUID'); } - /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification - */ - public function provideIsValid(): array + public function provideIsValid() { return [ // RFC 4122 UUIDs @@ -256,7 +226,7 @@ class ExpectedBehaviorTest extends TestCase /** * @dataProvider provideFromStringInteger */ - public function testSerialization(string $string): void + public function testSerialization($string) { $uuid = Uuid::fromString($string); @@ -271,10 +241,8 @@ class ExpectedBehaviorTest extends TestCase /** * @dataProvider provideFromStringInteger */ - public function testNumericReturnValues(string $string): void + public function testNumericReturnValues($string) { - $this->skip64BitTest(); - $leastSignificantBitsHex = substr(str_replace('-', '', $string), 16); $mostSignificantBitsHex = substr(str_replace('-', '', $string), 0, 16); $leastSignificantBits = BigNumber::convertToBase10($leastSignificantBitsHex, 16); @@ -289,7 +257,6 @@ class ExpectedBehaviorTest extends TestCase $clockSeqHiAndReserved = (int) $components[3] >> 8; $clockSeqLow = (int) $components[3] & 0x00ff; - /** @var Uuid $uuid */ $uuid = Uuid::fromString($string); $this->assertSame($components[0], (string) $uuid->getTimeLow()); @@ -306,13 +273,13 @@ class ExpectedBehaviorTest extends TestCase /** * @dataProvider provideFromStringInteger */ - public function testFromBytes(string $string, ?int $version, int $variant, string $integer): void + public function testFromBytes($string, $version, $variant, $integer) { - $bytes = (string) hex2bin(str_replace('-', '', $string)); + $bytes = hex2bin(str_replace('-', '', $string)); $uuid = Uuid::fromBytes($bytes); - $this->assertInstanceOf(UuidInterface::class, $uuid); + $this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid); $this->assertSame($string, $uuid->toString()); $this->assertSame($version, $uuid->getVersion()); $this->assertSame($variant, $uuid->getVariant()); @@ -331,13 +298,13 @@ class ExpectedBehaviorTest extends TestCase /** * @dataProvider provideFromStringInteger */ - public function testFromInteger(string $string, ?int $version, int $variant, string $integer): void + public function testFromInteger($string, $version, $variant, $integer) { $bytes = hex2bin(str_replace('-', '', $string)); $uuid = Uuid::fromInteger($integer); - $this->assertInstanceOf(UuidInterface::class, $uuid); + $this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid); $this->assertSame($string, $uuid->toString()); $this->assertSame($version, $uuid->getVersion()); $this->assertSame($variant, $uuid->getVariant()); @@ -356,13 +323,13 @@ class ExpectedBehaviorTest extends TestCase /** * @dataProvider provideFromStringInteger */ - public function testFromString(string $string, ?int $version, int $variant, string $integer): void + public function testFromString($string, $version, $variant, $integer) { $bytes = hex2bin(str_replace('-', '', $string)); $uuid = Uuid::fromString($string); - $this->assertInstanceOf(UuidInterface::class, $uuid); + $this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid); $this->assertSame($string, $uuid->toString()); $this->assertSame($version, $uuid->getVersion()); $this->assertSame($variant, $uuid->getVariant()); @@ -378,10 +345,7 @@ class ExpectedBehaviorTest extends TestCase $this->assertSame($bytes, $uuid->getBytes()); } - /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification - */ - public function provideFromStringInteger(): array + public function provideFromStringInteger() { return [ ['00000000-0000-0000-0000-000000000000', null, 0, '0'], @@ -425,11 +389,11 @@ class ExpectedBehaviorTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testGetSetFactory(): void + public function testGetSetFactory() { - $this->assertInstanceOf(UuidFactory::class, Uuid::getFactory()); + $this->assertInstanceOf('Ramsey\Uuid\UuidFactory', Uuid::getFactory()); - $factory = Mockery::mock(UuidFactory::class); + $factory = \Mockery::mock('Ramsey\Uuid\UuidFactory'); Uuid::setFactory($factory); $this->assertSame($factory, Uuid::getFactory()); @@ -439,11 +403,11 @@ class ExpectedBehaviorTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testFactoryProvidesFunctionality(): void + public function testFactoryProvidesFunctionality() { - $uuid = Mockery::mock(UuidInterface::class); + $uuid = \Mockery::mock('Ramsey\Uuid\UuidInterface'); - $factory = Mockery::mock(UuidFactoryInterface::class, [ + $factory = \Mockery::mock('Ramsey\Uuid\UuidFactoryInterface', [ 'uuid1' => $uuid, 'uuid3' => $uuid, 'uuid4' => $uuid, @@ -459,7 +423,7 @@ class ExpectedBehaviorTest extends TestCase $this->assertSame($uuid, Uuid::uuid3(Uuid::NAMESPACE_URL, 'https://example.com/foo')); $this->assertSame($uuid, Uuid::uuid4()); $this->assertSame($uuid, Uuid::uuid5(Uuid::NAMESPACE_URL, 'https://example.com/foo')); - $this->assertSame($uuid, Uuid::fromBytes((string) hex2bin('ffffffffffffffffffffffffffffffff'))); + $this->assertSame($uuid, Uuid::fromBytes(hex2bin('ffffffffffffffffffffffffffffffff'))); $this->assertSame($uuid, Uuid::fromString('ffffffff-ffff-ffff-ffff-ffffffffffff')); $this->assertSame($uuid, Uuid::fromInteger('340282366920938463463374607431768211455')); } @@ -468,11 +432,10 @@ class ExpectedBehaviorTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testUsingDegradedFeatures(): void + public function testUsingDegradedFeatures() { $numberConverter = new DegradedNumberConverter(); - $timeConverter = new DegradedTimeConverter(); - $builder = new DegradedUuidBuilder($numberConverter, $timeConverter); + $builder = new DegradedUuidBuilder($numberConverter); $factory = new UuidFactory(); $factory->setNumberConverter($numberConverter); @@ -482,20 +445,20 @@ class ExpectedBehaviorTest extends TestCase $uuid = Uuid::uuid1(); - $this->assertInstanceOf(UuidInterface::class, $uuid); - $this->assertInstanceOf(DegradedUuid::class, $uuid); - $this->assertInstanceOf(DegradedNumberConverter::class, $uuid->getNumberConverter()); + $this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid); + $this->assertInstanceOf('Ramsey\Uuid\DegradedUuid', $uuid); + $this->assertInstanceOf('Ramsey\Uuid\Converter\Number\DegradedNumberConverter', $uuid->getNumberConverter()); } /** * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testUsingCustomCodec(): void + public function testUsingCustomCodec() { - $mockUuid = Mockery::mock(UuidInterface::class); + $mockUuid = \Mockery::mock('Ramsey\Uuid\UuidInterface'); - $codec = Mockery::mock(CodecInterface::class, [ + $codec = \Mockery::mock('Ramsey\Uuid\Codec\CodecInterface', [ 'encode' => 'abcd1234', 'encodeBinary' => hex2bin('abcd1234'), 'decode' => $mockUuid, @@ -512,16 +475,16 @@ class ExpectedBehaviorTest extends TestCase $this->assertSame('abcd1234', $uuid->toString()); $this->assertSame(hex2bin('abcd1234'), $uuid->getBytes()); $this->assertSame($mockUuid, Uuid::fromString('f00ba2')); - $this->assertSame($mockUuid, Uuid::fromBytes((string) hex2bin('f00ba2'))); + $this->assertSame($mockUuid, Uuid::fromBytes(hex2bin('f00ba2'))); } /** * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testUsingCustomRandomGenerator(): void + public function testUsingCustomRandomGenerator() { - $generator = Mockery::mock(RandomGeneratorInterface::class, [ + $generator = \Mockery::mock('Ramsey\Uuid\Generator\RandomGeneratorInterface', [ 'generate' => hex2bin('01234567abcd5432dcba0123456789ab'), ]); @@ -539,9 +502,9 @@ class ExpectedBehaviorTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testUsingCustomTimeGenerator(): void + public function testUsingCustomTimeGenerator() { - $generator = Mockery::mock(TimeGeneratorInterface::class, [ + $generator = \Mockery::mock('Ramsey\Uuid\Generator\TimeGeneratorInterface', [ 'generate' => hex2bin('01234567abcd5432dcba0123456789ab'), ]); @@ -559,13 +522,13 @@ class ExpectedBehaviorTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testUsingDefaultTimeGeneratorWithCustomProviders(): void + public function testUsingDefaultTimeGeneratorWithCustomProviders() { - $nodeProvider = Mockery::mock(NodeProviderInterface::class, [ + $nodeProvider = \Mockery::mock('Ramsey\Uuid\Provider\NodeProviderInterface', [ 'getNode' => '0123456789ab', ]); - $timeConverter = Mockery::mock(TimeConverterInterface::class); + $timeConverter = \Mockery::mock('Ramsey\Uuid\Converter\TimeConverterInterface'); $timeConverter ->shouldReceive('calculateTime') ->andReturnUsing(function ($seconds, $microSeconds) { @@ -576,11 +539,12 @@ class ExpectedBehaviorTest extends TestCase ]; }); - $timeProvider = Mockery::mock(TimeProviderInterface::class, [ + $timeProvider = \Mockery::mock('Ramsey\Uuid\Provider\TimeProviderInterface', [ 'currentTime' => [ 'sec' => 1578522046, 'usec' => 10000, ], + 'getTime' => new Time(1578522046, 10000), ]); $generator = new DefaultTimeGenerator($nodeProvider, $timeConverter, $timeProvider); @@ -599,22 +563,22 @@ class ExpectedBehaviorTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testHelperFunctions(): void + public function testHelperFunctions() { - $uuid1 = Mockery::mock(UuidInterface::class, [ + $uuid1 = \Mockery::mock('Ramsey\Uuid\UuidInterface', [ 'toString' => 'aVersion1Uuid', ]); - $uuid3 = Mockery::mock(UuidInterface::class, [ + $uuid3 = \Mockery::mock('Ramsey\Uuid\UuidInterface', [ 'toString' => 'aVersion3Uuid', ]); - $uuid4 = Mockery::mock(UuidInterface::class, [ + $uuid4 = \Mockery::mock('Ramsey\Uuid\UuidInterface', [ 'toString' => 'aVersion4Uuid', ]); - $uuid5 = Mockery::mock(UuidInterface::class, [ + $uuid5 = \Mockery::mock('Ramsey\Uuid\UuidInterface', [ 'toString' => 'aVersion5Uuid', ]); - $factory = Mockery::mock(UuidFactoryInterface::class, [ + $factory = \Mockery::mock('Ramsey\Uuid\UuidFactoryInterface', [ 'uuid1' => $uuid1, 'uuid3' => $uuid3, 'uuid4' => $uuid4, @@ -623,10 +587,10 @@ class ExpectedBehaviorTest extends TestCase Uuid::setFactory($factory); - $this->assertSame('aVersion1Uuid', v1('ffffffffffff', 0xffff)); - $this->assertSame('aVersion3Uuid', v3(Uuid::NAMESPACE_URL, 'https://example.com/foo')); - $this->assertSame('aVersion4Uuid', v4()); - $this->assertSame('aVersion5Uuid', v5(Uuid::NAMESPACE_URL, 'https://example.com/foo')); + $this->assertSame('aVersion1Uuid', \Ramsey\Uuid\v1('ffffffffffff', 0xffff)); + $this->assertSame('aVersion3Uuid', \Ramsey\Uuid\v3(Uuid::NAMESPACE_URL, 'https://example.com/foo')); + $this->assertSame('aVersion4Uuid', \Ramsey\Uuid\v4()); + $this->assertSame('aVersion5Uuid', \Ramsey\Uuid\v5(Uuid::NAMESPACE_URL, 'https://example.com/foo')); } /**