Skip to content

Commit a031f69

Browse files
committed
stop using the deprecated at() PHPUnit matcher
1 parent 8ee84f9 commit a031f69

File tree

4 files changed

+30
-35
lines changed

4 files changed

+30
-35
lines changed

Tests/Controller/ContainerControllerResolverTest.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Psr\Log\LoggerInterface;
1616
use Symfony\Component\Debug\ErrorHandler;
1717
use Symfony\Component\DependencyInjection\Container;
18+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1819
use Symfony\Component\HttpFoundation\Request;
1920
use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver;
2021

@@ -117,16 +118,10 @@ public function testNonConstructController()
117118
$this->expectException('LogicException');
118119
$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"?');
119120
$container = $this->getMockBuilder(Container::class)->getMock();
120-
$container->expects($this->at(0))
121+
$container->expects($this->exactly(2))
121122
->method('has')
122123
->with(ImpossibleConstructController::class)
123-
->willReturn(true)
124-
;
125-
126-
$container->expects($this->at(1))
127-
->method('has')
128-
->with(ImpossibleConstructController::class)
129-
->willReturn(false)
124+
->willReturnOnConsecutiveCalls(true, false)
130125
;
131126

132127
$container->expects($this->atLeastOnce())
@@ -181,18 +176,10 @@ public function testExceptionWhenUsingRemovedControllerService()
181176
{
182177
$this->expectException('LogicException');
183178
$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"?');
184-
$container = $this->getMockBuilder(Container::class)->getMock();
185-
$container->expects($this->at(0))
186-
->method('has')
187-
->with('app.my_controller')
188-
->willReturn(false)
189-
;
190179

191-
$container->expects($this->atLeastOnce())
192-
->method('getRemovedIds')
193-
->with()
194-
->willReturn(['app.my_controller' => true])
195-
;
180+
$container = new ContainerBuilder();
181+
$container->register('app.my_controller');
182+
$container->removeDefinition('app.my_controller');
196183

197184
$resolver = $this->createControllerResolver(null, $container);
198185

Tests/EventListener/TranslatorListenerTest.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ public function testLocaleIsSetInOnKernelRequest()
4545
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest()
4646
{
4747
$this->translator
48-
->expects($this->at(0))
48+
->expects($this->exactly(2))
4949
->method('setLocale')
50-
->willThrowException(new \InvalidArgumentException());
51-
$this->translator
52-
->expects($this->at(1))
53-
->method('setLocale')
54-
->with($this->equalTo('en'));
50+
->withConsecutive(
51+
['fr'],
52+
['en']
53+
)
54+
->willReturnOnConsecutiveCalls(
55+
$this->throwException(new \InvalidArgumentException())
56+
);
5557

5658
$event = new GetResponseEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
5759
$this->listener->onKernelRequest($event);
@@ -82,13 +84,15 @@ public function testLocaleIsNotSetInOnKernelFinishRequestWhenParentRequestDoesNo
8284
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest()
8385
{
8486
$this->translator
85-
->expects($this->at(0))
86-
->method('setLocale')
87-
->willThrowException(new \InvalidArgumentException());
88-
$this->translator
89-
->expects($this->at(1))
87+
->expects($this->exactly(2))
9088
->method('setLocale')
91-
->with($this->equalTo('en'));
89+
->withConsecutive(
90+
['fr'],
91+
['en']
92+
)
93+
->willReturnOnConsecutiveCalls(
94+
$this->throwException(new \InvalidArgumentException())
95+
);
9296

9397
$this->setMasterRequest($this->createRequest('fr'));
9498
$event = new FinishRequestEvent($this->createHttpKernel(), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST);

Tests/HttpKernelTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ public function testVerifyRequestStackPushPopDuringHandle()
314314
$request = new Request();
315315

316316
$stack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->setMethods(['push', 'pop'])->getMock();
317-
$stack->expects($this->at(0))->method('push')->with($this->equalTo($request));
318-
$stack->expects($this->at(1))->method('pop');
317+
$stack->expects($this->once())->method('push')->with($this->equalTo($request));
318+
$stack->expects($this->once())->method('pop');
319319

320320
$dispatcher = new EventDispatcher();
321321
$kernel = $this->getHttpKernel($dispatcher, null, $stack);

Tests/KernelTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Config\Loader\LoaderInterface;
1616
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
use Symfony\Component\DependencyInjection\ContainerInterface;
1819
use Symfony\Component\Filesystem\Filesystem;
1920
use Symfony\Component\HttpFoundation\Request;
2021
use Symfony\Component\HttpFoundation\Response;
@@ -219,9 +220,12 @@ public function testShutdownCallsShutdownOnAllBundles()
219220
public function testShutdownGivesNullContainerToAllBundles()
220221
{
221222
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock();
222-
$bundle->expects($this->at(3))
223+
$bundle->expects($this->exactly(2))
223224
->method('setContainer')
224-
->with(null);
225+
->withConsecutive(
226+
[$this->isInstanceOf(ContainerInterface::class)],
227+
[null]
228+
);
225229

226230
$kernel = $this->getKernel(['getBundles']);
227231
$kernel->expects($this->any())

0 commit comments

Comments
 (0)