[Uid] Unable to extend Uuid/Ulid and use fromString()
This commit is contained in:
parent
c639531fe4
commit
824777938d
18
src/Symfony/Component/Uid/Tests/Fixtures/CustomUlid.php
Normal file
18
src/Symfony/Component/Uid/Tests/Fixtures/CustomUlid.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Uid\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\Uid\Ulid;
|
||||
|
||||
final class CustomUlid extends Ulid
|
||||
{
|
||||
}
|
18
src/Symfony/Component/Uid/Tests/Fixtures/CustomUuid.php
Normal file
18
src/Symfony/Component/Uid/Tests/Fixtures/CustomUuid.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Uid\Tests\Fixtures;
|
||||
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
final class CustomUuid extends Uuid
|
||||
{
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Uid\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Uid\Tests\Fixtures\CustomUlid;
|
||||
use Symfony\Component\Uid\Ulid;
|
||||
use Symfony\Component\Uid\UuidV4;
|
||||
|
||||
@ -118,4 +119,9 @@ class UlidTest extends TestCase
|
||||
$this->assertLessThan(0, $b->compare($c));
|
||||
$this->assertGreaterThan(0, $c->compare($b));
|
||||
}
|
||||
|
||||
public function testFromStringOnExtendedClassReturnsStatic()
|
||||
{
|
||||
$this->assertInstanceOf(CustomUlid::class, CustomUlid::fromString((new CustomUlid())->toBinary()));
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Uid\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Uid\NilUuid;
|
||||
use Symfony\Component\Uid\Tests\Fixtures\CustomUuid;
|
||||
use Symfony\Component\Uid\Ulid;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
use Symfony\Component\Uid\UuidV1;
|
||||
@ -185,4 +186,9 @@ class UuidTest extends TestCase
|
||||
$this->assertInstanceOf(NilUuid::class, $uuid);
|
||||
$this->assertSame('00000000-0000-0000-0000-000000000000', (string) $uuid);
|
||||
}
|
||||
|
||||
public function testFromStringOnExtendedClassReturnsStatic()
|
||||
{
|
||||
$this->assertInstanceOf(CustomUuid::class, CustomUuid::fromString(self::A_UUID_V4));
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ class Ulid extends AbstractUid
|
||||
base_convert(substr($ulid, 27, 5), 16, 32)
|
||||
);
|
||||
|
||||
return new self(strtr($ulid, 'abcdefghijklmnopqrstuv', 'ABCDEFGHJKMNPQRSTVWXYZ'));
|
||||
return new static(strtr($ulid, 'abcdefghijklmnopqrstuv', 'ABCDEFGHJKMNPQRSTVWXYZ'));
|
||||
}
|
||||
|
||||
public function toBinary(): string
|
||||
|
Reference in New Issue
Block a user