$test = $this->em->getRepository(Test::class)->findOneBy(['test' => $test]);
if (!empty($test)) {
$name = $test->getName();
$surname = $test->getSurname();
}
return $this->render('test/index.html.twig', [
'test' => $test,
'name' => $name ?? null,
'surname' => $surname ?? null
]);
// в твиге
{% if test is not null %}
<div>{{ test.name }}</div>
<div>{{ test.surname }}</div>
{% endif %}