From a031f696fc43db5f1ba97f33c1e0066a75196472 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 11 Aug 2020 09:56:31 +0200 Subject: [PATCH] stop using the deprecated at() PHPUnit matcher --- .../ContainerControllerResolverTest.php | 25 ++++------------- .../EventListener/TranslatorListenerTest.php | 28 +++++++++++-------- Tests/HttpKernelTest.php | 4 +-- Tests/KernelTest.php | 8 ++++-- 4 files changed, 30 insertions(+), 35 deletions(-) diff --git a/Tests/Controller/ContainerControllerResolverTest.php b/Tests/Controller/ContainerControllerResolverTest.php index ef1c82638b..8275154657 100644 --- a/Tests/Controller/ContainerControllerResolverTest.php +++ b/Tests/Controller/ContainerControllerResolverTest.php @@ -15,6 +15,7 @@ use Psr\Log\LoggerInterface; use Symfony\Component\Debug\ErrorHandler; use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver; @@ -117,16 +118,10 @@ public function testNonConstructController() $this->expectException('LogicException'); $this->expectExceptionMessage('Controller "Symfony\Component\HttpKernel\Tests\Controller\ImpossibleConstructController" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?'); $container = $this->getMockBuilder(Container::class)->getMock(); - $container->expects($this->at(0)) + $container->expects($this->exactly(2)) ->method('has') ->with(ImpossibleConstructController::class) - ->willReturn(true) - ; - - $container->expects($this->at(1)) - ->method('has') - ->with(ImpossibleConstructController::class) - ->willReturn(false) + ->willReturnOnConsecutiveCalls(true, false) ; $container->expects($this->atLeastOnce()) @@ -181,18 +176,10 @@ public function testExceptionWhenUsingRemovedControllerService() { $this->expectException('LogicException'); $this->expectExceptionMessage('Controller "app.my_controller" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?'); - $container = $this->getMockBuilder(Container::class)->getMock(); - $container->expects($this->at(0)) - ->method('has') - ->with('app.my_controller') - ->willReturn(false) - ; - $container->expects($this->atLeastOnce()) - ->method('getRemovedIds') - ->with() - ->willReturn(['app.my_controller' => true]) - ; + $container = new ContainerBuilder(); + $container->register('app.my_controller'); + $container->removeDefinition('app.my_controller'); $resolver = $this->createControllerResolver(null, $container); diff --git a/Tests/EventListener/TranslatorListenerTest.php b/Tests/EventListener/TranslatorListenerTest.php index 77c2c1c694..79e0d6f1ac 100644 --- a/Tests/EventListener/TranslatorListenerTest.php +++ b/Tests/EventListener/TranslatorListenerTest.php @@ -45,13 +45,15 @@ public function testLocaleIsSetInOnKernelRequest() public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest() { $this->translator - ->expects($this->at(0)) + ->expects($this->exactly(2)) ->method('setLocale') - ->willThrowException(new \InvalidArgumentException()); - $this->translator - ->expects($this->at(1)) - ->method('setLocale') - ->with($this->equalTo('en')); + ->withConsecutive( + ['fr'], + ['en'] + ) + ->willReturnOnConsecutiveCalls( + $this->throwException(new \InvalidArgumentException()) + ); $event = new GetResponseEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); $this->listener->onKernelRequest($event); @@ -82,13 +84,15 @@ public function testLocaleIsNotSetInOnKernelFinishRequestWhenParentRequestDoesNo public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest() { $this->translator - ->expects($this->at(0)) - ->method('setLocale') - ->willThrowException(new \InvalidArgumentException()); - $this->translator - ->expects($this->at(1)) + ->expects($this->exactly(2)) ->method('setLocale') - ->with($this->equalTo('en')); + ->withConsecutive( + ['fr'], + ['en'] + ) + ->willReturnOnConsecutiveCalls( + $this->throwException(new \InvalidArgumentException()) + ); $this->setMasterRequest($this->createRequest('fr')); $event = new FinishRequestEvent($this->createHttpKernel(), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST); diff --git a/Tests/HttpKernelTest.php b/Tests/HttpKernelTest.php index af81f021ed..97c58305db 100644 --- a/Tests/HttpKernelTest.php +++ b/Tests/HttpKernelTest.php @@ -314,8 +314,8 @@ public function testVerifyRequestStackPushPopDuringHandle() $request = new Request(); $stack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->setMethods(['push', 'pop'])->getMock(); - $stack->expects($this->at(0))->method('push')->with($this->equalTo($request)); - $stack->expects($this->at(1))->method('pop'); + $stack->expects($this->once())->method('push')->with($this->equalTo($request)); + $stack->expects($this->once())->method('pop'); $dispatcher = new EventDispatcher(); $kernel = $this->getHttpKernel($dispatcher, null, $stack); diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index 6cbf59b9b2..fd840bbb7b 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -15,6 +15,7 @@ use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -219,9 +220,12 @@ public function testShutdownCallsShutdownOnAllBundles() public function testShutdownGivesNullContainerToAllBundles() { $bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock(); - $bundle->expects($this->at(3)) + $bundle->expects($this->exactly(2)) ->method('setContainer') - ->with(null); + ->withConsecutive( + [$this->isInstanceOf(ContainerInterface::class)], + [null] + ); $kernel = $this->getKernel(['getBundles']); $kernel->expects($this->any())