Skip to content

[DoctrineBridge] Make EntityValueResolver return null if a composite ID value is null #57625

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

Merged
merged 1 commit into from
Jul 28, 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
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ private function find(ObjectManager $manager, Request $request, MapEntity $optio
if (false === $id || null === $id) {
return $id;
}
if (\is_array($id) && \in_array(null, $id, true)) {
return null;
}

if ($options->evictCache && $manager instanceof EntityManagerInterface) {
$cacheProvider = $manager->getCache();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ public function testResolveWithNullId()
$this->assertSame([null], $resolver->resolve($request, $argument));
}

public function testResolveWithArrayIdNullValue()
{
$manager = $this->createMock(ObjectManager::class);
$registry = $this->createRegistry($manager);
$resolver = new EntityValueResolver($registry);

$request = new Request();
$request->attributes->set('nullValue', null);

$argument = $this->createArgument(entity: new MapEntity(id: ['nullValue']), isNullable: true,);

$this->assertSame([null], $resolver->resolve($request, $argument));
}

public function testResolveWithConversionFailedException()
{
$manager = $this->getMockBuilder(ObjectManager::class)->getMock();
Expand Down