Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6972bc2

Browse files
committed
minor #37808 stop using the deprecated at() PHPUnit matcher (xabbuh)
This PR was merged into the 3.4 branch. Discussion ---------- stop using the deprecated at() PHPUnit matcher | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #37780 | License | MIT | Doc PR | Commits ------- 8503897 stop using the deprecated at() PHPUnit matcher
2 parents 804b8dd + 8503897 commit 6972bc2

File tree

21 files changed

+542
-528
lines changed

21 files changed

+542
-528
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($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+
$startInvocationMocker = $stopwatch->expects($this->exactly($expectedCalls))
70+
->method('start');
71+
\call_user_func_array([$startInvocationMocker, 'withConsecutive'], $expectedStartCalls);
72+
$stopInvocationMocker = $stopwatch->expects($this->exactly($expectedCalls))
73+
->method('stop');
74+
\call_user_func_array([$stopInvocationMocker, '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 <[email protected]>
@@ -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
}

0 commit comments

Comments
 (0)