diff --git a/src/UuidInterface.php b/src/UuidInterface.php index 5f41675..0a97808 100644 --- a/src/UuidInterface.php +++ b/src/UuidInterface.php @@ -19,6 +19,7 @@ use Ramsey\Uuid\Fields\FieldsInterface; use Ramsey\Uuid\Type\Hexadecimal; use Ramsey\Uuid\Type\Integer as IntegerObject; use Serializable; +use Stringable; /** * A UUID is a universally unique identifier adhering to an agreed-upon @@ -29,7 +30,8 @@ use Serializable; interface UuidInterface extends DeprecatedUuidInterface, JsonSerializable, - Serializable + Serializable, + Stringable { /** * Returns -1, 0, or 1 if the UUID is less than, equal to, or greater than diff --git a/tests/UuidTest.php b/tests/UuidTest.php index 17b62a9..feea5a0 100644 --- a/tests/UuidTest.php +++ b/tests/UuidTest.php @@ -41,6 +41,7 @@ use Ramsey\Uuid\UuidFactoryInterface; use Ramsey\Uuid\UuidInterface; use Ramsey\Uuid\Validator\GenericValidator; use Ramsey\Uuid\Validator\ValidatorInterface; +use Stringable; use stdClass; use function base64_decode; @@ -575,11 +576,19 @@ class UuidTest extends TestCase $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); $this->assertSame('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->toString()); $this->assertSame('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', (string) $uuid); + $this->assertSame( + 'ff6f8cb0-c57d-11e1-9b21-0800200c9a66', + (static fn (Stringable $uuid) => (string) $uuid)($uuid) + ); // Check with an old date $uuid = Uuid::fromString('0901e600-0154-1000-9b21-0800200c9a66'); $this->assertSame('0901e600-0154-1000-9b21-0800200c9a66', $uuid->toString()); $this->assertSame('0901e600-0154-1000-9b21-0800200c9a66', (string) $uuid); + $this->assertSame( + '0901e600-0154-1000-9b21-0800200c9a66', + (static fn (Stringable $uuid) => (string) $uuid)($uuid) + ); } public function testUuid1(): void