diff --git a/src/Symfony/Component/Uid/Tests/Fixtures/CustomUlid.php b/src/Symfony/Component/Uid/Tests/Fixtures/CustomUlid.php new file mode 100644 index 000000000000..1ff5c0f1d5b8 --- /dev/null +++ b/src/Symfony/Component/Uid/Tests/Fixtures/CustomUlid.php @@ -0,0 +1,18 @@ + + * + * 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 +{ +} diff --git a/src/Symfony/Component/Uid/Tests/Fixtures/CustomUuid.php b/src/Symfony/Component/Uid/Tests/Fixtures/CustomUuid.php new file mode 100644 index 000000000000..8afca539ee77 --- /dev/null +++ b/src/Symfony/Component/Uid/Tests/Fixtures/CustomUuid.php @@ -0,0 +1,18 @@ + + * + * 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 +{ +} diff --git a/src/Symfony/Component/Uid/Tests/UlidTest.php b/src/Symfony/Component/Uid/Tests/UlidTest.php index 58df676fe1b9..2e66026b6688 100644 --- a/src/Symfony/Component/Uid/Tests/UlidTest.php +++ b/src/Symfony/Component/Uid/Tests/UlidTest.php @@ -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 @@ public function testCompare() $this->assertLessThan(0, $b->compare($c)); $this->assertGreaterThan(0, $c->compare($b)); } + + public function testFromStringOnExtendedClassReturnsStatic() + { + $this->assertInstanceOf(CustomUlid::class, CustomUlid::fromString((new CustomUlid())->toBinary())); + } } diff --git a/src/Symfony/Component/Uid/Tests/UuidTest.php b/src/Symfony/Component/Uid/Tests/UuidTest.php index 14f95bb45ded..e8122bec9e72 100644 --- a/src/Symfony/Component/Uid/Tests/UuidTest.php +++ b/src/Symfony/Component/Uid/Tests/UuidTest.php @@ -13,6 +13,7 @@ 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 @@ public function testNilUuid() $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)); + } } diff --git a/src/Symfony/Component/Uid/Ulid.php b/src/Symfony/Component/Uid/Ulid.php index 3665f21ba9ed..b467f9be2b74 100644 --- a/src/Symfony/Component/Uid/Ulid.php +++ b/src/Symfony/Component/Uid/Ulid.php @@ -79,7 +79,7 @@ public static function fromString(string $ulid): parent 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