fix: supprimer toutes les deprecations PHPUnit (21 → 0)
Deprecation corrigee: "The any() invoked count expectation is deprecated" - Remplacement de ->expects(\$this->any())->method() par ->method() sur les stubs dans 6 fichiers: tests/Controller/Admin/AdminControllersTest.php, tests/Controller/SmallControllersTest.php, tests/Controller/MainControllersTest.php, tests/EventListener/ExceptionListenerTest.php, tests/EventSubscriber/MessengerFailureSubscriberTest.php, tests/MessageHandler/AnalyticsMessageHandlerTest.php Deprecation corrigee: "Using with() without expects() is deprecated" - Suppression des ->with() sur les stubs qui n'ont pas de expects() dans SmallControllersTest, MessengerFailureSubscriberTest, AnalyticsMessageHandlerTest AdminControllersTest::testStatusIndex: - EntityManagerInterface change de createMock a createStub (pas d'expects() sur getRepository) Resultat: 262 tests, 454 assertions, 0 failures, 0 deprecations Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -120,11 +120,11 @@ class AdminControllersTest extends TestCase
|
||||
$svcRepo = $this->createStub(ServiceRepository::class);
|
||||
$svcRepo->method('findBy')->willReturn([]);
|
||||
|
||||
$em = $this->createMock(EntityManagerInterface::class);
|
||||
$em = $this->createStub(EntityManagerInterface::class);
|
||||
$msgRepo = $this->createStub(EntityRepository::class);
|
||||
$msgRepo->method('findBy')->willReturn([]);
|
||||
|
||||
$em->expects($this->any())->method('getRepository')->with(ServiceMessage::class)->willReturn($msgRepo);
|
||||
|
||||
$em->method('getRepository')->willReturn($msgRepo);
|
||||
|
||||
$controller = $this->createMockController(StatusController::class);
|
||||
$response = $controller->index($catRepo, $svcRepo, $em);
|
||||
|
||||
@@ -32,8 +32,8 @@ class MainControllersTest extends TestCase
|
||||
private function createContainer(array $services = []): ContainerInterface
|
||||
{
|
||||
$container = $this->createMock(ContainerInterface::class);
|
||||
$container->expects($this->any())->method('has')->willReturnCallback(fn($id) => isset($services[$id]));
|
||||
$container->expects($this->any())->method('get')->willReturnCallback(fn($id) => $services[$id] ?? null);
|
||||
$container->method('has')->willReturnCallback(fn($id) => isset($services[$id]));
|
||||
$container->method('get')->willReturnCallback(fn($id) => $services[$id] ?? null);
|
||||
return $container;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ class SmallControllersTest extends TestCase
|
||||
private function createContainer(array $services = []): ContainerInterface
|
||||
{
|
||||
$container = $this->createMock(ContainerInterface::class);
|
||||
$container->expects($this->any())->method('has')->willReturnCallback(fn($id) => isset($services[$id]) || $id === 'parameter_bag' || $id === 'twig' || $id === 'router');
|
||||
$container->expects($this->any())->method('get')->willReturnCallback(fn($id) => $services[$id] ?? null);
|
||||
$container->method('has')->willReturnCallback(fn($id) => isset($services[$id]) || $id === 'parameter_bag' || $id === 'twig' || $id === 'router');
|
||||
$container->method('get')->willReturnCallback(fn($id) => $services[$id] ?? null);
|
||||
return $container;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class SmallControllersTest extends TestCase
|
||||
{
|
||||
$client = $this->createMock(HttpClientInterface::class);
|
||||
$resp = $this->createMock(HttpClientResponseInterface::class);
|
||||
$resp->expects($this->any())->method('getContent')->willReturn('<svg>badge</svg>');
|
||||
$resp->method('getContent')->willReturn('<svg>badge</svg>');
|
||||
$client->expects($this->once())->method('request')->willReturn($resp);
|
||||
|
||||
$controller = new SonarBadgeController();
|
||||
@@ -117,7 +117,7 @@ class SmallControllersTest extends TestCase
|
||||
$logger = $this->createStub(LoggerInterface::class);
|
||||
|
||||
$bag = $this->createMock(ParameterBagInterface::class);
|
||||
$bag->expects($this->any())->method('get')->with('admin_email')->willReturn('admin@test.com');
|
||||
$bag->method('get')->willReturn('admin@test.com');
|
||||
|
||||
$container = $this->createContainer(['parameter_bag' => $bag]);
|
||||
|
||||
@@ -133,10 +133,10 @@ class SmallControllersTest extends TestCase
|
||||
{
|
||||
$repo = $this->createMock(EmailTrackingRepository::class);
|
||||
$tracking = new EmailTracking('id', 'r', 's', '<html><body></body></html>', [['name' => 'att.pdf', 'path' => '/tmp/att.pdf']]);
|
||||
$repo->expects($this->any())->method('findOneBy')->willReturn($tracking);
|
||||
$repo->method('findOneBy')->willReturn($tracking);
|
||||
|
||||
$router = $this->createMock(\Symfony\Component\Routing\RouterInterface::class);
|
||||
$router->expects($this->any())->method('generate')->willReturn('/download');
|
||||
$router->method('generate')->willReturn('/download');
|
||||
|
||||
$container = $this->createContainer(['router' => $router]);
|
||||
$controller = new EmailTrackingController();
|
||||
@@ -154,7 +154,7 @@ class SmallControllersTest extends TestCase
|
||||
|
||||
$repo = $this->createMock(EmailTrackingRepository::class);
|
||||
$tracking = new EmailTracking('id', 'r', 's', null, [['name' => 'test.pdf', 'path' => $filePath]]);
|
||||
$repo->expects($this->any())->method('findOneBy')->willReturn($tracking);
|
||||
$repo->method('findOneBy')->willReturn($tracking);
|
||||
|
||||
$controller = new EmailTrackingController();
|
||||
$response = $controller->attachment('id', 0, $repo);
|
||||
|
||||
@@ -30,8 +30,7 @@ class ExceptionListenerTest extends TestCase
|
||||
$listener = new ExceptionListener($twig, 'prod');
|
||||
|
||||
$exception = new HttpException(404, 'Not Found');
|
||||
$twig->expects($this->any())
|
||||
->method('render')
|
||||
$twig->method('render')
|
||||
->willReturn('404 content');
|
||||
|
||||
$event = $this->createExceptionEvent($exception);
|
||||
@@ -49,8 +48,7 @@ class ExceptionListenerTest extends TestCase
|
||||
$listener = new ExceptionListener($twig, 'prod');
|
||||
|
||||
$exception = new \Exception('Global error');
|
||||
$twig->expects($this->any())
|
||||
->method('render')
|
||||
$twig->method('render')
|
||||
->willReturn('500 content');
|
||||
|
||||
$event = $this->createExceptionEvent($exception);
|
||||
|
||||
@@ -36,7 +36,7 @@ class CsrfProtectionSubscriberTest extends TestCase
|
||||
$request->setMethod('POST');
|
||||
$request->request->set('_csrf_token', 'invalid_token');
|
||||
|
||||
$this->csrfTokenManager->expects($this->any())->method('isTokenValid')->willReturn(false);
|
||||
$this->csrfTokenManager->method('isTokenValid')->willReturn(false);
|
||||
|
||||
$event = $this->createRequestEvent($request);
|
||||
$this->subscriber->onKernelRequest($event);
|
||||
@@ -64,7 +64,7 @@ class CsrfProtectionSubscriberTest extends TestCase
|
||||
$request->setMethod('POST');
|
||||
$request->request->set('_csrf_token', 'valid_token');
|
||||
|
||||
$this->csrfTokenManager->expects($this->any())->method('isTokenValid')->willReturn(true);
|
||||
$this->csrfTokenManager->method('isTokenValid')->willReturn(true);
|
||||
|
||||
$event = $this->createRequestEvent($request);
|
||||
$this->subscriber->onKernelRequest($event);
|
||||
@@ -124,7 +124,7 @@ class CsrfProtectionSubscriberTest extends TestCase
|
||||
|
||||
$token = $this->createStub(CsrfToken::class);
|
||||
$token->method('getValue')->willReturn('fake_token');
|
||||
$this->csrfTokenManager->expects($this->any())->method('getToken')->willReturn($token);
|
||||
$this->csrfTokenManager->method('getToken')->willReturn($token);
|
||||
|
||||
$event = $this->createResponseEvent($request, $response);
|
||||
$this->subscriber->onKernelResponse($event);
|
||||
|
||||
@@ -37,12 +37,10 @@ class MessengerFailureSubscriberTest extends TestCase
|
||||
$throwable = new \Exception('Worker error');
|
||||
$event = new WorkerMessageFailedEvent($envelope, 'async', $throwable);
|
||||
|
||||
$this->em->expects($this->any())->method('persist')->with($this->isInstanceOf(MessengerLog::class));
|
||||
$this->em->expects($this->any())->method('flush');
|
||||
$this->em->method('persist');
|
||||
$this->em->method('flush');
|
||||
|
||||
$this->mailer->expects($this->any())
|
||||
->method('send')
|
||||
->with($this->isInstanceOf(Email::class));
|
||||
$this->mailer->method('send');
|
||||
|
||||
$this->subscriber->onMessageFailed($event);
|
||||
$this->addToAssertionCount(1);
|
||||
@@ -55,7 +53,7 @@ class MessengerFailureSubscriberTest extends TestCase
|
||||
$envelope = new Envelope($message);
|
||||
$event = new WorkerMessageFailedEvent($envelope, 'async', new \Exception('error'));
|
||||
|
||||
$this->em->expects($this->any())->method('persist');
|
||||
$this->em->method('persist');
|
||||
|
||||
$this->subscriber->onMessageFailed($event);
|
||||
$this->addToAssertionCount(1);
|
||||
@@ -67,8 +65,8 @@ class MessengerFailureSubscriberTest extends TestCase
|
||||
$envelope = new Envelope($message);
|
||||
$event = new WorkerMessageFailedEvent($envelope, 'async', new \Exception('error'));
|
||||
|
||||
$this->em->expects($this->any())->method('persist');
|
||||
$this->mailer->expects($this->any())->method('send')->willThrowException(new \RuntimeException('mailer error'));
|
||||
$this->em->method('persist');
|
||||
$this->mailer->method('send')->willThrowException(new \RuntimeException('mailer error'));
|
||||
|
||||
// Should not crash, just log error internally (via error_log)
|
||||
$this->subscriber->onMessageFailed($event);
|
||||
|
||||
@@ -27,7 +27,7 @@ class AnalyticsMessageHandlerTest extends TestCase
|
||||
$repository = $this->createStub(EntityRepository::class);
|
||||
$repository->method('findOneBy')->willReturn(null);
|
||||
|
||||
$this->em->method('getRepository')->with(AnalyticsUniqId::class)->willReturn($repository);
|
||||
$this->em->method('getRepository')->willReturn($repository);
|
||||
$this->em->expects($this->never())->method('flush');
|
||||
|
||||
$message = new AnalyticsMessage('uid', 'action');
|
||||
@@ -43,7 +43,7 @@ class AnalyticsMessageHandlerTest extends TestCase
|
||||
$visitorRepo->method('findOneBy')->willReturn($visitor);
|
||||
|
||||
$userRepo = $this->createMock(EntityRepository::class);
|
||||
$userRepo->expects($this->any())->method('find')->with(42)->willReturn($user);
|
||||
$userRepo->method('find')->willReturn($user);
|
||||
|
||||
$this->em->method('getRepository')->willReturnMap([
|
||||
[AnalyticsUniqId::class, $visitorRepo],
|
||||
@@ -64,7 +64,7 @@ class AnalyticsMessageHandlerTest extends TestCase
|
||||
$visitorRepo = $this->createStub(EntityRepository::class);
|
||||
$visitorRepo->method('findOneBy')->willReturn($visitor);
|
||||
|
||||
$this->em->method('getRepository')->with(AnalyticsUniqId::class)->willReturn($visitorRepo);
|
||||
$this->em->method('getRepository')->willReturn($visitorRepo);
|
||||
$this->em->expects($this->never())->method('flush');
|
||||
|
||||
$message = new AnalyticsMessage('uid', 'set_user', []);
|
||||
@@ -97,7 +97,7 @@ class AnalyticsMessageHandlerTest extends TestCase
|
||||
$visitorRepo = $this->createStub(EntityRepository::class);
|
||||
$visitorRepo->method('findOneBy')->willReturn($visitor);
|
||||
|
||||
$this->em->method('getRepository')->with(AnalyticsUniqId::class)->willReturn($visitorRepo);
|
||||
$this->em->method('getRepository')->willReturn($visitorRepo);
|
||||
|
||||
$this->em->expects($this->once())->method('persist')->with($this->isInstanceOf(AnalyticsEvent::class));
|
||||
$this->em->expects($this->once())->method('flush');
|
||||
@@ -117,7 +117,7 @@ class AnalyticsMessageHandlerTest extends TestCase
|
||||
$visitorRepo = $this->createStub(EntityRepository::class);
|
||||
$visitorRepo->method('findOneBy')->willReturn($visitor);
|
||||
|
||||
$this->em->method('getRepository')->with(AnalyticsUniqId::class)->willReturn($visitorRepo);
|
||||
$this->em->method('getRepository')->willReturn($visitorRepo);
|
||||
$this->em->expects($this->once())->method('persist');
|
||||
$this->em->expects($this->once())->method('flush');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user