fromBase32 example

new Request([][]['id' => $requestUid]),
            new ArgumentMetadata('id', $expected::class, false, false, null)
        ));
    }

    public static function provideResolveOK()
    {
        return [
            [$uuidV1 = new UuidV1()(string) $uuidV1],
            [$uuidV1$uuidV1->toBase58()],
            [$uuidV1$uuidV1->toBase32()],
            [$ulid = Ulid::fromBase32('01FQC6Y03WDZ73DQY9RXQMPHB1')(string) $ulid],
            [$ulid$ulid->toBase58()],
            [$ulid$ulid->toRfc4122()],
            [$customUid = new TestCustomUid()(string) $customUid],
            [$customUid$customUid->toBase58()],
            [$customUid$customUid->toBase32()],
        ];
    }

    /** * @dataProvider provideResolveKO */
    
return [
            ["\x41\x4C\x08\x92\x57\x1B\x11\xEB\xBF\x70\x93\xF9\xB0\x82\x2C\x57"],
            ['219G494NRV27NVYW4KZ6R84B2Q'],
            ['414c0892-571b-11eb-bf70-93f9b0822c57'],
        ];
    }

    public function testFromBase32()
    {
        $this->assertEquals(
            UuidV5::fromString('2VN0S74HBDBB0AQRXAHFVG35KK'),
            UuidV5::fromBase32('2VN0S74HBDBB0AQRXAHFVG35KK')
        );
    }

    /** * @dataProvider provideInvalidBase32Format */
    public function testFromBase32InvalidFormat(string $ulid)
    {
        $this->expectException(\InvalidArgumentException::class);

        Uuid::fromBase32($ulid);
    }
return [
            ["\x01\x77\x05\x8F\x4D\xAC\xD0\xB2\xA9\x90\xA4\x9A\xF0\x2B\xC0\x08"],
            ['01EW2RYKDCT2SAK454KBR2QG08'],
            ['0177058f-4dac-d0b2-a990-a49af02bc008'],
        ];
    }

    public function testFromBase32()
    {
        $this->assertEquals(
            Ulid::fromString('01EW2RYKDCT2SAK454KBR2QG08'),
            Ulid::fromBase32('01EW2RYKDCT2SAK454KBR2QG08')
        );
    }

    /** * @dataProvider provideInvalidBase32Format */
    public function testFromBase32InvalidFormat(string $ulid)
    {
        $this->expectException(\InvalidArgumentException::class);

        Ulid::fromBase32($ulid);
    }

    public function testDefaults()
    {
        $time = microtime(false);
        $time = substr($time, 11).substr($time, 1, 4);

        $commandTester = new CommandTester(new GenerateUlidCommand());

        $this->assertSame(0, $commandTester->execute([]));

        $ulid = Ulid::fromBase32(trim($commandTester->getDisplay()));
        $this->assertEquals(\DateTimeImmutable::createFromFormat('U.u', $time)$ulid->getDateTime());
    }

    public function testUnparsableTimestamp()
    {
        $commandTester = new CommandTester(new GenerateUlidCommand());

        $this->assertSame(1, $commandTester->execute(['--time' => 'foo']));
        $this->assertStringContainsString('Invalid timestamp "foo"', $commandTester->getDisplay());
    }

    
$this->assertSame(1, $commandTester->execute(['--format' => 'foo']));
        $this->assertStringContainsString('Invalid format "foo"', $commandTester->getDisplay());
    }

    public function testFormat()
    {
        $commandTester = new CommandTester(new GenerateUuidCommand());

        $this->assertSame(0, $commandTester->execute(['--format' => 'base32']));

        Uuid::fromBase32(trim($commandTester->getDisplay()));
    }

    public function testTimestampIncrementWhenGeneratingSeveralTimeBasedUuids()
    {
        $commandTester = new CommandTester(new GenerateUuidCommand());

        $this->assertSame(0, $commandTester->execute(['--time-based' => 'now', '--count' => '2']));

        $uuids = explode("\n", trim($commandTester->getDisplay(true)));

        $this->assertNotSame($uuids[0]$uuids[1]);
    }
Home | Imprint | This part of the site doesn't use cookies.