Skip to content

Commit 42170cd

Browse files
committed
Allow to get ID on EntityId
1 parent 5c6cf04 commit 42170cd

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Definition/EntityID.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ public function __construct(EntityManager $entityManager, string $className, ?st
3838
$this->id = $id;
3939
}
4040

41+
/**
42+
* Get the ID
43+
*
44+
* @return null|string
45+
*/
46+
public function getId(): ?string
47+
{
48+
return $this->id;
49+
}
50+
4151
/**
4252
* Get the entity from DB
4353
*

tests/Definition/EntityIDTypeTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public function testMetadata(): void
3232
self::assertSame('Automatically generated type to be used as input where an object of type `User` is needed', $this->type->description);
3333
}
3434

35+
public function testCanGetIdWhenReadingVariable(): void
36+
{
37+
$actual = $this->type->parseValue('123')->getId();
38+
self::assertSame('123', $actual);
39+
}
40+
3541
public function testCanGetEntityFromRepositoryWhenReadingVariable(): void
3642
{
3743
$actual = $this->type->parseValue('123')->getEntity();
@@ -45,6 +51,13 @@ public function testNonExistingEntityThrowErrorWhenReadingVariable(): void
4551
$this->type->parseValue('non-existing-id')->getEntity();
4652
}
4753

54+
public function testCanGetIdWhenReadingLiteral(): void
55+
{
56+
$ast = new StringValueNode(['value' => '123']);
57+
$actual = $this->type->parseLiteral($ast)->getId();
58+
self::assertSame('123', $actual);
59+
}
60+
4861
public function testCanGetEntityFromRepositoryWhenReadingLiteral(): void
4962
{
5063
$ast = new StringValueNode(['value' => '123']);

0 commit comments

Comments
 (0)