Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Ramsey\Uuid\Test; use Brick\Math\BigInteger; use Ramsey\Uuid\Builder\Degr..

Decoded Output download

<?php
 namespace Ramsey\Uuid\Test; use Brick\Math\BigInteger; use Ramsey\Uuid\Builder\DegradedUuidBuilder; use Ramsey\Uuid\Codec\CodecInterface; use Ramsey\Uuid\Codec\OrderedTimeCodec; use Ramsey\Uuid\Codec\TimestampFirstCombCodec; use Ramsey\Uuid\Converter\Number\DegradedNumberConverter; use Ramsey\Uuid\Converter\Time\DegradedTimeConverter; use Ramsey\Uuid\Converter\TimeConverterInterface; use Ramsey\Uuid\DegradedUuid; use Ramsey\Uuid\Generator\CombGenerator; use Ramsey\Uuid\Generator\DefaultTimeGenerator; use Ramsey\Uuid\Math\BrickMathCalculator; use Ramsey\Uuid\Type\Hexadecimal; use Ramsey\Uuid\Type\Time; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidFactory; use stdClass; class ExpectedBehaviorTest extends TestCase { public function testStaticCreationMethodsAndStandardBehavior($method, $args) { $uuid = call_user_func_array(array("Ramsey\Uuid\Uuid", $method), $args); $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("Ramsey\Uuid\Converter\NumberConverterInterface", $uuid->getNumberConverter()); $this->assertIsString((string) $uuid->getHex()); $this->assertIsArray($uuid->getFieldsHex()); $this->assertArrayHasKey("time_low", $uuid->getFieldsHex()); $this->assertArrayHasKey("time_mid", $uuid->getFieldsHex()); $this->assertArrayHasKey("time_hi_and_version", $uuid->getFieldsHex()); $this->assertArrayHasKey("clock_seq_hi_and_reserved", $uuid->getFieldsHex()); $this->assertArrayHasKey("clock_seq_low", $uuid->getFieldsHex()); $this->assertArrayHasKey("node", $uuid->getFieldsHex()); $this->assertIsString($uuid->getTimeLowHex()); $this->assertIsString($uuid->getTimeMidHex()); $this->assertIsString($uuid->getTimeHiAndVersionHex()); $this->assertIsString($uuid->getClockSeqHiAndReservedHex()); $this->assertIsString($uuid->getClockSeqLowHex()); $this->assertIsString($uuid->getNodeHex()); $this->assertSame($uuid->getFieldsHex()["time_low"], $uuid->getTimeLowHex()); $this->assertSame($uuid->getFieldsHex()["time_mid"], $uuid->getTimeMidHex()); $this->assertSame($uuid->getFieldsHex()["time_hi_and_version"], $uuid->getTimeHiAndVersionHex()); $this->assertSame($uuid->getFieldsHex()["clock_seq_hi_and_reserved"], $uuid->getClockSeqHiAndReservedHex()); $this->assertSame($uuid->getFieldsHex()["clock_seq_low"], $uuid->getClockSeqLowHex()); $this->assertSame($uuid->getFieldsHex()["node"], $uuid->getNodeHex()); $this->assertSame(substr((string) $uuid->getHex(), 16), $uuid->getLeastSignificantBitsHex()); $this->assertSame(substr((string) $uuid->getHex(), 0, 16), $uuid->getMostSignificantBitsHex()); $this->assertSame((string) $uuid->getHex(), $uuid->getTimeLowHex() . $uuid->getTimeMidHex() . $uuid->getTimeHiAndVersionHex() . $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex() . $uuid->getNodeHex()); $this->assertSame((string) $uuid->getHex(), $uuid->getFieldsHex()["time_low"] . $uuid->getFieldsHex()["time_mid"] . $uuid->getFieldsHex()["time_hi_and_version"] . $uuid->getFieldsHex()["clock_seq_hi_and_reserved"] . $uuid->getFieldsHex()["clock_seq_low"] . $uuid->getFieldsHex()["node"]); $this->assertIsString($uuid->getUrn()); $this->assertStringStartsWith("urn:uuid:", $uuid->getUrn()); $this->assertSame("urn:uuid:" . (string) $uuid->getHex(), str_replace("-", '', $uuid->getUrn())); $this->assertSame((string) $uuid->getHex(), str_replace("-", '', $uuid->toString())); $this->assertSame((string) $uuid->getHex(), str_replace("-", '', (string) $uuid)); $this->assertSame($uuid->toString(), $uuid->getTimeLowHex() . "-" . $uuid->getTimeMidHex() . "-" . $uuid->getTimeHiAndVersionHex() . "-" . $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex() . "-" . $uuid->getNodeHex()); $this->assertSame((string) $uuid, $uuid->getTimeLowHex() . "-" . $uuid->getTimeMidHex() . "-" . $uuid->getTimeHiAndVersionHex() . "-" . $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex() . "-" . $uuid->getNodeHex()); $this->assertSame(2, $uuid->getVariant()); $this->assertSame((int) substr($method, -1), $uuid->getVersion()); $this->assertSame(1, preg_match("/^\d+$/", (string) $uuid->getInteger())); } public function provideStaticCreationMethods() { return array(array("uuid1", array()), array("uuid1", array("00000fffffff")), array("uuid1", array(null, 1234)), array("uuid1", array("00000fffffff", 1234)), array("uuid1", array("00000fffffff", null)), array("uuid1", array(268435455)), array("uuid1", array(268435455, 1234)), array("uuid1", array(268435455, null)), array("uuid3", array(Uuid::NAMESPACE_URL, "https://example.com/foo")), array("uuid4", array()), array("uuid5", array(Uuid::NAMESPACE_URL, "https://example.com/foo"))); } public function testUuidVersion1MethodBehavior() { $uuid = Uuid::uuid1("00000fffffff", 65535); $this->assertInstanceOf("DateTimeInterface", $uuid->getDateTime()); $this->assertSame("00000fffffff", $uuid->getNodeHex()); $this->assertSame("3fff", $uuid->getClockSequenceHex()); $this->assertSame("16383", (string) $uuid->getClockSequence()); } public function testUuidVersion1MethodBehavior64Bit() { $uuid = Uuid::uuid1("ffffffffffff", 65535); $this->assertInstanceOf("DateTimeInterface", $uuid->getDateTime()); $this->assertSame("ffffffffffff", $uuid->getNodeHex()); $this->assertSame("281474976710655", (string) $uuid->getNode()); $this->assertSame("3fff", $uuid->getClockSequenceHex()); $this->assertSame("16383", (string) $uuid->getClockSequence()); $this->assertSame(1, preg_match("/^\d+$/", (string) $uuid->getTimestamp())); } public function testIsValid($uuid, $expected) { $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"); } public function provideIsValid() { return array(array("00000000-0000-0000-0000-000000000000", true), array("ff6f8cb0-c57d-11e1-8b21-0800200c9a66", true), array("ff6f8cb0-c57d-11e1-9b21-0800200c9a66", true), array("ff6f8cb0-c57d-11e1-ab21-0800200c9a66", true), array("ff6f8cb0-c57d-11e1-bb21-0800200c9a66", true), array("ff6f8cb0-c57d-21e1-8b21-0800200c9a66", true), array("ff6f8cb0-c57d-21e1-9b21-0800200c9a66", true), array("ff6f8cb0-c57d-21e1-ab21-0800200c9a66", true), array("ff6f8cb0-c57d-21e1-bb21-0800200c9a66", true), array("ff6f8cb0-c57d-31e1-8b21-0800200c9a66", true), array("ff6f8cb0-c57d-31e1-9b21-0800200c9a66", true), array("ff6f8cb0-c57d-31e1-ab21-0800200c9a66", true), array("ff6f8cb0-c57d-31e1-bb21-0800200c9a66", true), array("ff6f8cb0-c57d-41e1-8b21-0800200c9a66", true), array("ff6f8cb0-c57d-41e1-9b21-0800200c9a66", true), array("ff6f8cb0-c57d-41e1-ab21-0800200c9a66", true), array("ff6f8cb0-c57d-41e1-bb21-0800200c9a66", true), array("ff6f8cb0-c57d-51e1-8b21-0800200c9a66", true), array("ff6f8cb0-c57d-51e1-9b21-0800200c9a66", true), array("ff6f8cb0-c57d-51e1-ab21-0800200c9a66", true), array("ff6f8cb0-c57d-51e1-bb21-0800200c9a66", true), array("ffffffff-ffff-ffff-ffff-ffffffffffff", true), array("00000000-0000-0000-0000-000000000000", true), array("ff6f8cb0-c57d-01e1-0b21-0800200c9a66", true), array("ff6f8cb0-c57d-01e1-1b21-0800200c9a66", true), array("ff6f8cb0-c57d-01e1-2b21-0800200c9a66", true), array("ff6f8cb0-c57d-01e1-3b21-0800200c9a66", true), array("ff6f8cb0-c57d-01e1-4b21-0800200c9a66", true), array("ff6f8cb0-c57d-01e1-5b21-0800200c9a66", true), array("ff6f8cb0-c57d-01e1-6b21-0800200c9a66", true), array("ff6f8cb0-c57d-01e1-7b21-0800200c9a66", true), array("ff6f8cb0-c57d-01e1-db21-0800200c9a66", true), array("ff6f8cb0-c57d-01e1-eb21-0800200c9a66", true), array("ff6f8cb0-c57d-01e1-fb21-0800200c9a66", true), array("{ff6f8cb0-c57d-01e1-fb21-0800200c9a66}", true), array("urn:uuid:ff6f8cb0-c57d-01e1-fb21-0800200c9a66", true), array("ffffffffffffffffffffffffffffffff", false), array("00000000000000000000000000000000", false), array(0, false), array("foobar", false), array("ff6f8cb0c57d51e1bb210800200c9a66", false), array("gf6f8cb0-c57d-51e1-bb21-0800200c9a66", false)); } public function testSerialization($string) { $uuid = Uuid::fromString($string); $serialized = serialize($uuid); $unserialized = unserialize($serialized); $this->assertSame(0, $uuid->compareTo($unserialized)); $this->assertTrue($uuid->equals($unserialized)); $this->assertSame(""{$string}"", json_encode($uuid)); } public function testSerializationWithOrderedTimeCodec($string) { $factory = new UuidFactory(); $factory->setCodec(new OrderedTimeCodec($factory->getUuidBuilder())); $previousFactory = Uuid::getFactory(); Uuid::setFactory($factory); $uuid = Uuid::fromString($string); $serialized = serialize($uuid); $unserialized = unserialize($serialized); Uuid::setFactory($previousFactory); $this->assertSame(0, $uuid->compareTo($unserialized)); $this->assertTrue($uuid->equals($unserialized)); $this->assertSame(""{$string}"", json_encode($uuid)); } public function testNumericReturnValues($string) { $leastSignificantBitsHex = substr(str_replace("-", '', $string), 16); $mostSignificantBitsHex = substr(str_replace("-", '', $string), 0, 16); $leastSignificantBits = BigInteger::fromBase($leastSignificantBitsHex, 16)->__toString(); $mostSignificantBits = BigInteger::fromBase($mostSignificantBitsHex, 16)->__toString(); $components = explode("-", $string); array_walk($components, function (&$value) { $value = BigInteger::fromBase($value, 16)->__toString(); }); if (strtolower($string) === Uuid::MAX) { $clockSeq = (int) $components[3]; } else { $clockSeq = (int) $components[3] & 16383; } $clockSeqHiAndReserved = (int) $components[3] >> 8; $clockSeqLow = (int) $components[3] & 255; $uuid = Uuid::fromString($string); $this->assertSame($components[0], (string) $uuid->getTimeLow()); $this->assertSame($components[1], (string) $uuid->getTimeMid()); $this->assertSame($components[2], (string) $uuid->getTimeHiAndVersion()); $this->assertSame((string) $clockSeq, (string) $uuid->getClockSequence()); $this->assertSame((string) $clockSeqHiAndReserved, (string) $uuid->getClockSeqHiAndReserved()); $this->assertSame((string) $clockSeqLow, (string) $uuid->getClockSeqLow()); $this->assertSame($components[4], (string) $uuid->getNode()); $this->assertSame($leastSignificantBits, (string) $uuid->getLeastSignificantBits()); $this->assertSame($mostSignificantBits, (string) $uuid->getMostSignificantBits()); } public function testFromBytes($string, $version, $variant, $integer) { $bytes = hex2bin(str_replace("-", '', $string)); $uuid = Uuid::fromBytes($bytes); $this->assertInstanceOf("Ramsey\Uuid\UuidInterface", $uuid); $this->assertSame($string, $uuid->toString()); $this->assertSame($version, $uuid->getVersion()); $this->assertSame($variant, $uuid->getVariant()); $components = explode("-", $string); $this->assertSame($components[0], $uuid->getTimeLowHex()); $this->assertSame($components[1], $uuid->getTimeMidHex()); $this->assertSame($components[2], $uuid->getTimeHiAndVersionHex()); $this->assertSame($components[3], $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex()); $this->assertSame($components[4], $uuid->getNodeHex()); $this->assertSame($integer, (string) $uuid->getInteger()); $this->assertSame($bytes, $uuid->getBytes()); } public function testFromInteger($string, $version, $variant, $integer) { $bytes = hex2bin(str_replace("-", '', $string)); $uuid = Uuid::fromInteger($integer); $this->assertInstanceOf("Ramsey\Uuid\UuidInterface", $uuid); $this->assertSame($string, $uuid->toString()); $this->assertSame($version, $uuid->getVersion()); $this->assertSame($variant, $uuid->getVariant()); $components = explode("-", $string); $this->assertSame($components[0], $uuid->getTimeLowHex()); $this->assertSame($components[1], $uuid->getTimeMidHex()); $this->assertSame($components[2], $uuid->getTimeHiAndVersionHex()); $this->assertSame($components[3], $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex()); $this->assertSame($components[4], $uuid->getNodeHex()); $this->assertSame($integer, (string) $uuid->getInteger()); $this->assertSame($bytes, $uuid->getBytes()); } public function testFromString($string, $version, $variant, $integer) { $bytes = hex2bin(str_replace("-", '', $string)); $uuid = Uuid::fromString($string); $this->assertInstanceOf("Ramsey\Uuid\UuidInterface", $uuid); $this->assertSame($string, $uuid->toString()); $this->assertSame($version, $uuid->getVersion()); $this->assertSame($variant, $uuid->getVariant()); $components = explode("-", $string); $this->assertSame($components[0], $uuid->getTimeLowHex()); $this->assertSame($components[1], $uuid->getTimeMidHex()); $this->assertSame($components[2], $uuid->getTimeHiAndVersionHex()); $this->assertSame($components[3], $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex()); $this->assertSame($components[4], $uuid->getNodeHex()); $this->assertSame($integer, (string) $uuid->getInteger()); $this->assertSame($bytes, $uuid->getBytes()); } public function provideFromStringInteger() { return array(array("00000000-0000-0000-0000-000000000000", null, 2, "0"), array("ff6f8cb0-c57d-11e1-8b21-0800200c9a66", 1, 2, "339532337419071774304650190139318639206"), array("ff6f8cb0-c57d-11e1-9b21-0800200c9a66", 1, 2, "339532337419071774305803111643925486182"), array("ff6f8cb0-c57d-11e1-ab21-0800200c9a66", 1, 2, "339532337419071774306956033148532333158"), array("ff6f8cb0-c57d-11e1-bb21-0800200c9a66", 1, 2, "339532337419071774308108954653139180134"), array("ff6f8cb0-c57d-21e1-8b21-0800200c9a66", 2, 2, "339532337419071849862513916053642058342"), array("ff6f8cb0-c57d-21e1-9b21-0800200c9a66", 2, 2, "339532337419071849863666837558248905318"), array("ff6f8cb0-c57d-21e1-ab21-0800200c9a66", 2, 2, "339532337419071849864819759062855752294"), array("ff6f8cb0-c57d-21e1-bb21-0800200c9a66", 2, 2, "339532337419071849865972680567462599270"), array("ff6f8cb0-c57d-31e1-8b21-0800200c9a66", 3, 2, "339532337419071925420377641967965477478"), array("ff6f8cb0-c57d-31e1-9b21-0800200c9a66", 3, 2, "339532337419071925421530563472572324454"), array("ff6f8cb0-c57d-31e1-ab21-0800200c9a66", 3, 2, "339532337419071925422683484977179171430"), array("ff6f8cb0-c57d-31e1-bb21-0800200c9a66", 3, 2, "339532337419071925423836406481786018406"), array("ff6f8cb0-c57d-41e1-8b21-0800200c9a66", 4, 2, "339532337419072000978241367882288896614"), array("ff6f8cb0-c57d-41e1-9b21-0800200c9a66", 4, 2, "339532337419072000979394289386895743590"), array("ff6f8cb0-c57d-41e1-ab21-0800200c9a66", 4, 2, "339532337419072000980547210891502590566"), array("ff6f8cb0-c57d-41e1-bb21-0800200c9a66", 4, 2, "339532337419072000981700132396109437542"), array("ff6f8cb0-c57d-51e1-8b21-0800200c9a66", 5, 2, "339532337419072076536105093796612315750"), array("ff6f8cb0-c57d-51e1-9b21-0800200c9a66", 5, 2, "339532337419072076537258015301219162726"), array("ff6f8cb0-c57d-51e1-ab21-0800200c9a66", 5, 2, "339532337419072076538410936805826009702"), array("ff6f8cb0-c57d-51e1-bb21-0800200c9a66", 5, 2, "339532337419072076539563858310432856678"), array("ff6f8cb0-c57d-01e1-0b21-0800200c9a66", null, 0, "339532337419071698737563092188140444262"), array("ff6f8cb0-c57d-01e1-1b21-0800200c9a66", null, 0, "339532337419071698738716013692747291238"), array("ff6f8cb0-c57d-01e1-2b21-0800200c9a66", null, 0, "339532337419071698739868935197354138214"), array("ff6f8cb0-c57d-01e1-3b21-0800200c9a66", null, 0, "339532337419071698741021856701960985190"), array("ff6f8cb0-c57d-01e1-4b21-0800200c9a66", null, 0, "339532337419071698742174778206567832166"), array("ff6f8cb0-c57d-01e1-5b21-0800200c9a66", null, 0, "339532337419071698743327699711174679142"), array("ff6f8cb0-c57d-01e1-6b21-0800200c9a66", null, 0, "339532337419071698744480621215781526118"), array("ff6f8cb0-c57d-01e1-7b21-0800200c9a66", null, 0, "339532337419071698745633542720388373094"), array("ff6f8cb0-c57d-01e1-cb21-0800200c9a66", null, 6, "339532337419071698751398150243422607974"), array("ff6f8cb0-c57d-01e1-db21-0800200c9a66", null, 6, "339532337419071698752551071748029454950"), array("ff6f8cb0-c57d-01e1-eb21-0800200c9a66", null, 7, "339532337419071698753703993252636301926"), array("ff6f8cb0-c57d-01e1-fb21-0800200c9a66", null, 7, "339532337419071698754856914757243148902"), array("ffffffff-ffff-ffff-ffff-ffffffffffff", null, 2, "340282366920938463463374607431768211455")); } public function testGetSetFactory() { $this->assertInstanceOf("Ramsey\Uuid\UuidFactory", Uuid::getFactory()); $factory = \Mockery::mock("Ramsey\Uuid\UuidFactory"); Uuid::setFactory($factory); $this->assertSame($factory, Uuid::getFactory()); } public function testFactoryProvidesFunctionality() { $uuid = \Mockery::mock("Ramsey\Uuid\UuidInterface"); $factory = \Mockery::mock("Ramsey\Uuid\UuidFactoryInterface", array("uuid1" => $uuid, "uuid3" => $uuid, "uuid4" => $uuid, "uuid5" => $uuid, "fromBytes" => $uuid, "fromString" => $uuid, "fromInteger" => $uuid)); Uuid::setFactory($factory); $this->assertSame($uuid, Uuid::uuid1("ffffffffffff", 65535)); $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(hex2bin("ffffffffffffffffffffffffffffffff"))); $this->assertSame($uuid, Uuid::fromString("ffffffff-ffff-ffff-ffff-ffffffffffff")); $this->assertSame($uuid, Uuid::fromInteger("340282366920938463463374607431768211455")); } public function testUsingDegradedFeatures() { $numberConverter = new DegradedNumberConverter(); $builder = new DegradedUuidBuilder($numberConverter); $factory = new UuidFactory(); $factory->setNumberConverter($numberConverter); $factory->setUuidBuilder($builder); Uuid::setFactory($factory); $uuid = Uuid::uuid1(); $this->assertInstanceOf("Ramsey\Uuid\UuidInterface", $uuid); $this->assertInstanceOf("Ramsey\Uuid\DegradedUuid", $uuid); $this->assertInstanceOf("Ramsey\Uuid\Converter\Number\DegradedNumberConverter", $uuid->getNumberConverter()); } public function testUsingCustomCodec() { $mockUuid = \Mockery::mock("Ramsey\Uuid\UuidInterface"); $codec = \Mockery::mock("Ramsey\Uuid\Codec\CodecInterface", array("encode" => "abcd1234", "encodeBinary" => hex2bin("abcd1234"), "decode" => $mockUuid, "decodeBytes" => $mockUuid)); $factory = new UuidFactory(); $factory->setCodec($codec); Uuid::setFactory($factory); $uuid = Uuid::uuid4(); $this->assertSame("abcd1234", $uuid->toString()); $this->assertSame(hex2bin("abcd1234"), $uuid->getBytes()); $this->assertSame($mockUuid, Uuid::fromString("f00ba2")); $this->assertSame($mockUuid, Uuid::fromBytes(hex2bin("f00ba2"))); } public function testUsingCustomRandomGenerator() { $generator = \Mockery::mock("Ramsey\Uuid\Generator\RandomGeneratorInterface", array("generate" => hex2bin("01234567abcd5432dcba0123456789ab"))); $factory = new UuidFactory(); $factory->setRandomGenerator($generator); Uuid::setFactory($factory); $uuid = Uuid::uuid4(); $this->assertSame("01234567-abcd-4432-9cba-0123456789ab", $uuid->toString()); } public function testUsingCustomTimeGenerator() { $generator = \Mockery::mock("Ramsey\Uuid\Generator\TimeGeneratorInterface", array("generate" => hex2bin("01234567abcd5432dcba0123456789ab"))); $factory = new UuidFactory(); $factory->setTimeGenerator($generator); Uuid::setFactory($factory); $uuid = Uuid::uuid1(); $this->assertSame("01234567-abcd-1432-9cba-0123456789ab", $uuid->toString()); } public function testUsingDefaultTimeGeneratorWithCustomProviders() { $nodeProvider = \Mockery::mock("Ramsey\Uuid\Provider\NodeProviderInterface", array("getNode" => new Hexadecimal("0123456789ab"))); $timeConverter = \Mockery::mock("Ramsey\Uuid\Converter\TimeConverterInterface"); $timeConverter->shouldReceive("calculateTime")->andReturnUsing(function ($seconds, $microseconds) { return new Hexadecimal("abcd" . dechex($microseconds) . dechex($seconds)); }); $timeProvider = \Mockery::mock("Ramsey\Uuid\Provider\TimeProviderInterface", array("currentTime" => array("sec" => 1578522046, "usec" => 10000), "getTime" => new Time(1578522046, 10000))); $generator = new DefaultTimeGenerator($nodeProvider, $timeConverter, $timeProvider); $factory = new UuidFactory(); $factory->setTimeGenerator($generator); Uuid::setFactory($factory); $uuid = Uuid::uuid1(null, 4095); $this->assertSame("5e1655be-2710-1bcd-8fff-0123456789ab", $uuid->toString()); } public function testHelperFunctions() { $uuid1 = \Mockery::mock("Ramsey\Uuid\UuidInterface", array("toString" => "aVersion1Uuid")); $uuid3 = \Mockery::mock("Ramsey\Uuid\UuidInterface", array("toString" => "aVersion3Uuid")); $uuid4 = \Mockery::mock("Ramsey\Uuid\UuidInterface", array("toString" => "aVersion4Uuid")); $uuid5 = \Mockery::mock("Ramsey\Uuid\UuidInterface", array("toString" => "aVersion5Uuid")); $factory = \Mockery::mock("Ramsey\Uuid\UuidFactoryInterface", array("uuid1" => $uuid1, "uuid3" => $uuid3, "uuid4" => $uuid4, "uuid5" => $uuid5)); Uuid::setFactory($factory); $this->assertSame("aVersion1Uuid", \Ramsey\Uuid\v1("ffffffffffff", 65535)); $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")); } public function testUseOfTimestampFirstCombCodec() { $factory = new UuidFactory(); $factory->setRandomGenerator(new CombGenerator($factory->getRandomGenerator(), $factory->getNumberConverter())); $factory->setCodec(new TimestampFirstCombCodec($factory->getUuidBuilder())); $uuid = $factory->uuid4(); $fields = array_values($uuid->getFieldsHex()); $last48Bits = $fields[5]; $fields[5] = $fields[0] . $fields[1]; $fields[0] = substr($last48Bits, 0, 8); $fields[1] = substr($last48Bits, 8, 4); $expectedHex = implode('', $fields); $expectedBytes = hex2bin($expectedHex); $this->assertInstanceOf("Ramsey\Uuid\UuidInterface", $uuid); $this->assertSame(2, $uuid->getVariant()); $this->assertSame(4, $uuid->getVersion()); $this->assertSame($expectedBytes, $uuid->getBytes()); $this->assertSame($expectedHex, (string) $uuid->getHex()); } public function testUuidConstants($constantName, $expected) { $this->assertSame($expected, constant("Ramsey\Uuid\Uuid::{$constantName}")); } public function provideUuidConstantTests() { return array(array("NAMESPACE_DNS", "6ba7b810-9dad-11d1-80b4-00c04fd430c8"), array("NAMESPACE_URL", "6ba7b811-9dad-11d1-80b4-00c04fd430c8"), array("NAMESPACE_OID", "6ba7b812-9dad-11d1-80b4-00c04fd430c8"), array("NAMESPACE_X500", "6ba7b814-9dad-11d1-80b4-00c04fd430c8"), array("NIL", "00000000-0000-0000-0000-000000000000"), array("MAX", "ffffffff-ffff-ffff-ffff-ffffffffffff"), array("RESERVED_NCS", 0), array("RFC_4122", 2), array("RESERVED_MICROSOFT", 6), array("RESERVED_FUTURE", 7), array("VALID_PATTERN", "^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$"), array("UUID_TYPE_TIME", 1), array("UUID_TYPE_IDENTIFIER", 2), array("UUID_TYPE_HASH_MD5", 3), array("UUID_TYPE_RANDOM", 4), array("UUID_TYPE_HASH_SHA1", 5), array("UUID_TYPE_REORDERED_TIME", 6), array("UUID_TYPE_UNIX_TIME", 7)); } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace Ramsey\Uuid\Test; use Brick\Math\BigInteger; use Ramsey\Uuid\Builder\DegradedUuidBuilder; use Ramsey\Uuid\Codec\CodecInterface; use Ramsey\Uuid\Codec\OrderedTimeCodec; use Ramsey\Uuid\Codec\TimestampFirstCombCodec; use Ramsey\Uuid\Converter\Number\DegradedNumberConverter; use Ramsey\Uuid\Converter\Time\DegradedTimeConverter; use Ramsey\Uuid\Converter\TimeConverterInterface; use Ramsey\Uuid\DegradedUuid; use Ramsey\Uuid\Generator\CombGenerator; use Ramsey\Uuid\Generator\DefaultTimeGenerator; use Ramsey\Uuid\Math\BrickMathCalculator; use Ramsey\Uuid\Type\Hexadecimal; use Ramsey\Uuid\Type\Time; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidFactory; use stdClass; class ExpectedBehaviorTest extends TestCase { public function testStaticCreationMethodsAndStandardBehavior($method, $args) { $uuid = call_user_func_array(array("\122\141\155\x73\145\171\134\x55\165\x69\x64\x5c\125\x75\151\144", $method), $args); $this->assertInstanceOf("\122\141\x6d\x73\145\171\134\x55\x75\151\x64\134\125\165\x69\144\111\x6e\x74\x65\162\146\x61\143\x65", $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("\x52\x61\155\163\145\171\x5c\x55\165\151\x64\x5c\103\x6f\x6e\166\x65\162\x74\145\x72\134\116\x75\155\142\x65\x72\103\x6f\x6e\x76\x65\162\x74\x65\x72\x49\x6e\x74\145\x72\146\141\143\145", $uuid->getNumberConverter()); $this->assertIsString((string) $uuid->getHex()); $this->assertIsArray($uuid->getFieldsHex()); $this->assertArrayHasKey("\164\151\155\145\137\154\157\167", $uuid->getFieldsHex()); $this->assertArrayHasKey("\x74\x69\x6d\x65\x5f\155\151\144", $uuid->getFieldsHex()); $this->assertArrayHasKey("\x74\151\x6d\x65\137\x68\x69\x5f\141\x6e\x64\137\166\145\x72\x73\151\157\x6e", $uuid->getFieldsHex()); $this->assertArrayHasKey("\x63\154\x6f\143\153\x5f\163\145\x71\137\150\x69\137\x61\156\x64\137\162\x65\163\145\x72\166\x65\144", $uuid->getFieldsHex()); $this->assertArrayHasKey("\x63\x6c\157\x63\x6b\137\163\x65\x71\137\x6c\157\x77", $uuid->getFieldsHex()); $this->assertArrayHasKey("\x6e\157\144\x65", $uuid->getFieldsHex()); $this->assertIsString($uuid->getTimeLowHex()); $this->assertIsString($uuid->getTimeMidHex()); $this->assertIsString($uuid->getTimeHiAndVersionHex()); $this->assertIsString($uuid->getClockSeqHiAndReservedHex()); $this->assertIsString($uuid->getClockSeqLowHex()); $this->assertIsString($uuid->getNodeHex()); $this->assertSame($uuid->getFieldsHex()["\164\x69\155\145\x5f\x6c\x6f\167"], $uuid->getTimeLowHex()); $this->assertSame($uuid->getFieldsHex()["\164\x69\x6d\x65\x5f\155\151\x64"], $uuid->getTimeMidHex()); $this->assertSame($uuid->getFieldsHex()["\164\151\155\x65\x5f\150\151\x5f\141\156\144\137\166\145\162\x73\x69\157\156"], $uuid->getTimeHiAndVersionHex()); $this->assertSame($uuid->getFieldsHex()["\x63\x6c\157\x63\153\137\163\145\161\x5f\x68\x69\x5f\x61\156\144\137\x72\145\163\x65\x72\x76\145\x64"], $uuid->getClockSeqHiAndReservedHex()); $this->assertSame($uuid->getFieldsHex()["\143\154\x6f\143\x6b\137\x73\x65\x71\x5f\x6c\x6f\x77"], $uuid->getClockSeqLowHex()); $this->assertSame($uuid->getFieldsHex()["\156\x6f\x64\x65"], $uuid->getNodeHex()); $this->assertSame(substr((string) $uuid->getHex(), 16), $uuid->getLeastSignificantBitsHex()); $this->assertSame(substr((string) $uuid->getHex(), 0, 16), $uuid->getMostSignificantBitsHex()); $this->assertSame((string) $uuid->getHex(), $uuid->getTimeLowHex() . $uuid->getTimeMidHex() . $uuid->getTimeHiAndVersionHex() . $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex() . $uuid->getNodeHex()); $this->assertSame((string) $uuid->getHex(), $uuid->getFieldsHex()["\x74\x69\x6d\145\137\154\157\x77"] . $uuid->getFieldsHex()["\x74\151\155\x65\137\155\x69\144"] . $uuid->getFieldsHex()["\164\151\155\x65\x5f\150\x69\x5f\141\x6e\144\x5f\166\x65\x72\x73\151\157\x6e"] . $uuid->getFieldsHex()["\x63\x6c\x6f\x63\x6b\x5f\163\x65\161\137\x68\x69\x5f\141\x6e\x64\x5f\162\x65\x73\145\x72\166\x65\144"] . $uuid->getFieldsHex()["\x63\154\x6f\x63\153\137\x73\145\x71\x5f\x6c\x6f\x77"] . $uuid->getFieldsHex()["\156\157\x64\145"]); $this->assertIsString($uuid->getUrn()); $this->assertStringStartsWith("\x75\162\156\72\165\165\x69\x64\72", $uuid->getUrn()); $this->assertSame("\x75\x72\x6e\72\x75\x75\x69\144\x3a" . (string) $uuid->getHex(), str_replace("\x2d", '', $uuid->getUrn())); $this->assertSame((string) $uuid->getHex(), str_replace("\55", '', $uuid->toString())); $this->assertSame((string) $uuid->getHex(), str_replace("\55", '', (string) $uuid)); $this->assertSame($uuid->toString(), $uuid->getTimeLowHex() . "\x2d" . $uuid->getTimeMidHex() . "\x2d" . $uuid->getTimeHiAndVersionHex() . "\x2d" . $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex() . "\x2d" . $uuid->getNodeHex()); $this->assertSame((string) $uuid, $uuid->getTimeLowHex() . "\55" . $uuid->getTimeMidHex() . "\55" . $uuid->getTimeHiAndVersionHex() . "\x2d" . $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex() . "\x2d" . $uuid->getNodeHex()); $this->assertSame(2, $uuid->getVariant()); $this->assertSame((int) substr($method, -1), $uuid->getVersion()); $this->assertSame(1, preg_match("\57\x5e\134\144\x2b\x24\x2f", (string) $uuid->getInteger())); } public function provideStaticCreationMethods() { return array(array("\165\165\151\x64\x31", array()), array("\x75\165\151\x64\61", array("\x30\x30\x30\x30\60\x66\x66\146\146\146\146\146")), array("\165\165\151\144\61", array(null, 1234)), array("\x75\x75\151\x64\x31", array("\60\60\60\60\60\146\x66\x66\146\146\146\x66", 1234)), array("\x75\x75\151\x64\61", array("\x30\x30\60\x30\x30\x66\x66\146\146\146\x66\146", null)), array("\165\x75\x69\144\61", array(268435455)), array("\165\x75\151\x64\x31", array(268435455, 1234)), array("\x75\165\x69\144\61", array(268435455, null)), array("\165\x75\x69\144\63", array(Uuid::NAMESPACE_URL, "\x68\164\164\160\163\x3a\57\57\145\x78\x61\155\160\154\145\56\x63\x6f\x6d\x2f\146\x6f\x6f")), array("\x75\165\x69\144\x34", array()), array("\165\165\x69\144\x35", array(Uuid::NAMESPACE_URL, "\x68\164\164\160\163\x3a\x2f\x2f\145\170\141\x6d\160\x6c\x65\56\143\x6f\155\x2f\x66\x6f\x6f"))); } public function testUuidVersion1MethodBehavior() { $uuid = Uuid::uuid1("\x30\x30\x30\x30\x30\146\146\x66\146\146\146\146", 65535); $this->assertInstanceOf("\104\141\x74\145\x54\151\x6d\145\x49\156\x74\145\x72\x66\x61\143\145", $uuid->getDateTime()); $this->assertSame("\60\60\60\60\x30\146\146\x66\x66\146\146\x66", $uuid->getNodeHex()); $this->assertSame("\63\146\x66\x66", $uuid->getClockSequenceHex()); $this->assertSame("\61\66\63\70\x33", (string) $uuid->getClockSequence()); } public function testUuidVersion1MethodBehavior64Bit() { $uuid = Uuid::uuid1("\146\146\x66\x66\x66\146\146\x66\146\146\x66\146", 65535); $this->assertInstanceOf("\x44\x61\x74\145\x54\151\x6d\145\x49\x6e\x74\145\x72\146\x61\143\x65", $uuid->getDateTime()); $this->assertSame("\x66\146\x66\x66\x66\x66\146\146\146\146\146\x66", $uuid->getNodeHex()); $this->assertSame("\x32\70\61\x34\67\x34\71\67\x36\x37\x31\x30\66\x35\x35", (string) $uuid->getNode()); $this->assertSame("\x33\x66\146\146", $uuid->getClockSequenceHex()); $this->assertSame("\x31\66\63\70\x33", (string) $uuid->getClockSequence()); $this->assertSame(1, preg_match("\57\x5e\x5c\144\x2b\x24\x2f", (string) $uuid->getTimestamp())); } public function testIsValid($uuid, $expected) { $this->assertSame($expected, Uuid::isValid($uuid), "{$uuid}\x20\151\163\40\x6e\x6f\x74\40\141\x20\x76\141\154\151\144\x20\x55\125\x49\104"); $this->assertSame($expected, Uuid::isValid(strtoupper($uuid)), strtoupper($uuid) . "\40\x69\x73\40\156\x6f\164\40\141\40\x76\x61\154\151\144\40\125\x55\111\104"); } public function provideIsValid() { return array(array("\x30\x30\x30\x30\x30\60\x30\x30\x2d\60\x30\60\x30\55\x30\60\x30\x30\55\60\60\x30\x30\55\x30\x30\60\x30\x30\x30\x30\x30\x30\60\x30\60", true), array("\146\x66\66\x66\x38\x63\x62\x30\x2d\x63\x35\67\x64\55\61\61\x65\61\x2d\x38\x62\62\x31\x2d\x30\70\60\x30\x32\x30\x30\x63\71\x61\x36\66", true), array("\x66\146\x36\x66\x38\x63\x62\60\55\143\x35\67\144\x2d\61\x31\x65\x31\x2d\71\x62\62\61\55\60\70\x30\x30\62\x30\60\x63\71\x61\66\x36", true), array("\x66\x66\x36\x66\70\x63\x62\60\x2d\x63\65\67\x64\55\x31\61\145\61\55\x61\142\62\x31\55\x30\x38\60\60\62\60\60\143\71\x61\x36\66", true), array("\146\x66\x36\x66\x38\x63\142\60\x2d\143\65\x37\x64\x2d\x31\x31\x65\x31\x2d\142\142\62\61\55\60\x38\60\60\62\x30\x30\143\x39\x61\x36\x36", true), array("\146\x66\x36\x66\70\143\x62\60\55\143\65\67\144\x2d\x32\x31\145\61\55\70\x62\x32\61\x2d\60\x38\60\60\x32\60\x30\143\71\x61\66\66", true), array("\146\x66\x36\146\70\x63\142\60\55\x63\x35\67\x64\x2d\x32\61\145\61\55\71\x62\62\61\55\x30\70\60\x30\62\60\x30\x63\71\x61\x36\66", true), array("\146\x66\66\146\x38\143\142\60\x2d\143\65\67\x64\x2d\x32\61\145\61\55\x61\142\x32\x31\x2d\x30\x38\60\x30\x32\x30\60\143\x39\x61\x36\66", true), array("\146\146\66\x66\70\143\x62\60\55\x63\x35\67\144\55\62\61\x65\x31\x2d\x62\142\x32\x31\55\60\70\x30\x30\x32\x30\60\143\x39\141\66\x36", true), array("\x66\x66\x36\146\x38\x63\x62\60\55\143\x35\x37\144\x2d\x33\x31\145\x31\55\70\142\62\x31\55\60\70\x30\x30\62\x30\60\143\71\141\66\x36", true), array("\x66\x66\66\x66\70\x63\x62\60\55\143\x35\x37\144\55\x33\x31\x65\61\55\x39\x62\x32\x31\x2d\60\x38\x30\60\62\60\60\143\x39\141\66\66", true), array("\146\146\66\x66\70\x63\142\60\x2d\x63\65\67\x64\55\63\x31\145\x31\55\x61\x62\62\x31\x2d\60\70\x30\x30\62\x30\x30\143\71\x61\x36\x36", true), array("\146\146\66\x66\x38\143\x62\x30\55\143\x35\x37\144\55\x33\x31\145\61\x2d\x62\x62\62\61\55\x30\70\x30\60\x32\x30\x30\x63\x39\141\x36\x36", true), array("\x66\146\x36\146\x38\x63\x62\60\x2d\143\65\x37\144\55\x34\x31\x65\61\55\x38\x62\62\61\55\60\70\x30\60\x32\x30\60\x63\71\141\x36\66", true), array("\146\146\x36\x66\70\143\x62\x30\55\143\x35\67\144\55\x34\61\145\61\x2d\71\x62\x32\61\55\x30\x38\60\x30\x32\60\x30\x63\x39\x61\66\66", true), array("\146\146\x36\146\x38\143\142\60\x2d\143\x35\67\x64\55\64\61\x65\61\55\x61\142\x32\x31\55\x30\x38\x30\x30\x32\x30\x30\143\71\141\x36\x36", true), array("\x66\146\66\146\70\143\142\x30\55\143\65\x37\x64\x2d\x34\x31\x65\61\55\x62\x62\62\x31\x2d\x30\x38\60\60\62\x30\x30\143\x39\141\x36\66", true), array("\146\146\66\x66\x38\x63\142\x30\55\143\x35\x37\144\55\65\61\145\61\x2d\70\142\x32\x31\55\60\70\60\x30\62\60\x30\143\x39\141\66\x36", true), array("\146\146\x36\x66\70\x63\142\60\55\143\65\x37\144\55\65\x31\x65\x31\55\71\142\62\x31\55\60\x38\60\x30\x32\x30\x30\x63\71\x61\x36\66", true), array("\146\x66\66\x66\70\x63\142\x30\x2d\x63\x35\x37\144\x2d\x35\x31\x65\x31\x2d\x61\142\62\x31\55\x30\70\60\60\62\60\60\143\71\141\66\66", true), array("\x66\x66\66\x66\70\x63\x62\x30\55\x63\65\67\x64\x2d\65\61\145\61\x2d\142\x62\x32\x31\55\x30\70\60\x30\62\60\x30\143\x39\141\x36\x36", true), array("\x66\x66\x66\146\146\146\146\x66\x2d\x66\146\x66\146\55\x66\146\x66\146\x2d\x66\x66\146\x66\x2d\146\146\x66\x66\x66\x66\146\x66\146\x66\x66\x66", true), array("\60\60\x30\x30\x30\x30\60\x30\55\x30\x30\x30\x30\55\60\60\x30\60\55\60\x30\60\x30\55\60\x30\60\x30\60\60\60\x30\60\x30\60\60", true), array("\146\x66\x36\146\x38\143\142\x30\55\x63\65\67\144\55\x30\61\145\61\x2d\x30\142\x32\x31\x2d\x30\70\x30\x30\62\x30\60\143\71\x61\x36\66", true), array("\146\146\66\x66\x38\143\x62\x30\55\143\x35\x37\144\55\60\61\x65\x31\x2d\x31\142\62\61\55\60\x38\60\60\62\60\x30\143\x39\141\x36\x36", true), array("\146\146\x36\146\x38\143\142\60\x2d\x63\65\67\144\x2d\x30\x31\145\61\55\62\x62\x32\61\x2d\60\x38\x30\60\x32\60\x30\143\x39\x61\x36\66", true), array("\x66\x66\x36\x66\70\143\142\x30\55\x63\65\67\x64\x2d\x30\x31\x65\61\x2d\x33\x62\x32\61\x2d\60\x38\x30\60\x32\60\60\x63\x39\141\x36\x36", true), array("\146\146\66\x66\70\x63\142\60\55\x63\x35\67\144\55\x30\x31\145\61\55\64\142\62\x31\x2d\60\x38\x30\60\62\60\x30\x63\x39\141\x36\x36", true), array("\x66\146\x36\x66\x38\x63\x62\x30\x2d\x63\65\x37\x64\x2d\60\x31\x65\61\55\65\x62\62\x31\x2d\x30\x38\x30\x30\62\x30\60\143\x39\141\x36\x36", true), array("\146\146\x36\146\x38\x63\x62\60\x2d\x63\65\x37\144\55\x30\x31\145\61\x2d\66\x62\x32\x31\55\60\70\x30\x30\x32\x30\60\x63\71\141\66\x36", true), array("\x66\146\66\x66\70\x63\142\x30\x2d\143\65\x37\x64\55\60\x31\x65\61\x2d\67\x62\x32\61\55\x30\x38\x30\x30\x32\60\60\143\x39\x61\66\x36", true), array("\146\146\66\146\70\143\142\x30\55\143\65\67\x64\x2d\60\61\x65\61\55\144\x62\x32\61\x2d\x30\x38\60\60\62\x30\x30\x63\71\141\x36\66", true), array("\146\x66\66\146\x38\143\x62\x30\55\x63\x35\x37\x64\55\60\61\x65\61\x2d\x65\142\62\61\x2d\60\70\60\x30\62\60\60\x63\x39\x61\x36\x36", true), array("\146\x66\x36\146\x38\x63\142\x30\55\x63\65\67\x64\55\60\x31\x65\61\x2d\146\x62\x32\61\x2d\60\x38\x30\x30\62\60\60\x63\x39\141\66\66", true), array("\x7b\x66\x66\x36\146\70\x63\x62\x30\55\143\x35\x37\x64\x2d\60\61\x65\x31\55\146\x62\62\x31\x2d\x30\x38\60\60\62\60\60\143\71\141\x36\x36\x7d", true), array("\x75\162\156\72\165\x75\151\144\72\x66\x66\66\146\x38\x63\x62\60\55\143\65\x37\144\55\x30\61\x65\61\x2d\x66\142\62\61\x2d\60\70\x30\x30\x32\60\60\x63\71\x61\66\x36", true), array("\146\x66\x66\x66\146\146\146\146\146\x66\x66\x66\146\146\146\x66\146\x66\146\146\146\146\x66\x66\146\146\146\146\x66\146\x66\146", false), array("\x30\x30\x30\60\x30\x30\x30\x30\x30\60\x30\x30\x30\x30\x30\x30\x30\x30\x30\60\x30\x30\x30\60\x30\x30\x30\x30\x30\60\x30\x30", false), array(0, false), array("\146\157\157\142\141\162", false), array("\146\146\66\x66\70\x63\x62\60\x63\x35\x37\144\x35\61\145\x31\x62\x62\62\x31\60\x38\x30\x30\x32\x30\60\x63\x39\x61\66\x36", false), array("\147\x66\x36\x66\x38\x63\x62\x30\x2d\x63\65\67\144\55\65\61\x65\x31\x2d\x62\x62\62\x31\55\x30\70\x30\x30\62\x30\60\143\71\141\x36\66", false)); } public function testSerialization($string) { $uuid = Uuid::fromString($string); $serialized = serialize($uuid); $unserialized = unserialize($serialized); $this->assertSame(0, $uuid->compareTo($unserialized)); $this->assertTrue($uuid->equals($unserialized)); $this->assertSame("\x22{$string}\x22", json_encode($uuid)); } public function testSerializationWithOrderedTimeCodec($string) { $factory = new UuidFactory(); $factory->setCodec(new OrderedTimeCodec($factory->getUuidBuilder())); $previousFactory = Uuid::getFactory(); Uuid::setFactory($factory); $uuid = Uuid::fromString($string); $serialized = serialize($uuid); $unserialized = unserialize($serialized); Uuid::setFactory($previousFactory); $this->assertSame(0, $uuid->compareTo($unserialized)); $this->assertTrue($uuid->equals($unserialized)); $this->assertSame("\42{$string}\42", json_encode($uuid)); } public function testNumericReturnValues($string) { $leastSignificantBitsHex = substr(str_replace("\55", '', $string), 16); $mostSignificantBitsHex = substr(str_replace("\55", '', $string), 0, 16); $leastSignificantBits = BigInteger::fromBase($leastSignificantBitsHex, 16)->__toString(); $mostSignificantBits = BigInteger::fromBase($mostSignificantBitsHex, 16)->__toString(); $components = explode("\55", $string); array_walk($components, function (&$value) { $value = BigInteger::fromBase($value, 16)->__toString(); }); if (strtolower($string) === Uuid::MAX) { $clockSeq = (int) $components[3]; } else { $clockSeq = (int) $components[3] & 16383; } $clockSeqHiAndReserved = (int) $components[3] >> 8; $clockSeqLow = (int) $components[3] & 255; $uuid = Uuid::fromString($string); $this->assertSame($components[0], (string) $uuid->getTimeLow()); $this->assertSame($components[1], (string) $uuid->getTimeMid()); $this->assertSame($components[2], (string) $uuid->getTimeHiAndVersion()); $this->assertSame((string) $clockSeq, (string) $uuid->getClockSequence()); $this->assertSame((string) $clockSeqHiAndReserved, (string) $uuid->getClockSeqHiAndReserved()); $this->assertSame((string) $clockSeqLow, (string) $uuid->getClockSeqLow()); $this->assertSame($components[4], (string) $uuid->getNode()); $this->assertSame($leastSignificantBits, (string) $uuid->getLeastSignificantBits()); $this->assertSame($mostSignificantBits, (string) $uuid->getMostSignificantBits()); } public function testFromBytes($string, $version, $variant, $integer) { $bytes = hex2bin(str_replace("\55", '', $string)); $uuid = Uuid::fromBytes($bytes); $this->assertInstanceOf("\x52\x61\x6d\x73\x65\171\x5c\x55\165\x69\144\134\x55\165\151\x64\111\x6e\164\x65\x72\x66\141\143\145", $uuid); $this->assertSame($string, $uuid->toString()); $this->assertSame($version, $uuid->getVersion()); $this->assertSame($variant, $uuid->getVariant()); $components = explode("\x2d", $string); $this->assertSame($components[0], $uuid->getTimeLowHex()); $this->assertSame($components[1], $uuid->getTimeMidHex()); $this->assertSame($components[2], $uuid->getTimeHiAndVersionHex()); $this->assertSame($components[3], $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex()); $this->assertSame($components[4], $uuid->getNodeHex()); $this->assertSame($integer, (string) $uuid->getInteger()); $this->assertSame($bytes, $uuid->getBytes()); } public function testFromInteger($string, $version, $variant, $integer) { $bytes = hex2bin(str_replace("\x2d", '', $string)); $uuid = Uuid::fromInteger($integer); $this->assertInstanceOf("\x52\141\155\163\145\171\x5c\125\x75\151\144\134\125\165\151\x64\x49\x6e\164\145\x72\146\141\x63\145", $uuid); $this->assertSame($string, $uuid->toString()); $this->assertSame($version, $uuid->getVersion()); $this->assertSame($variant, $uuid->getVariant()); $components = explode("\x2d", $string); $this->assertSame($components[0], $uuid->getTimeLowHex()); $this->assertSame($components[1], $uuid->getTimeMidHex()); $this->assertSame($components[2], $uuid->getTimeHiAndVersionHex()); $this->assertSame($components[3], $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex()); $this->assertSame($components[4], $uuid->getNodeHex()); $this->assertSame($integer, (string) $uuid->getInteger()); $this->assertSame($bytes, $uuid->getBytes()); } public function testFromString($string, $version, $variant, $integer) { $bytes = hex2bin(str_replace("\55", '', $string)); $uuid = Uuid::fromString($string); $this->assertInstanceOf("\122\x61\155\x73\145\171\x5c\125\165\151\x64\x5c\125\165\151\x64\111\156\164\x65\162\146\141\143\145", $uuid); $this->assertSame($string, $uuid->toString()); $this->assertSame($version, $uuid->getVersion()); $this->assertSame($variant, $uuid->getVariant()); $components = explode("\x2d", $string); $this->assertSame($components[0], $uuid->getTimeLowHex()); $this->assertSame($components[1], $uuid->getTimeMidHex()); $this->assertSame($components[2], $uuid->getTimeHiAndVersionHex()); $this->assertSame($components[3], $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex()); $this->assertSame($components[4], $uuid->getNodeHex()); $this->assertSame($integer, (string) $uuid->getInteger()); $this->assertSame($bytes, $uuid->getBytes()); } public function provideFromStringInteger() { return array(array("\60\60\60\x30\60\x30\x30\60\x2d\60\60\60\60\55\x30\60\x30\x30\x2d\x30\x30\x30\x30\x2d\x30\60\x30\x30\x30\60\60\60\x30\60\x30\60", null, 2, "\60"), array("\x66\x66\66\146\70\x63\x62\60\55\x63\x35\x37\x64\55\x31\x31\x65\x31\x2d\70\x62\x32\x31\55\x30\x38\x30\60\x32\60\x30\143\71\141\66\66", 1, 2, "\x33\x33\71\65\x33\x32\63\x33\67\x34\61\x39\60\67\61\67\67\x34\63\x30\x34\x36\65\60\x31\x39\60\61\x33\x39\63\61\70\x36\x33\x39\62\x30\x36"), array("\x66\x66\66\x66\x38\x63\142\60\55\143\65\x37\x64\x2d\61\61\145\x31\x2d\x39\x62\x32\61\x2d\60\70\x30\60\x32\60\x30\143\x39\x61\x36\x36", 1, 2, "\63\63\x39\65\x33\x32\x33\x33\67\x34\x31\x39\60\x37\61\x37\x37\64\x33\x30\x35\x38\60\x33\x31\x31\x31\x36\64\63\71\x32\x35\64\70\x36\61\70\x32"), array("\x66\x66\x36\x66\x38\143\142\x30\x2d\143\x35\67\x64\x2d\61\x31\x65\61\x2d\141\142\x32\61\55\x30\70\60\x30\62\x30\x30\143\x39\x61\x36\66", 1, 2, "\x33\x33\x39\65\x33\62\63\63\x37\x34\x31\x39\x30\67\x31\67\x37\64\x33\x30\x36\71\x35\x36\60\x33\63\x31\x34\70\x35\63\62\63\x33\x33\61\x35\70"), array("\x66\146\66\146\x38\x63\142\x30\55\143\x35\x37\144\55\61\x31\x65\61\x2d\x62\142\62\61\55\60\x38\x30\60\62\60\60\x63\x39\141\66\x36", 1, 2, "\x33\x33\71\65\63\x32\63\x33\67\64\x31\71\x30\67\61\x37\67\64\63\x30\70\61\x30\70\71\65\64\66\x35\x33\x31\63\71\61\70\60\61\x33\x34"), array("\146\x66\66\x66\70\143\142\x30\55\x63\65\x37\x64\x2d\x32\61\x65\61\55\70\x62\62\61\x2d\60\x38\x30\x30\62\x30\x30\143\71\141\66\x36", 2, 2, "\63\63\x39\x35\x33\62\63\x33\67\x34\61\x39\60\x37\61\70\x34\71\70\x36\62\65\61\x33\71\x31\66\60\x35\63\x36\64\x32\x30\x35\70\x33\x34\62"), array("\x66\x66\66\146\70\143\x62\x30\x2d\x63\65\x37\144\55\x32\x31\145\x31\x2d\x39\x62\x32\x31\x2d\60\x38\x30\x30\62\60\60\x63\71\x61\66\x36", 2, 2, "\63\x33\x39\65\x33\62\x33\63\67\64\61\x39\x30\x37\61\x38\64\x39\x38\x36\x33\66\x36\66\x38\x33\67\x35\x35\x38\x32\64\70\71\60\x35\63\61\70"), array("\x66\x66\66\x66\70\143\x62\x30\x2d\x63\65\x37\x64\55\62\61\145\x31\55\141\142\62\61\55\60\x38\x30\60\x32\x30\60\x63\x39\141\66\66", 2, 2, "\63\x33\71\65\63\62\63\x33\67\x34\x31\71\x30\x37\x31\x38\x34\71\x38\x36\64\x38\x31\71\67\x35\71\x30\66\62\70\65\65\67\65\62\x32\71\64"), array("\x66\x66\66\x66\x38\143\142\60\55\x63\65\67\144\x2d\62\61\x65\x31\55\x62\x62\x32\61\x2d\60\70\x30\x30\62\60\x30\143\x39\x61\x36\66", 2, 2, "\x33\x33\x39\65\x33\62\x33\63\x37\64\x31\x39\x30\x37\61\70\x34\71\70\x36\x35\71\x37\x32\66\x38\x30\65\x36\67\64\66\62\x35\71\x39\62\x37\x30"), array("\x66\x66\66\146\70\x63\x62\x30\55\143\65\67\144\55\63\x31\145\x31\55\x38\x62\62\x31\55\60\70\60\60\x32\x30\60\x63\x39\141\x36\x36", 3, 2, "\x33\x33\x39\65\63\x32\x33\x33\67\x34\61\x39\x30\x37\61\71\x32\65\64\62\60\x33\x37\x37\66\64\61\71\66\67\x39\x36\x35\64\x37\67\64\x37\70"), array("\146\x66\x36\x66\x38\x63\x62\60\x2d\x63\x35\x37\x64\55\63\61\145\61\x2d\x39\x62\62\61\55\60\70\x30\x30\x32\x30\x30\x63\71\x61\x36\66", 3, 2, "\63\63\71\x35\63\62\63\63\67\64\x31\71\x30\67\x31\71\x32\x35\x34\x32\x31\x35\63\x30\65\66\63\x34\67\62\x35\67\x32\x33\x32\64\x34\x35\x34"), array("\146\146\66\146\x38\143\142\x30\55\143\x35\x37\144\x2d\x33\x31\145\x31\x2d\141\x62\x32\61\55\60\x38\x30\60\62\x30\x30\x63\71\141\x36\x36", 3, 2, "\x33\x33\x39\x35\63\62\x33\63\67\64\x31\x39\x30\67\61\71\x32\x35\64\x32\62\66\70\x33\x34\70\64\x39\x37\x37\61\x37\x39\61\67\61\64\x33\60"), array("\x66\146\x36\x66\70\143\142\x30\55\x63\65\67\x64\55\x33\61\145\x31\x2d\142\x62\62\x31\x2d\60\70\x30\60\x32\x30\60\x63\71\x61\x36\x36", 3, 2, "\x33\x33\x39\x35\x33\x32\x33\x33\x37\64\61\x39\60\67\x31\x39\x32\x35\64\x32\x33\70\x33\x36\x34\x30\x36\64\x38\x31\67\70\66\60\61\x38\x34\x30\66"), array("\x66\146\66\x66\70\143\x62\60\x2d\x63\65\67\x64\55\x34\x31\145\61\x2d\70\x62\x32\61\x2d\60\70\60\60\62\x30\60\x63\71\x61\66\66", 4, 2, "\63\63\x39\65\x33\62\x33\x33\x37\x34\61\x39\60\x37\x32\x30\60\x30\x39\67\70\x32\64\61\x33\x36\67\x38\x38\x32\x32\70\70\70\x39\66\66\61\x34"), array("\x66\x66\x36\x66\70\x63\142\60\55\143\65\67\x64\x2d\64\x31\x65\61\55\x39\x62\x32\61\x2d\x30\x38\60\60\62\x30\60\143\71\141\66\x36", 4, 2, "\63\x33\71\65\63\62\63\x33\x37\x34\61\x39\60\67\62\x30\60\60\x39\x37\x39\63\x39\64\x32\x38\x39\x33\x38\x36\70\71\x35\67\x34\63\65\71\x30"), array("\x66\x66\x36\x66\x38\143\x62\60\x2d\143\65\67\x64\55\x34\61\x65\61\x2d\141\x62\x32\x31\55\60\x38\60\60\x32\x30\60\143\71\x61\x36\x36", 4, 2, "\x33\63\71\x35\x33\x32\x33\x33\67\x34\61\71\60\67\62\60\60\x30\71\70\60\x35\64\67\x32\61\x30\70\x39\61\65\x30\x32\x35\71\60\x35\x36\x36"), array("\x66\x66\x36\146\70\143\142\60\55\x63\65\67\x64\x2d\64\x31\x65\61\x2d\142\x62\62\x31\55\60\70\60\60\62\60\x30\143\71\x61\x36\x36", 4, 2, "\x33\63\71\65\x33\x32\63\x33\x37\x34\x31\71\x30\x37\62\60\x30\60\71\70\x31\x37\x30\60\61\63\62\x33\x39\66\61\x30\x39\x34\63\x37\x35\x34\x32"), array("\146\146\x36\x66\70\x63\142\60\55\143\x35\67\x64\x2d\x35\61\145\61\55\x38\x62\62\x31\55\x30\x38\60\60\62\60\x30\143\71\141\x36\66", 5, 2, "\x33\x33\71\65\x33\x32\63\x33\67\x34\x31\71\60\67\62\x30\67\x36\65\x33\66\61\60\65\60\71\63\67\71\66\x36\x31\x32\x33\x31\65\x37\x35\60"), array("\146\x66\66\x66\70\x63\142\x30\x2d\x63\x35\x37\x64\55\65\61\145\x31\55\71\x62\62\61\x2d\60\x38\60\60\62\x30\60\143\x39\x61\x36\x36", 5, 2, "\x33\x33\71\x35\63\62\x33\63\67\64\61\x39\x30\67\62\x30\x37\x36\x35\x33\x37\x32\65\70\60\x31\x35\63\x30\61\62\61\71\x31\x36\62\x37\x32\x36"), array("\x66\146\66\146\70\x63\x62\60\55\143\65\x37\144\x2d\x35\61\145\61\x2d\141\x62\62\x31\x2d\60\70\60\60\62\x30\60\143\71\141\66\66", 5, 2, "\63\63\x39\65\63\x32\x33\x33\x37\x34\61\x39\x30\67\x32\60\67\x36\x35\x33\70\x34\x31\60\71\x33\x36\70\x30\x35\70\x32\66\60\60\71\67\x30\62"), array("\x66\146\x36\x66\x38\143\142\x30\x2d\x63\65\x37\144\x2d\x35\61\145\61\x2d\x62\x62\62\x31\55\60\70\x30\x30\x32\60\x30\143\x39\141\66\x36", 5, 2, "\63\x33\x39\65\63\x32\x33\x33\x37\x34\61\71\x30\x37\x32\60\x37\66\65\63\71\x35\x36\x33\x38\x35\x38\63\61\x30\64\x33\x32\70\x35\66\x36\x37\70"), array("\x66\x66\66\x66\70\143\x62\60\55\143\x35\67\144\55\60\x31\145\x31\x2d\x30\142\x32\x31\55\60\70\x30\60\x32\x30\60\143\71\x61\x36\x36", null, 0, "\63\x33\x39\x35\63\62\x33\x33\x37\64\x31\71\x30\x37\61\66\x39\x38\67\x33\x37\x35\66\x33\60\x39\62\x31\70\x38\x31\64\x30\x34\x34\64\x32\x36\x32"), array("\x66\146\x36\x66\x38\x63\x62\x30\55\143\x35\x37\144\x2d\x30\x31\145\x31\x2d\x31\x62\62\61\x2d\60\70\60\60\62\x30\x30\143\71\x61\66\x36", null, 0, "\63\63\x39\65\63\62\x33\63\x37\x34\x31\71\x30\67\x31\x36\71\x38\67\63\x38\67\x31\66\x30\61\x33\66\x39\62\67\64\x37\x32\71\x31\x32\63\70"), array("\146\146\x36\x66\x38\143\142\x30\55\x63\x35\x37\x64\55\60\x31\145\61\x2d\62\x62\x32\x31\55\x30\70\60\60\62\60\x30\143\x39\141\66\x36", null, 0, "\x33\63\x39\x35\63\62\63\63\67\x34\61\x39\60\67\61\x36\x39\x38\67\63\x39\x38\66\x38\71\63\65\x31\x39\67\63\x35\x34\61\63\70\62\61\x34"), array("\x66\x66\x36\x66\x38\143\x62\60\55\143\x35\67\x64\x2d\x30\61\145\x31\55\x33\142\62\x31\x2d\60\x38\x30\60\62\x30\x30\x63\x39\x61\x36\x36", null, 0, "\63\63\x39\x35\63\62\x33\x33\x37\x34\61\x39\x30\67\x31\66\71\70\x37\64\x31\x30\x32\x31\70\x35\x36\x37\x30\61\71\x36\60\71\70\x35\x31\71\x30"), array("\146\x66\x36\146\70\x63\x62\x30\55\143\65\67\x64\x2d\x30\x31\x65\x31\55\x34\142\62\x31\x2d\x30\70\60\60\x32\x30\x30\143\x39\x61\66\x36", null, 0, "\63\x33\x39\65\63\x32\x33\63\x37\x34\x31\x39\x30\x37\x31\x36\x39\x38\x37\64\x32\x31\x37\x34\x37\x37\70\62\x30\66\65\x36\67\x38\x33\62\61\66\x36"), array("\146\x66\x36\146\70\x63\142\60\x2d\x63\65\x37\x64\55\x30\61\x65\x31\x2d\65\142\62\61\x2d\x30\70\60\60\62\x30\x30\x63\x39\141\x36\66", null, 0, "\63\63\71\65\63\62\63\x33\x37\64\x31\x39\60\x37\x31\x36\71\x38\x37\64\x33\63\62\x37\x36\x39\x39\x37\x31\x31\61\x37\x34\x36\67\x39\61\x34\x32"), array("\x66\x66\66\146\x38\143\142\60\x2d\x63\x35\x37\x64\x2d\x30\61\x65\61\x2d\66\x62\62\x31\x2d\x30\70\x30\x30\x32\x30\60\x63\71\141\x36\66", null, 0, "\x33\63\x39\65\63\62\x33\x33\67\64\61\71\x30\x37\61\x36\x39\70\x37\64\64\64\x38\x30\x36\x32\x31\x32\x31\x35\67\x38\x31\x35\62\66\61\61\70"), array("\x66\146\66\x66\x38\x63\x62\60\55\x63\x35\x37\x64\55\x30\x31\x65\x31\55\x37\x62\x32\61\x2d\60\70\60\60\x32\x30\x30\x63\x39\x61\x36\x36", null, 0, "\x33\x33\x39\x35\63\62\63\x33\x37\64\61\71\60\x37\x31\66\71\70\x37\x34\65\x36\x33\63\x35\64\x32\67\x32\60\63\x38\70\x33\x37\x33\60\71\x34"), array("\x66\146\66\146\x38\143\142\60\55\143\x35\67\x64\x2d\x30\61\145\x31\55\x63\142\62\61\x2d\60\70\x30\60\62\60\x30\143\71\x61\66\66", null, 6, "\x33\x33\71\65\63\62\x33\x33\x37\64\61\71\x30\x37\x31\66\71\x38\67\x35\61\63\x39\x38\x31\65\x30\x32\x34\63\x34\x32\x32\66\60\x37\71\67\64"), array("\x66\x66\66\x66\x38\x63\x62\60\55\143\65\x37\144\x2d\x30\x31\x65\x31\x2d\144\142\x32\61\x2d\60\x38\60\x30\x32\60\x30\x63\x39\x61\x36\x36", null, 6, "\63\x33\x39\65\x33\x32\63\x33\x37\x34\x31\71\60\x37\x31\x36\x39\70\x37\65\x32\x35\x35\61\60\67\61\x37\64\70\x30\62\71\x34\x35\x34\71\65\x30"), array("\x66\146\66\x66\x38\x63\142\x30\55\x63\65\67\x64\55\60\61\145\x31\x2d\x65\142\x32\x31\55\x30\70\60\x30\x32\x30\x30\143\71\141\x36\x36", null, 7, "\63\63\71\x35\x33\62\63\63\67\x34\x31\71\x30\67\x31\66\71\x38\x37\x35\x33\67\60\63\x39\71\63\62\65\62\x36\63\x36\63\x30\x31\x39\x32\66"), array("\146\x66\x36\x66\70\x63\x62\x30\x2d\143\65\x37\144\x2d\x30\61\145\x31\55\x66\x62\x32\61\x2d\x30\70\60\60\62\60\60\x63\x39\141\x36\66", null, 7, "\x33\x33\71\x35\x33\x32\63\x33\x37\64\61\x39\x30\x37\x31\x36\71\70\67\65\64\x38\65\66\x39\x31\64\67\65\67\62\x34\x33\61\x34\70\x39\x30\x32"), array("\x66\146\x66\146\146\x66\x66\146\x2d\x66\146\x66\x66\x2d\x66\146\x66\146\x2d\x66\x66\146\146\55\x66\146\x66\x66\x66\146\146\x66\146\146\146\146", null, 2, "\63\64\x30\62\x38\62\x33\x36\66\x39\x32\x30\x39\x33\70\x34\66\x33\64\66\63\63\x37\64\66\x30\67\64\x33\61\67\x36\x38\62\61\x31\64\65\65")); } public function testGetSetFactory() { $this->assertInstanceOf("\x52\141\155\163\145\x79\134\x55\165\x69\x64\x5c\125\165\x69\144\x46\x61\x63\164\x6f\x72\x79", Uuid::getFactory()); $factory = \Mockery::mock("\122\141\x6d\163\145\x79\x5c\x55\165\x69\x64\134\x55\165\x69\x64\x46\141\143\164\x6f\x72\x79"); Uuid::setFactory($factory); $this->assertSame($factory, Uuid::getFactory()); } public function testFactoryProvidesFunctionality() { $uuid = \Mockery::mock("\x52\141\x6d\x73\x65\171\134\x55\165\x69\x64\134\125\x75\x69\x64\x49\156\x74\145\162\146\141\143\145"); $factory = \Mockery::mock("\x52\x61\155\163\145\171\x5c\x55\x75\151\x64\x5c\x55\x75\151\x64\x46\141\x63\164\157\x72\171\111\x6e\164\145\162\x66\x61\x63\145", array("\x75\x75\151\x64\x31" => $uuid, "\165\x75\151\144\63" => $uuid, "\x75\165\x69\x64\x34" => $uuid, "\165\165\151\144\x35" => $uuid, "\146\x72\157\x6d\x42\x79\x74\145\163" => $uuid, "\x66\162\x6f\x6d\123\164\162\151\x6e\x67" => $uuid, "\146\162\157\x6d\111\x6e\164\145\147\145\x72" => $uuid)); Uuid::setFactory($factory); $this->assertSame($uuid, Uuid::uuid1("\x66\146\146\x66\146\146\146\x66\146\146\x66\146", 65535)); $this->assertSame($uuid, Uuid::uuid3(Uuid::NAMESPACE_URL, "\150\164\164\160\163\x3a\57\x2f\145\x78\x61\155\x70\x6c\145\x2e\143\x6f\155\x2f\x66\x6f\157")); $this->assertSame($uuid, Uuid::uuid4()); $this->assertSame($uuid, Uuid::uuid5(Uuid::NAMESPACE_URL, "\x68\164\164\x70\163\72\x2f\57\x65\x78\141\x6d\x70\x6c\x65\56\x63\x6f\x6d\x2f\x66\157\x6f")); $this->assertSame($uuid, Uuid::fromBytes(hex2bin("\x66\146\146\146\x66\x66\x66\146\146\x66\x66\x66\146\x66\146\x66\x66\x66\146\146\x66\x66\x66\x66\x66\x66\146\146\146\146\x66\146"))); $this->assertSame($uuid, Uuid::fromString("\x66\146\x66\146\146\146\x66\x66\55\x66\146\146\x66\x2d\x66\x66\146\146\55\146\146\x66\146\x2d\x66\x66\146\x66\146\x66\146\x66\x66\146\146\x66")); $this->assertSame($uuid, Uuid::fromInteger("\63\64\x30\62\70\x32\63\x36\x36\x39\62\x30\71\63\x38\64\66\63\x34\x36\63\63\x37\x34\66\x30\67\64\63\61\x37\66\x38\62\x31\x31\64\65\65")); } public function testUsingDegradedFeatures() { $numberConverter = new DegradedNumberConverter(); $builder = new DegradedUuidBuilder($numberConverter); $factory = new UuidFactory(); $factory->setNumberConverter($numberConverter); $factory->setUuidBuilder($builder); Uuid::setFactory($factory); $uuid = Uuid::uuid1(); $this->assertInstanceOf("\122\141\155\163\145\171\x5c\x55\165\x69\x64\x5c\x55\165\x69\144\111\156\x74\145\162\x66\141\x63\145", $uuid); $this->assertInstanceOf("\122\x61\x6d\163\x65\x79\x5c\125\165\151\144\x5c\104\145\147\x72\141\x64\145\x64\x55\x75\151\x64", $uuid); $this->assertInstanceOf("\x52\x61\x6d\x73\x65\171\x5c\125\x75\x69\144\x5c\103\x6f\156\166\145\162\164\x65\162\x5c\x4e\165\x6d\x62\x65\x72\x5c\104\145\x67\x72\x61\x64\145\144\116\165\155\142\x65\162\x43\x6f\156\x76\145\162\164\x65\x72", $uuid->getNumberConverter()); } public function testUsingCustomCodec() { $mockUuid = \Mockery::mock("\x52\141\155\x73\x65\171\134\125\x75\151\144\x5c\125\x75\151\144\x49\156\x74\x65\x72\x66\141\x63\145"); $codec = \Mockery::mock("\122\141\x6d\x73\x65\x79\x5c\125\165\x69\144\134\103\157\x64\x65\x63\x5c\103\x6f\144\145\x63\x49\x6e\164\145\x72\146\141\143\145", array("\145\x6e\143\157\x64\145" => "\x61\x62\143\x64\61\62\63\x34", "\145\x6e\x63\157\x64\x65\102\151\156\141\x72\x79" => hex2bin("\x61\142\x63\144\61\x32\x33\64"), "\144\145\x63\x6f\144\x65" => $mockUuid, "\144\145\143\157\x64\145\102\x79\x74\145\x73" => $mockUuid)); $factory = new UuidFactory(); $factory->setCodec($codec); Uuid::setFactory($factory); $uuid = Uuid::uuid4(); $this->assertSame("\141\142\x63\x64\61\x32\63\x34", $uuid->toString()); $this->assertSame(hex2bin("\141\142\143\x64\61\62\63\64"), $uuid->getBytes()); $this->assertSame($mockUuid, Uuid::fromString("\x66\x30\60\142\141\x32")); $this->assertSame($mockUuid, Uuid::fromBytes(hex2bin("\146\x30\x30\142\x61\62"))); } public function testUsingCustomRandomGenerator() { $generator = \Mockery::mock("\x52\x61\155\x73\145\x79\x5c\x55\x75\x69\x64\x5c\107\x65\x6e\145\162\x61\x74\157\162\134\x52\x61\x6e\144\157\155\x47\x65\x6e\145\162\141\x74\157\162\111\x6e\x74\145\162\x66\141\x63\145", array("\x67\145\156\x65\162\141\x74\145" => hex2bin("\60\x31\x32\x33\x34\x35\x36\67\141\142\x63\144\65\64\x33\x32\144\143\142\x61\60\61\62\x33\64\x35\66\67\x38\71\x61\142"))); $factory = new UuidFactory(); $factory->setRandomGenerator($generator); Uuid::setFactory($factory); $uuid = Uuid::uuid4(); $this->assertSame("\x30\x31\x32\x33\64\65\x36\67\x2d\141\142\x63\x64\55\64\x34\63\x32\x2d\71\143\x62\x61\x2d\60\61\62\x33\x34\65\x36\67\x38\x39\141\x62", $uuid->toString()); } public function testUsingCustomTimeGenerator() { $generator = \Mockery::mock("\x52\141\x6d\163\145\x79\x5c\x55\x75\151\x64\134\x47\145\x6e\145\x72\x61\164\157\x72\x5c\124\151\x6d\x65\107\x65\x6e\x65\162\x61\164\157\162\x49\156\164\145\x72\x66\x61\x63\x65", array("\147\145\x6e\145\x72\x61\x74\x65" => hex2bin("\60\x31\62\63\64\x35\x36\x37\141\x62\143\x64\65\64\63\62\144\143\x62\x61\60\x31\x32\63\64\65\x36\x37\70\x39\141\142"))); $factory = new UuidFactory(); $factory->setTimeGenerator($generator); Uuid::setFactory($factory); $uuid = Uuid::uuid1(); $this->assertSame("\60\x31\62\x33\x34\x35\66\x37\55\x61\142\x63\x64\55\x31\x34\63\x32\55\x39\143\x62\141\55\x30\61\x32\63\64\65\66\x37\70\71\x61\142", $uuid->toString()); } public function testUsingDefaultTimeGeneratorWithCustomProviders() { $nodeProvider = \Mockery::mock("\x52\141\x6d\163\145\x79\134\125\x75\x69\x64\134\120\162\x6f\x76\151\x64\x65\162\134\116\x6f\144\145\x50\x72\157\x76\151\144\145\162\x49\x6e\x74\x65\162\x66\141\x63\145", array("\x67\145\164\116\x6f\144\x65" => new Hexadecimal("\x30\61\x32\x33\x34\65\x36\67\x38\x39\x61\142"))); $timeConverter = \Mockery::mock("\122\x61\155\163\145\171\x5c\x55\x75\151\x64\134\103\157\x6e\x76\145\162\x74\145\x72\134\x54\x69\x6d\x65\103\x6f\156\166\145\x72\x74\x65\162\x49\156\x74\x65\162\x66\x61\143\x65"); $timeConverter->shouldReceive("\143\x61\154\x63\x75\x6c\141\x74\x65\124\151\155\145")->andReturnUsing(function ($seconds, $microseconds) { return new Hexadecimal("\141\x62\x63\x64" . dechex($microseconds) . dechex($seconds)); }); $timeProvider = \Mockery::mock("\122\141\x6d\163\x65\x79\134\125\165\151\144\134\120\x72\157\166\151\x64\145\162\x5c\124\151\x6d\145\120\162\157\x76\x69\x64\x65\162\111\156\x74\x65\162\146\x61\143\145", array("\x63\165\x72\162\145\x6e\x74\124\151\155\145" => array("\x73\145\143" => 1578522046, "\165\163\145\x63" => 10000), "\147\145\164\x54\x69\155\145" => new Time(1578522046, 10000))); $generator = new DefaultTimeGenerator($nodeProvider, $timeConverter, $timeProvider); $factory = new UuidFactory(); $factory->setTimeGenerator($generator); Uuid::setFactory($factory); $uuid = Uuid::uuid1(null, 4095); $this->assertSame("\65\x65\61\66\x35\65\142\145\55\x32\67\x31\60\x2d\61\142\143\x64\x2d\x38\146\146\146\x2d\60\x31\x32\x33\x34\65\x36\x37\70\71\141\142", $uuid->toString()); } public function testHelperFunctions() { $uuid1 = \Mockery::mock("\x52\141\x6d\163\x65\171\x5c\125\x75\151\x64\134\x55\x75\151\144\111\156\x74\x65\162\146\141\143\145", array("\164\157\123\x74\162\151\x6e\147" => "\x61\126\145\162\163\151\157\x6e\61\x55\x75\x69\144")); $uuid3 = \Mockery::mock("\122\141\x6d\x73\x65\x79\x5c\125\165\x69\144\134\125\165\x69\144\111\x6e\164\145\x72\x66\141\x63\x65", array("\164\x6f\123\164\162\151\x6e\147" => "\141\126\x65\162\163\151\x6f\156\63\x55\x75\151\144")); $uuid4 = \Mockery::mock("\122\141\155\x73\145\171\134\x55\x75\x69\x64\134\125\x75\151\x64\111\x6e\x74\145\x72\146\x61\143\145", array("\x74\157\x53\164\162\151\x6e\x67" => "\141\126\x65\x72\163\151\x6f\x6e\x34\125\x75\151\x64")); $uuid5 = \Mockery::mock("\122\x61\x6d\163\145\x79\x5c\x55\x75\151\144\x5c\125\x75\x69\144\111\x6e\164\145\162\146\x61\x63\x65", array("\164\157\x53\164\162\x69\x6e\x67" => "\x61\x56\145\162\x73\151\x6f\156\x35\x55\165\x69\x64")); $factory = \Mockery::mock("\122\141\x6d\x73\145\171\134\x55\x75\151\x64\x5c\x55\165\x69\x64\x46\x61\143\x74\x6f\162\x79\111\156\x74\145\162\x66\141\x63\145", array("\165\x75\x69\144\61" => $uuid1, "\x75\x75\151\144\63" => $uuid3, "\165\165\151\x64\x34" => $uuid4, "\x75\165\151\144\65" => $uuid5)); Uuid::setFactory($factory); $this->assertSame("\x61\126\145\x72\163\x69\x6f\156\x31\x55\165\151\144", \Ramsey\Uuid\v1("\146\146\146\146\x66\x66\x66\146\146\x66\146\x66", 65535)); $this->assertSame("\141\126\x65\162\163\151\157\156\63\125\165\x69\x64", \Ramsey\Uuid\v3(Uuid::NAMESPACE_URL, "\x68\x74\x74\160\163\72\57\x2f\x65\x78\x61\155\x70\154\145\56\x63\x6f\155\57\146\x6f\157")); $this->assertSame("\141\x56\x65\162\163\x69\x6f\x6e\64\125\x75\151\144", \Ramsey\Uuid\v4()); $this->assertSame("\x61\x56\145\162\163\x69\x6f\156\x35\x55\165\x69\144", \Ramsey\Uuid\v5(Uuid::NAMESPACE_URL, "\150\x74\x74\160\x73\72\x2f\x2f\x65\170\141\x6d\x70\154\145\x2e\143\157\x6d\57\146\157\157")); } public function testUseOfTimestampFirstCombCodec() { $factory = new UuidFactory(); $factory->setRandomGenerator(new CombGenerator($factory->getRandomGenerator(), $factory->getNumberConverter())); $factory->setCodec(new TimestampFirstCombCodec($factory->getUuidBuilder())); $uuid = $factory->uuid4(); $fields = array_values($uuid->getFieldsHex()); $last48Bits = $fields[5]; $fields[5] = $fields[0] . $fields[1]; $fields[0] = substr($last48Bits, 0, 8); $fields[1] = substr($last48Bits, 8, 4); $expectedHex = implode('', $fields); $expectedBytes = hex2bin($expectedHex); $this->assertInstanceOf("\122\x61\x6d\x73\x65\171\x5c\125\x75\151\144\x5c\x55\165\151\144\111\156\164\145\x72\x66\141\x63\x65", $uuid); $this->assertSame(2, $uuid->getVariant()); $this->assertSame(4, $uuid->getVersion()); $this->assertSame($expectedBytes, $uuid->getBytes()); $this->assertSame($expectedHex, (string) $uuid->getHex()); } public function testUuidConstants($constantName, $expected) { $this->assertSame($expected, constant("\122\x61\x6d\163\145\x79\x5c\x55\x75\151\x64\134\125\165\151\x64\72\72{$constantName}")); } public function provideUuidConstantTests() { return array(array("\116\101\x4d\105\x53\x50\x41\x43\x45\137\x44\116\123", "\66\142\141\x37\142\x38\61\x30\x2d\71\144\141\144\x2d\x31\x31\x64\61\x2d\x38\60\x62\64\55\60\x30\143\60\64\146\144\64\63\x30\143\70"), array("\116\x41\x4d\105\123\x50\101\x43\105\137\x55\122\x4c", "\66\x62\x61\67\x62\x38\61\x31\x2d\x39\x64\x61\x64\x2d\61\x31\x64\61\55\x38\60\142\x34\55\60\60\x63\x30\x34\x66\x64\x34\x33\60\143\x38"), array("\116\101\115\x45\x53\x50\101\103\105\137\x4f\111\104", "\66\142\x61\67\x62\x38\x31\x32\x2d\71\x64\x61\144\55\61\61\x64\x31\x2d\70\x30\x62\x34\x2d\60\60\x63\x30\64\x66\x64\64\x33\60\x63\70"), array("\x4e\x41\115\105\x53\x50\x41\103\105\137\130\x35\60\x30", "\66\142\x61\67\142\x38\x31\x34\55\71\144\x61\x64\55\x31\61\144\x31\x2d\70\x30\x62\x34\55\60\x30\x63\60\x34\x66\144\x34\x33\60\143\70"), array("\x4e\x49\114", "\60\60\60\60\60\x30\x30\60\55\x30\x30\x30\x30\55\60\x30\x30\60\x2d\60\x30\60\60\55\60\x30\60\x30\x30\60\x30\x30\x30\x30\60\x30"), array("\x4d\101\130", "\x66\x66\146\x66\x66\146\146\x66\x2d\146\146\146\146\55\x66\x66\146\146\x2d\x66\x66\146\146\x2d\146\146\x66\x66\146\x66\146\x66\x66\x66\146\x66"), array("\122\x45\123\x45\x52\126\x45\104\x5f\x4e\103\x53", 0), array("\122\x46\x43\137\x34\61\x32\62", 2), array("\x52\105\123\105\x52\126\105\104\x5f\115\x49\x43\122\117\123\117\106\124", 6), array("\x52\x45\123\x45\122\126\105\104\137\x46\125\x54\125\122\x45", 7), array("\126\101\114\x49\x44\x5f\x50\101\x54\x54\105\x52\116", "\136\x5b\60\55\x39\101\55\106\141\55\146\x5d\x7b\x38\x7d\x2d\x5b\60\x2d\71\101\x2d\106\141\x2d\146\135\173\64\175\55\x5b\x30\55\71\101\55\x46\x61\x2d\x66\x5d\173\x34\175\x2d\x5b\60\x2d\71\x41\x2d\106\141\55\146\135\173\x34\175\x2d\133\60\x2d\x39\x41\55\x46\x61\55\146\135\173\61\x32\175\44"), array("\x55\x55\111\x44\x5f\x54\x59\x50\x45\x5f\124\x49\x4d\105", 1), array("\125\x55\111\104\137\124\x59\x50\x45\137\111\104\x45\116\124\111\106\x49\x45\x52", 2), array("\125\x55\111\104\137\x54\131\x50\105\137\x48\101\x53\x48\x5f\115\104\65", 3), array("\x55\x55\x49\104\137\x54\131\x50\x45\137\x52\x41\x4e\x44\x4f\115", 4), array("\125\125\111\104\137\124\x59\120\105\x5f\x48\101\123\110\137\x53\110\101\x31", 5), array("\x55\x55\x49\x44\x5f\x54\131\120\x45\x5f\122\x45\x4f\122\x44\x45\x52\x45\x44\137\x54\x49\x4d\105", 6), array("\125\x55\111\104\x5f\124\131\x50\x45\x5f\125\x4e\x49\130\x5f\x54\111\x4d\x45", 7)); } }

Function Calls

None

Variables

None

Stats

MD5 ce67eda664c310649929ae8d517af63c
Eval Count 0
Decode Time 117 ms