From 277e4fa4907e0d10a76ff3e65debd8a8d1834c7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 31 Mar 2026 17:32:36 +0200 Subject: [PATCH] Add RandomUserTrait to retrieve random user for testing - Implemented `getRandomUser` method to fetch a random user using `EntityManagerInterface`. - Added support for random user retrieval by querying `User` entity repository. --- .../ChillMainBundle/Test/RandomUserTrait.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Test/RandomUserTrait.php diff --git a/src/Bundle/ChillMainBundle/Test/RandomUserTrait.php b/src/Bundle/ChillMainBundle/Test/RandomUserTrait.php new file mode 100644 index 000000000..80ad8bfc5 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Test/RandomUserTrait.php @@ -0,0 +1,30 @@ +getRepository(User::class); + $count = $userRepository->count([]); + $random = mt_rand(0, $count - 1); + + return $em->createQuery('SELECT u FROM '.User::class.' u ') + ->setMaxResults(1) + ->setFirstResult($random) + ->getSingleResult(); + } +}