Skip to content

Commit 7c3a172

Browse files
committed
stop using the deprecated at() PHPUnit matcher
1 parent 389cb6c commit 7c3a172

File tree

3 files changed

+45
-71
lines changed

3 files changed

+45
-71
lines changed

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);

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;

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;

0 commit comments

Comments
 (0)