10000 stop using the deprecated at() PHPUnit matcher · symfony/symfony@23b07b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 23b07b0

Browse files
committed
stop using the deprecated at() PHPUnit matcher
1 parent c5cfa04 commit 23b07b0

File tree

8 files changed

+87
-116
lines changed

8 files changed

+87
-116
lines changed

src/Symfony/Bridge/Monolog/Tests/Handler/ConsoleHandlerTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,12 @@ public function testVerbosityChanged()
112112
{
113113
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
114114
$output
115-
->expects($this->at(0))
115+
->expects($this->exactly(2))
116116
->method('getVerbosity')
117-
->willReturn(OutputInterface::VERBOSITY_QUIET)
118-
;
119-
$output
120-
->expects($this->at(1))
121-
->method('getVerbosity')
122-
->willReturn(OutputInterface::VERBOSITY_DEBUG)
117+
->willReturnOnConsecutiveCalls(
118+
OutputInterface::VERBOSITY_QUIET,
119+
OutputInterface::VERBOSITY_DEBUG
120+
)
123121
;
124122
$handler = new ConsoleHandler($output);
125123
$this->assertFalse(< B41A span class=pl-s1>$handler->isHandling(['level' => Logger::NOTICE]),

src/Symfony/Bridge/Twig/Tests/Extension/StopwatchExtensionTest.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,22 @@ protected function getStopwatch($events = [])
5757
$events = \is_array($events) ? $events : [$events];
5858
$stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')->getMock();
5959

60-
$i = -1;
60+
$expectedCalls = 0;
61+
$expectedStartCalls = [];
62+
$expectedStopCalls = [];
6163
foreach ($events as $eventName) {
62-
$stopwatch->expects($this->at(++$i))
63-
->method('start')
64-
->with($this->equalTo($eventName), 'template')
65-
;
66-
$stopwatch->expects($this->at(++$i))
67-
->method('stop')
68-
->with($this->equalTo($eventName))
69-
;
64+
++$expectedCalls;
65+
$expectedStartCalls[] = [$this->equalTo($eventName), 'template'];
66+
$expectedStopCalls[] = [$this->equalTo($eventName)];
7067
}
7168

69+
$stopwatch->expects($this->exactly($expectedCalls))
70+
->method('start')
71+
->withConsecutive(...$expectedStartCalls);
72+
$stopwatch->expects($this->exactly($expectedCalls))
73+
->method('stop')
74+
->withConsecutive(...$expectedStopCalls);
75+
7276
return $stopwatch;
7377
}
7478
}

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/TemplateControllerTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Bundle\FrameworkBundle\Controller\TemplateController;
1515
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
1616
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
17+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718

1819
/**
1920
* @author Kévin Dunglas <dunglas@gmail.com>
@@ -48,10 +49,8 @@ public function testLegacyTwig()
4849
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
4950
$twig->expects($this->once())->method('render')->willReturn('bar');
5051

51-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
52-
$container->expects($this->at(0))->method('has')->willReturn(false);
53-
$container->expects($this->at(1))->method('has')->willReturn(true);
54-
$container->expects($this->at(2))->method('get')->willReturn($twig);
52+
$container = new ContainerBuilder();
53+
$container->set('twig', $twig);
5554

5655
$controller = new TemplateController();
5756
$controller->setContainer($container);
@@ -67,9 +66,8 @@ public function testLegacyTemplating()
6766
$templating = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')->getMock();
6867
$templating->expects($this->once())->method('render')->willReturn('bar');
6968

70-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
71-
$container->expects($this->at(0))->method('has')->willReturn(true);
72-
$container->expects($this->at(1))->method('get')->willReturn($templating);
69+
$container = new ContainerBuilder();
70+
$container->set('templating', $templating);
7371

7472
$controller = new TemplateController();
7573
$controller->setContainer($container);

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/DelegatingEngineTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\HttpFoundation\Response;
1718

1819
class DelegatingEngineTest extends TestCase
@@ -108,14 +109,10 @@ private function getFrameworkEngineMock($template, $supports)
108109

109110
private function getContainerMock($services)
110111
{
111-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
112+
$container = new ContainerBuilder();
112113

113-
$i = 0;
114114
foreach ($services as $id => $service) {
115-
$container->expects($this->at($i++))
116-
->method('get')
117-
->with($id)
118-
->willReturn($service);
115+
$container->set($id, $service);
119116
}
120117

121118
return $container;

src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php

Lines changed: 37 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -297,17 +297,18 @@ public function testResourceFilesOptionLoadsBeforeOtherAddedResources($debug, $e
297297

298298
$loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock();
299299

300-
$loader->expects($this->at(0))
300+
$loader->expects($this->exactly(2))
301301
->method('load')
302-
/* The "messages.some_locale.loader" is passed via the resource_file option and shall be loaded first */
303-
->with('messages.some_locale.loader', 'some_locale', 'messages')
304-
->willReturn($someCatalogue);
305-
306-
$loader->expects($this->at(1))
307-
->method('load')
308-
/* This resource is added by an addResource() call and shall be loaded after the resource_files */
309-
->with('second_resource.some_locale.loader', 'some_locale', 'messages')
310-
->willReturn($someCatalogue);
302+
->withConsecutive(
303+
/* The "messages.some_locale.loader" is passed via the resource_file option and shall be loaded first */
304+
['messages.some_locale.loader', 'some_locale', 'messages'],
305+
/* This resource is added by an addResource() call and shall be loaded after the resource_files */
306+
['second_resource.some_locale.loader', 'some_locale', 'messages'],
307+
)
308+
->willReturnOnConsecutiveCalls(
309+
$someCatalogue,
310+
$someCatalogue
311+
);
311312

312313
$options = [
313314
'resource_files' => ['some_locale' => ['messages.some_locale.loader']],
@@ -352,55 +353,33 @@ protected function getLoader()
352353
{
353354
$loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock();
354355
$loader
355-
->expects($this->at(0))
356-
->method('load')
357-
->willReturn($this->getCatalogue('fr', [
358-
'foo' => 'foo (FR)',
359-
]))
360-
;
361-
$loader
362-
->expects($this->at(1))
363-
->method('load')
364-
->willReturn($this->getCatalogue('en', [
365-
'foo' => 'foo (EN)',
366-
'bar' => 'bar (EN)',
367-
'choice' => '{0} choice 0 (EN)|{1} choice 1 (EN)|]1,Inf] choice inf (EN)',
368-
]))
369-
;
370-
$loader
371-
->expects($this->at(2))
372-
->method('load')
373-
->willReturn($this->getCatalogue('es', [
374-
'foobar' => 'foobar (ES)',
375-
]))
376-
;
377-
$loader
378-
->expects($this->at(3))
379-
->method('load')
380-
->willReturn($this->getCatalogue('pt-PT', [
381-
'foobarfoo' => 'foobarfoo (PT-PT)',
382-
]))
383-
;
384-
$loader
385-
->expects($this->at(4))
386-
->method('load')
387-
->willReturn($this->getCatalogue('pt_BR', [
388-
'other choice' => '{0} other choice 0 (PT-BR)|{1} other choice 1 (PT-BR)|]1,Inf] other choice inf (PT-BR)',
389-
]))
390-
;
391-
$loader
392-
->expects($this->at(5))
393-
->method('load')
394-
->willReturn($this->getCatalogue('fr.UTF-8', [
395-
'foobarbaz' => 'foobarbaz (fr.UTF-8)',
396-
]))
397-
;
398-
$loader
399-
->expects($this->at(6))
356+
->expects($this->exactly(7))
400357
->method('load')
401-
->willReturn($this->getCatalogue('sr@latin', [
402-
'foobarbax' => 'foobarbax (sr@latin)',
403-
]))
358+
->willReturnOnConsecutiveCalls(
359+
$this->getCatalogue('fr', [
360+
'foo' => 'foo (FR)',
361+
]),
362+
$this->getCatalogue('en', [
363+
'foo' => 'foo (EN)',
364+
'bar' => 'bar (EN)',
365+
'choice' => '{0} choice 0 (EN)|{1} choice 1 (EN)|]1,Inf] choice inf (EN)',
366+
]),
367+
$this->getCatalogue('es', [
368+
'foobar' => 'foobar (ES)',
369+
]),
370+
$this->getCatalogue('pt-PT', [
371+
'foobarfoo' => 'foobarfoo (PT-PT)',
372+
]),
373+
$this->getCatalogue('pt_BR', [
374+
'other choice' => '{0} other choice 0 (PT-BR)|{1} other choice 1 (PT-BR)|]1,Inf] other choice inf (PT-BR)',
375+
]),
376+
$this->getCatalogue('fr.UTF-8', [
377+
'foobarbaz' => 'foobarbaz (fr.UTF-8)',
378+
]),
379+
$this->getCatalogue('sr@latin', [
380+
'foobarbax' => 'foobarbax (sr@latin)',
381+
])
382+
)
404383
;
405384

406385
return $loader;

src/Symfony/Component/EventDispatcher/Tests/Debug/TraceableEventDispatcherTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,12 @@ public function testLogger()
174174
$tdispatcher->addListener('foo', $listener1 = function () {});
175175
$tdispatcher->addListener('foo', $listener2 = function () {});
176176

177-
$logger->expects($this->at(0))->method('debug')->with('Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']);
178-
$logger->expects($this->at(1))->method('debug')->with('Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']);
177+
$logger->expects($this->exactly(2))
178+
->method('debug')
179+
->withConsecutive(
180+
['Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']],
181+
['Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']]
182+
);
179183

180184
$tdispatcher->dispatch('foo');
181185
}
@@ -189,9 +193,13 @@ public function testLoggerWithStoppedEvent()
189193
$tdispatcher->addListener('foo', $listener1 = function (Event $event) { $event->stopPropagation(); });
190194
$tdispatcher->addListener('foo', $listener2 = function () {});
191195

192-
$logger->expects($this->at(0))->method('debug')->with('Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']);
193-
$logger->expects($this->at(1))->method('debug')->with('Listener "{listener}" stopped propagation of the event "{event}".', ['event' => 'foo', 'listener' => 'closure']);
194-
$logger->expects($this->at(2))->method('debug')->with('Listener "{listener}" was not called for event "{event}".', ['event' => 'foo', 'listener' => 'closure']);
196+
$logger->expects($this->exactly(3))
197+
->method('debug')
198+
->withConsecutive(
199+
['Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']],
200+
['Listener "{listener}" stopped propagation of the event "{event}".', ['event' => 'foo', 'listener' => 'closure']],
201+
['Listener "{listener}" was not called for event "{event}".', ['event' => 'foo', 'listener' => 'closure']]
202+
);
195203

196204
$tdispatcher->dispatch('foo');
197205
}

src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,12 @@ public function testSetVary()
461461
public function testDefaultContentType()
462462
{
463463
$headerMock = $this->getMockBuilder('Symfony\Component\HttpFoundation\ResponseHeaderBag')->setMethods(['set'])->getMock();
464-
$headerMock->expects($this->at(0))
464+
$headerMock->expects($this->exactly(2))
465465
->method('set')
466-
->with('Content-Type', 'text/html');
467-
$headerMock->expects($this->at(1))
468-
->method('set')
469-
->with('Content-Type', 'text/html; charset=UTF-8');
466+
->withConsecutive(
467+
['Content-Type', 'text/html'],
468+
['Content-Type', 'text/html; charset=UTF-8']
469+
);
470470

471471
$response = new Response('foo');
472472
$response->headers = $headerMock;

src/Symfony/Component/HttpKernel/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

0 commit comments

Comments
 (0)
0