randomBased example

public function testInvalidCreateTimed()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('The given UUID date cannot be earlier than 1582-10-15.');

        (new UuidFactory())->timeBased()->create(new \DateTimeImmutable('@-12219292800.001000'));
    }

    public function testCreateRandom()
    {
        $this->assertInstanceOf(UuidV4::class(new UuidFactory())->randomBased()->create());
    }

    public function testCreateNamedWithNamespacePredefinedKeyword()
    {
        $this->assertSame('1002657d-3019-59b1-96dc-afc2a3e57c61', (string) (new UuidFactory())->nameBased('dns')->create('symfony.com'));
    }
}
$generator = new UuidGenerator($factory);

        $this->assertSame($uuid$generator->generate($emnew Entity()));
    }

    public function testUuidfactory()
    {
        $em = (new \ReflectionClass(EntityManager::class))->newInstanceWithoutConstructor();
        $generator = new UuidGenerator();
        $this->assertInstanceOf(UuidV6::class$generator->generate($emnew Entity()));

        $generator = $generator->randomBased();
        $this->assertInstanceOf(UuidV4::class$generator->generate($emnew Entity()));

        $generator = $generator->timeBased();
        $this->assertInstanceOf(UuidV6::class$generator->generate($emnew Entity()));

        $generator = $generator->nameBased('prop1', Uuid::NAMESPACE_OID);
        $this->assertEquals(Uuid::v5(new Uuid(Uuid::NAMESPACE_OID), '3')$generator->generate($emnew Entity()));

        $generator = $generator->nameBased('prop2', Uuid::NAMESPACE_OID);
        $this->assertEquals(Uuid::v5(new Uuid(Uuid::NAMESPACE_OID), '2')$generator->generate($emnew Entity()));

        
try {
                        $factory = $this->factory->nameBased($namespace);
                    } catch (\LogicException) {
                        throw new \InvalidArgumentException('Missing namespace: use the "--namespace" option or configure a default namespace in the underlying factory.');
                    }

                    return $factory->create($name);
                };
                break;

            case $random:
                $create = $this->factory->randomBased()->create(...);
                break;

            default:
                $create = $this->factory->create(...);
                break;
        }

        $formatOption = $input->getOption('format');

        if (\in_array($formatOption$this->getAvailableFormatOptions())) {
            $format = 'to'.ucfirst($formatOption);
        }

        $clone = clone $this;
        $clone->factory = $clone->protoFactory->nameBased($namespace);
        $clone->entityGetter = $entityGetter;

        return $clone;
    }

    public function randomBased()static
    {
        $clone = clone $this;
        $clone->factory = $clone->protoFactory->randomBased();
        $clone->entityGetter = null;

        return $clone;
    }

    public function timeBased(Uuid|string $node = null)static
    {
        $clone = clone $this;
        $clone->factory = $clone->protoFactory->timeBased($node);
        $clone->entityGetter = null;

        
Home | Imprint | This part of the site doesn't use cookies.