Skip to content

Commit b9b0c03

Browse files
committed
Simplify debug info for UUID properties
1 parent b10537d commit b9b0c03

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/AbstractEntity.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ public function __debugInfo(): array
168168
if ($property->isPrivate()) {
169169
$propertyName .= ':private';
170170
}
171-
$result[$propertyName] = $property->getValue($this);
171+
$propertyValue = $property->getValue($this);
172+
if ($propertyValue instanceof \Ramsey\Uuid\UuidInterface) {
173+
$propertyValue = $propertyValue->toString() . " (UUIDv{$propertyValue->getVersion()})";
174+
}
175+
$result[$propertyName] = $propertyValue;
172176
}
173177
return $result;
174178
}

tests/AbstractEntityTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Composite\Entity\Tests\TestStand\TestEntityWithHydrator;
99
use Composite\Entity\Tests\TestStand\TestSubEntity;
1010
use PHPUnit\Framework\Attributes\DataProvider;
11+
use Ramsey\Uuid\Uuid;
12+
use Ramsey\Uuid\UuidInterface;
1113

1214
final class AbstractEntityTest extends \PHPUnit\Framework\TestCase
1315
{
@@ -223,16 +225,19 @@ public function __construct(
223225
public function test_debugInfo(): void
224226
{
225227
$entity = new class extends AbstractEntity {
228+
public UuidInterface $uuid;
226229
public int $var1 = 1;
227230
protected int $var2 = 2;
228231
private int $var3 = 3;
229232
public int $var4;
230233
public function __construct(
231234
public TestSubEntity $subEntity = new TestSubEntity(),
232235
) {
236+
$this->uuid = Uuid::fromString('123e4567-e89b-12d3-a456-426655440000');
233237
}
234238
};
235239
$expected = print_r([
240+
'uuid' => '123e4567-e89b-12d3-a456-426655440000 (UUIDv1)',
236241
'var1' => 1,
237242
'var2' => 2,
238243
'var3:private' => 3,

0 commit comments

Comments
 (0)