Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toString() method to Id #73

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
536 changes: 272 additions & 264 deletions composer.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/Serializer/IdListNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public function supportsDenormalization($data, $type, $format = null, array $con
}

/**
* @param IdList $object
* @param IdList $data
* @param array<string, string|int|bool> $context
*
* @return array<int, string>
*/
public function normalize($object, $format = null, array $context = []): array
public function normalize($data, $format = null, array $context = []): array
{
return $object->idsAsStringList();
return $data->idsAsStringList();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Serializer/IdNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function supportsDenormalization($data, $type, $format = null, array $con
}

/**
* @param Id $object
* @param Id $data
* @param array<string, string|int|bool> $context
*/
public function normalize($object, $format = null, array $context = []): string
public function normalize($data, $format = null, array $context = []): string
{
return (string) $object;
return (string) $data;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/ValueObject/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public function __toString(): string

// Accessors

public function toString(): string
{
return $this->value;
}

/**
* @param static $id
*/
Expand Down
11 changes: 11 additions & 0 deletions tests/ValueObject/IdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading