From 034963f95c51fbb4d4d6de113cd3871d695f1cd2 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Fri, 19 Apr 2024 10:20:16 -0400 Subject: [PATCH] reset-password cleanup / improve phpstan compat out of the box --- src/Maker/MakeResetPassword.php | 3 +-- .../Test.ResetPasswordController.tpl.php | 14 ++++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Maker/MakeResetPassword.php b/src/Maker/MakeResetPassword.php index c311928fc..5af4878fc 100644 --- a/src/Maker/MakeResetPassword.php +++ b/src/Maker/MakeResetPassword.php @@ -11,7 +11,6 @@ namespace Symfony\Bundle\MakerBundle\Maker; -use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use PhpParser\Builder\Param; use Symfony\Bridge\Twig\AppVariable; @@ -365,7 +364,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen $useStatements = new UseStatementGenerator([ $userClassNameDetails->getFullName(), $userRepositoryDetails->getFullName(), - EntityManager::class, + EntityManagerInterface::class, KernelBrowser::class, WebTestCase::class, UserPasswordHasherInterface::class, diff --git a/src/Resources/skeleton/resetPassword/Test.ResetPasswordController.tpl.php b/src/Resources/skeleton/resetPassword/Test.ResetPasswordController.tpl.php index 16a8a6c01..e4ea1575f 100644 --- a/src/Resources/skeleton/resetPassword/Test.ResetPasswordController.tpl.php +++ b/src/Resources/skeleton/resetPassword/Test.ResetPasswordController.tpl.php @@ -6,7 +6,7 @@ class ResetPasswordTest extends WebTestCase { private KernelBrowser $client; - private EntityManager $em; + private EntityManagerInterface $em; private $userRepository; protected function setUp(): void @@ -15,8 +15,12 @@ protected function setUp(): void // Ensure we have a clean database $container = static::getContainer(); - $this->em = $container->get('doctrine')->getManager(); - $this->userRepository = $this->em->getRepository(::class); + + /** @var EntityManagerInterface $em */ + $em = $container->get('doctrine')->getManager(); + $this->em = $em; + + $this->userRepository = $container->get(::class); foreach ($this->userRepository->findAll() as $user) { $this->em->remove($user); @@ -25,7 +29,7 @@ protected function setUp(): void $this->em->flush(); } - public function testMaker(): void + public function testResetPasswordController(): void { // Create a test user $user = (new ()) @@ -85,6 +89,8 @@ public function testMaker(): void $user = $this->userRepository->findOneBy(['email' => 'me@example.com']); + self::assertInstanceOf(::class, $user); + /** @var UserPasswordHasherInterface $passwordHasher */ $passwordHasher = static::getContainer()->get(UserPasswordHasherInterface::class); self::assertTrue($passwordHasher->isPasswordValid($user, 'newStrongPassword'));