From 0d4041919275d48027c3da41ad103b45600b2d0f Mon Sep 17 00:00:00 2001 From: Christian Kolb Date: Tue, 3 Dec 2024 07:42:38 +0100 Subject: [PATCH] Add toString to Id class --- CHANGELOG.md | 4 ++++ README.md | 2 +- UPGRADE.md | 4 ++++ src/ValueObject/Id.php | 5 +++++ tests/ValueObject/IdTest.php | 11 +++++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2106a59..1b903c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.4.0 + +- Added method `toString(): string` to `Id`. + ## 1.3.0 - Added method `mapWithIdKeys(callable $mapFunction): array` to `IdList`. diff --git a/README.md b/README.md index 5d970c7..8982a9d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A Symfony bundle to work with id and id list value objects in Symfony. It includ As it's a central part of an application, it's tested thoroughly (including mutation testing). -[![Latest Stable Version](https://img.shields.io/badge/stable-1.3.0-blue)](https://packagist.org/packages/digital-craftsman/ids) +[![Latest Stable Version](https://img.shields.io/badge/stable-1.4.0-blue)](https://packagist.org/packages/digital-craftsman/ids) [![PHP Version Require](https://img.shields.io/badge/php-8.2|8.3-5b5d95)](https://packagist.org/packages/digital-craftsman/ids) [![codecov](https://codecov.io/gh/digital-craftsman-de/ids/branch/main/graph/badge.svg?token=BL0JKZYLBG)](https://codecov.io/gh/digital-craftsman-de/ids) ![Packagist Downloads](https://img.shields.io/packagist/dt/digital-craftsman/ids) diff --git a/UPGRADE.md b/UPGRADE.md index 9e9d743..3745a6a 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade guide +## From 1.3.* to 1.4.0 + +Nothing to do. + ## From 1.2.* to 1.3.0 Nothing to do. diff --git a/src/ValueObject/Id.php b/src/ValueObject/Id.php index cf0f412..817f8a7 100644 --- a/src/ValueObject/Id.php +++ b/src/ValueObject/Id.php @@ -35,6 +35,11 @@ public function __toString(): string // Accessors + public function toString(): string + { + return $this->value; + } + /** * @param static $id */ diff --git a/tests/ValueObject/IdTest.php b/tests/ValueObject/IdTest.php index 3fe8d38..e3852a2 100644 --- a/tests/ValueObject/IdTest.php +++ b/tests/ValueObject/IdTest.php @@ -35,6 +35,17 @@ public function construction_with_invalid_id_fails(): void new UserId('test'); } + #[Test] + public function to_string_works(): void + { + // -- Arrange + $idString = 'f41e0af4-88c4-4d79-9c1a-6e8ea34a956f'; + $id = UserId::fromString($idString); + + // -- Act & Assert + self::assertSame($idString, $id->toString()); + } + #[Test] public function user_id_is_equal(): void {