Doc
Решение через EquatableInterface. Сокращенный класс что получилось:
//src/Entity/User.php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\EquatableInterface;
/**
* @ORM\Table(name="user", uniqueConstraints={@ORM\UniqueConstraint(name="UNIQ_8D93D649E7927C74", columns={"email"})})
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
* @ORM\HasLifecycleCallbacks()
*/
class User implements UserInterface, EquatableInterface
{
/**
* @see EquatableInterface
* @param UserInterface $user
* @return bool
*/
public function isEqualTo(UserInterface $user): bool
{
return $user->roles === $this->roles;
}
}