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

850389731c stop using the deprecated at() PHPUnit matcher
This commit is contained in:
Fabien Potencier 2020-08-13 16:08:51 +02:00
commit 6972bc232d
21 changed files with 537 additions and 523 deletions

View File

@ -112,14 +112,12 @@ class ConsoleHandlerTest extends TestCase
{ {
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock(); $output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
$output $output
->expects($this->at(0)) ->expects($this->exactly(2))
->method('getVerbosity') ->method('getVerbosity')
->willReturn(OutputInterface::VERBOSITY_QUIET) ->willReturnOnConsecutiveCalls(
; OutputInterface::VERBOSITY_QUIET,
$output OutputInterface::VERBOSITY_DEBUG
->expects($this->at(1)) )
->method('getVerbosity')
->willReturn(OutputInterface::VERBOSITY_DEBUG)
; ;
$handler = new ConsoleHandler($output); $handler = new ConsoleHandler($output);
$this->assertFalse($handler->isHandling(['level' => Logger::NOTICE]), $this->assertFalse($handler->isHandling(['level' => Logger::NOTICE]),

View File

@ -57,18 +57,22 @@ class StopwatchExtensionTest extends TestCase
$events = \is_array($events) ? $events : [$events]; $events = \is_array($events) ? $events : [$events];
$stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')->getMock(); $stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')->getMock();
$i = -1; $expectedCalls = 0;
$expectedStartCalls = [];
$expectedStopCalls = [];
foreach ($events as $eventName) { foreach ($events as $eventName) {
$stopwatch->expects($this->at(++$i)) ++$expectedCalls;
->method('start') $expectedStartCalls[] = [$this->equalTo($eventName), 'template'];
->with($this->equalTo($eventName), 'template') $expectedStopCalls[] = [$this->equalTo($eventName)];
;
$stopwatch->expects($this->at(++$i))
->method('stop')
->with($this->equalTo($eventName))
;
} }
$startInvocationMocker = $stopwatch->expects($this->exactly($expectedCalls))
->method('start');
\call_user_func_array([$startInvocationMocker, 'withConsecutive'], $expectedStartCalls);
$stopInvocationMocker = $stopwatch->expects($this->exactly($expectedCalls))
->method('stop');
\call_user_func_array([$stopInvocationMocker, 'withConsecutive'], $expectedStopCalls);
return $stopwatch; return $stopwatch;
} }
} }

View File

@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\TemplateController; use Symfony\Bundle\FrameworkBundle\Controller\TemplateController;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/** /**
* @author Kévin Dunglas <dunglas@gmail.com> * @author Kévin Dunglas <dunglas@gmail.com>
@ -48,10 +49,8 @@ class TemplateControllerTest extends TestCase
$twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock(); $twig = $this->getMockBuilder('Twig\Environment')->disableOriginalConstructor()->getMock();
$twig->expects($this->once())->method('render')->willReturn('bar'); $twig->expects($this->once())->method('render')->willReturn('bar');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container = new ContainerBuilder();
$container->expects($this->at(0))->method('has')->willReturn(false); $container->set('twig', $twig);
$container->expects($this->at(1))->method('has')->willReturn(true);
$container->expects($this->at(2))->method('get')->willReturn($twig);
$controller = new TemplateController(); $controller = new TemplateController();
$controller->setContainer($container); $controller->setContainer($container);
@ -67,9 +66,8 @@ class TemplateControllerTest extends TestCase
$templating = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')->getMock(); $templating = $this->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface')->getMock();
$templating->expects($this->once())->method('render')->willReturn('bar'); $templating->expects($this->once())->method('render')->willReturn('bar');
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container = new ContainerBuilder();
$container->expects($this->at(0))->method('has')->willReturn(true); $container->set('templating', $templating);
$container->expects($this->at(1))->method('get')->willReturn($templating);
$controller = new TemplateController(); $controller = new TemplateController();
$controller->setContainer($container); $controller->setContainer($container);

View File

@ -13,6 +13,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Templating;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine; use Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
class DelegatingEngineTest extends TestCase class DelegatingEngineTest extends TestCase
@ -108,14 +109,10 @@ class DelegatingEngineTest extends TestCase
private function getContainerMock($services) private function getContainerMock($services)
{ {
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container = new ContainerBuilder();
$i = 0;
foreach ($services as $id => $service) { foreach ($services as $id => $service) {
$container->expects($this->at($i++)) $container->set($id, $service);
->method('get')
->with($id)
->willReturn($service);
} }
return $container; return $container;

View File

@ -297,17 +297,18 @@ class TranslatorTest extends TestCase
$loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock(); $loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock();
$loader->expects($this->at(0)) $loader->expects($this->exactly(2))
->method('load') ->method('load')
/* The "messages.some_locale.loader" is passed via the resource_file option and shall be loaded first */ ->withConsecutive(
->with('messages.some_locale.loader', 'some_locale', 'messages') /* The "messages.some_locale.loader" is passed via the resource_file option and shall be loaded first */
->willReturn($someCatalogue); ['messages.some_locale.loader', 'some_locale', 'messages'],
/* This resource is added by an addResource() call and shall be loaded after the resource_files */
$loader->expects($this->at(1)) ['second_resource.some_locale.loader', 'some_locale', 'messages']
->method('load') )
/* This resource is added by an addResource() call and shall be loaded after the resource_files */ ->willReturnOnConsecutiveCalls(
->with('second_resource.some_locale.loader', 'some_locale', 'messages') $someCatalogue,
->willReturn($someCatalogue); $someCatalogue
);
$options = [ $options = [
'resource_files' => ['some_locale' => ['messages.some_locale.loader']], 'resource_files' => ['some_locale' => ['messages.some_locale.loader']],
@ -352,55 +353,33 @@ class TranslatorTest extends TestCase
{ {
$loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock(); $loader = $this->getMockBuilder('Symfony\Component\Translation\Loader\LoaderInterface')->getMock();
$loader $loader
->expects($this->at(0)) ->expects($this->exactly(7))
->method('load') ->method('load')
->willReturn($this->getCatalogue('fr', [ ->willReturnOnConsecutiveCalls(
'foo' => 'foo (FR)', $this->getCatalogue('fr', [
])) 'foo' => 'foo (FR)',
; ]),
$loader $this->getCatalogue('en', [
->expects($this->at(1)) 'foo' => 'foo (EN)',
->method('load') 'bar' => 'bar (EN)',
->willReturn($this->getCatalogue('en', [ 'choice' => '{0} choice 0 (EN)|{1} choice 1 (EN)|]1,Inf] choice inf (EN)',
'foo' => 'foo (EN)', ]),
'bar' => 'bar (EN)', $this->getCatalogue('es', [
'choice' => '{0} choice 0 (EN)|{1} choice 1 (EN)|]1,Inf] choice inf (EN)', 'foobar' => 'foobar (ES)',
])) ]),
; $this->getCatalogue('pt-PT', [
$loader 'foobarfoo' => 'foobarfoo (PT-PT)',
->expects($this->at(2)) ]),
->method('load') $this->getCatalogue('pt_BR', [
->willReturn($this->getCatalogue('es', [ 'other choice' => '{0} other choice 0 (PT-BR)|{1} other choice 1 (PT-BR)|]1,Inf] other choice inf (PT-BR)',
'foobar' => 'foobar (ES)', ]),
])) $this->getCatalogue('fr.UTF-8', [
; 'foobarbaz' => 'foobarbaz (fr.UTF-8)',
$loader ]),
->expects($this->at(3)) $this->getCatalogue('sr@latin', [
->method('load') 'foobarbax' => 'foobarbax (sr@latin)',
->willReturn($this->getCatalogue('pt-PT', [ ])
'foobarfoo' => 'foobarfoo (PT-PT)', )
]))
;
$loader
->expects($this->at(4))
->method('load')
->willReturn($this->getCatalogue('pt_BR', [
'other choice' => '{0} other choice 0 (PT-BR)|{1} other choice 1 (PT-BR)|]1,Inf] other choice inf (PT-BR)',
]))
;
$loader
->expects($this->at(5))
->method('load')
->willReturn($this->getCatalogue('fr.UTF-8', [
'foobarbaz' => 'foobarbaz (fr.UTF-8)',
]))
;
$loader
->expects($this->at(6))
->method('load')
->willReturn($this->getCatalogue('sr@latin', [
'foobarbax' => 'foobarbax (sr@latin)',
]))
; ;
return $loader; return $loader;

View File

@ -174,8 +174,12 @@ class TraceableEventDispatcherTest extends TestCase
$tdispatcher->addListener('foo', $listener1 = function () {}); $tdispatcher->addListener('foo', $listener1 = function () {});
$tdispatcher->addListener('foo', $listener2 = function () {}); $tdispatcher->addListener('foo', $listener2 = function () {});
$logger->expects($this->at(0))->method('debug')->with('Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']); $logger->expects($this->exactly(2))
$logger->expects($this->at(1))->method('debug')->with('Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']); ->method('debug')
->withConsecutive(
['Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']],
['Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']]
);
$tdispatcher->dispatch('foo'); $tdispatcher->dispatch('foo');
} }
@ -189,9 +193,13 @@ class TraceableEventDispatcherTest extends TestCase
$tdispatcher->addListener('foo', $listener1 = function (Event $event) { $event->stopPropagation(); }); $tdispatcher->addListener('foo', $listener1 = function (Event $event) { $event->stopPropagation(); });
$tdispatcher->addListener('foo', $listener2 = function () {}); $tdispatcher->addListener('foo', $listener2 = function () {});
$logger->expects($this->at(0))->method('debug')->with('Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']); $logger->expects($this->exactly(3))
$logger->expects($this->at(1))->method('debug')->with('Listener "{listener}" stopped propagation of the event "{event}".', ['event' => 'foo', 'listener' => 'closure']); ->method('debug')
$logger->expects($this->at(2))->method('debug')->with('Listener "{listener}" was not called for event "{event}".', ['event' => 'foo', 'listener' => 'closure']); ->withConsecutive(
['Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']],
['Listener "{listener}" stopped propagation of the event "{event}".', ['event' => 'foo', 'listener' => 'closure']],
['Listener "{listener}" was not called for event "{event}".', ['event' => 'foo', 'listener' => 'closure']]
);
$tdispatcher->dispatch('foo'); $tdispatcher->dispatch('foo');
} }

View File

@ -74,14 +74,13 @@ class CachingFactoryDecoratorTest extends TestCase
$list1 = new ArrayChoiceList([]); $list1 = new ArrayChoiceList([]);
$list2 = new ArrayChoiceList([]); $list2 = new ArrayChoiceList([]);
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createListFromChoices') ->method('createListFromChoices')
->with($choices1) ->withConsecutive(
->willReturn($list1); [$choices1],
$this->decoratedFactory->expects($this->at(1)) [$choices2]
->method('createListFromChoices') )
->with($choices2) ->willReturnOnConsecutiveCalls($list1, $list2);
->willReturn($list2);
$this->assertSame($list1, $this->factory->createListFromChoices($choices1)); $this->assertSame($list1, $this->factory->createListFromChoices($choices1));
$this->assertSame($list2, $this->factory->createListFromChoices($choices2)); $this->assertSame($list2, $this->factory->createListFromChoices($choices2));
@ -115,14 +114,13 @@ class CachingFactoryDecoratorTest extends TestCase
$list1 = new ArrayChoiceList([]); $list1 = new ArrayChoiceList([]);
$list2 = new ArrayChoiceList([]); $list2 = new ArrayChoiceList([]);
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createListFromChoices') ->method('createListFromChoices')
->with($choices1) ->withConsecutive(
->willReturn($list1); [$choices1],
$this->decoratedFactory->expects($this->at(1)) [$choices2]
->method('createListFromChoices') )
->with($choices2) ->willReturnOnConsecutiveCalls($list1, $list2);
->willReturn($list2);
$this->assertSame($list1, $this->factory->createListFromChoices($choices1)); $this->assertSame($list1, $this->factory->createListFromChoices($choices1));
$this->assertSame($list2, $this->factory->createListFromChoices($choices2)); $this->assertSame($list2, $this->factory->createListFromChoices($choices2));
@ -151,14 +149,13 @@ class CachingFactoryDecoratorTest extends TestCase
$closure1 = function () {}; $closure1 = function () {};
$closure2 = function () {}; $closure2 = function () {};
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createListFromChoices') ->method('createListFromChoices')
->with($choices, $closure1) ->withConsecutive(
->willReturn($list1); [$choices, $closure1],
$this->decoratedFactory->expects($this->at(1)) [$choices, $closure2]
->method('createListFromChoices') )
->with($choices, $closure2) ->willReturnOnConsecutiveCalls($list1, $list2);
->willReturn($list2);
$this->assertSame($list1, $this->factory->createListFromChoices($choices, $closure1)); $this->assertSame($list1, $this->factory->createListFromChoices($choices, $closure1));
$this->assertSame($list2, $this->factory->createListFromChoices($choices, $closure2)); $this->assertSame($list2, $this->factory->createListFromChoices($choices, $closure2));
@ -185,14 +182,13 @@ class CachingFactoryDecoratorTest extends TestCase
$list1 = new ArrayChoiceList([]); $list1 = new ArrayChoiceList([]);
$list2 = new ArrayChoiceList([]); $list2 = new ArrayChoiceList([]);
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createListFromLoader') ->method('createListFromLoader')
->with($loader1) ->withConsecutive(
->willReturn($list1); [$loader1],
$this->decoratedFactory->expects($this->at(1)) [$loader2]
->method('createListFromLoader') )
->with($loader2) ->willReturnOnConsecutiveCalls($list1, $list2);
->willReturn($list2);
$this->assertSame($list1, $this->factory->createListFromLoader($loader1)); $this->assertSame($list1, $this->factory->createListFromLoader($loader1));
$this->assertSame($list2, $this->factory->createListFromLoader($loader2)); $this->assertSame($list2, $this->factory->createListFromLoader($loader2));
@ -221,14 +217,13 @@ class CachingFactoryDecoratorTest extends TestCase
$closure1 = function () {}; $closure1 = function () {};
$closure2 = function () {}; $closure2 = function () {};
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createListFromLoader') ->method('createListFromLoader')
->with($loader, $closure1) ->withConsecutive(
->willReturn($list1); [$loader, $closure1],
$this->decoratedFactory->expects($this->at(1)) [$loader, $closure2]
->method('createListFromLoader') )
->with($loader, $closure2) ->willReturnOnConsecutiveCalls($list1, $list2);
->willReturn($list2);
$this->assertSame($list1, $this->factory->createListFromLoader($loader, $closure1)); $this->assertSame($list1, $this->factory->createListFromLoader($loader, $closure1));
$this->assertSame($list2, $this->factory->createListFromLoader($loader, $closure2)); $this->assertSame($list2, $this->factory->createListFromLoader($loader, $closure2));
@ -257,14 +252,13 @@ class CachingFactoryDecoratorTest extends TestCase
$view1 = new ChoiceListView(); $view1 = new ChoiceListView();
$view2 = new ChoiceListView(); $view2 = new ChoiceListView();
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createView') ->method('createView')
->with($list, $preferred1) ->withConsecutive(
->willReturn($view1); [$list, $preferred1],
$this->decoratedFactory->expects($this->at(1)) [$list, $preferred2]
->method('createView') )
->with($list, $preferred2) ->willReturnOnConsecutiveCalls($view1, $view2);
->willReturn($view2);
$this->assertSame($view1, $this->factory->createView($list, $preferred1)); $this->assertSame($view1, $this->factory->createView($list, $preferred1));
$this->assertSame($view2, $this->factory->createView($list, $preferred2)); $this->assertSame($view2, $this->factory->createView($list, $preferred2));
@ -293,14 +287,13 @@ class CachingFactoryDecoratorTest extends TestCase
$view1 = new ChoiceListView(); $view1 = new ChoiceListView();
$view2 = new ChoiceListView(); $view2 = new ChoiceListView();
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createView') ->method('createView')
->with($list, $preferred1) ->withConsecutive(
->willReturn($view1); [$list, $preferred1],
$this->decoratedFactory->expects($this->at(1)) [$list, $preferred2]
->method('createView') )
->with($list, $preferred2) ->willReturnOnConsecutiveCalls($view1, $view2);
->willReturn($view2);
$this->assertSame($view1, $this->factory->createView($list, $preferred1)); $this->assertSame($view1, $this->factory->createView($list, $preferred1));
$this->assertSame($view2, $this->factory->createView($list, $preferred2)); $this->assertSame($view2, $this->factory->createView($list, $preferred2));
@ -329,14 +322,13 @@ class CachingFactoryDecoratorTest extends TestCase
$view1 = new ChoiceListView(); $view1 = new ChoiceListView();
$view2 = new ChoiceListView(); $view2 = new ChoiceListView();
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createView') ->method('createView')
->with($list, null, $labels1) ->withConsecutive(
->willReturn($view1); [$list, null, $labels1],
$this->decoratedFactory->expects($this->at(1)) [$list, null, $labels2]
->method('createView') )
->with($list, null, $labels2) ->willReturnOnConsecutiveCalls($view1, $view2);
->willReturn($view2);
$this->assertSame($view1, $this->factory->createView($list, null, $labels1)); $this->assertSame($view1, $this->factory->createView($list, null, $labels1));
$this->assertSame($view2, $this->factory->createView($list, null, $labels2)); $this->assertSame($view2, $this->factory->createView($list, null, $labels2));
@ -365,14 +357,13 @@ class CachingFactoryDecoratorTest extends TestCase
$view1 = new ChoiceListView(); $view1 = new ChoiceListView();
$view2 = new ChoiceListView(); $view2 = new ChoiceListView();
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createView') ->method('createView')
->with($list, null, null, $index1) ->withConsecutive(
->willReturn($view1); [$list, null, null, $index1],
$this->decoratedFactory->expects($this->at(1)) [$list, null, null, $index2]
->method('createView') )
->with($list, null, null, $index2) ->willReturnOnConsecutiveCalls($view1, $view2);
->willReturn($view2);
$this->assertSame($view1, $this->factory->createView($list, null, null, $index1)); $this->assertSame($view1, $this->factory->createView($list, null, null, $index1));
$this->assertSame($view2, $this->factory->createView($list, null, null, $index2)); $this->assertSame($view2, $this->factory->createView($list, null, null, $index2));
@ -401,14 +392,13 @@ class CachingFactoryDecoratorTest extends TestCase
$view1 = new ChoiceListView(); $view1 = new ChoiceListView();
$view2 = new ChoiceListView(); $view2 = new ChoiceListView();
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createView') ->method('createView')
->with($list, null, null, null, $groupBy1) ->withConsecutive(
->willReturn($view1); [$list, null, null, null, $groupBy1],
$this->decoratedFactory->expects($this->at(1)) [$list, null, null, null, $groupBy2]
->method('createView') )
->with($list, null, null, null, $groupBy2) ->willReturnOnConsecutiveCalls($view1, $view2);
->willReturn($view2);
$this->assertSame($view1, $this->factory->createView($list, null, null, null, $groupBy1)); $this->assertSame($view1, $this->factory->createView($list, null, null, null, $groupBy1));
$this->assertSame($view2, $this->factory->createView($list, null, null, null, $groupBy2)); $this->assertSame($view2, $this->factory->createView($list, null, null, null, $groupBy2));
@ -437,14 +427,13 @@ class CachingFactoryDecoratorTest extends TestCase
$view1 = new ChoiceListView(); $view1 = new ChoiceListView();
$view2 = new ChoiceListView(); $view2 = new ChoiceListView();
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createView') ->method('createView')
->with($list, null, null, null, null, $attr1) ->withConsecutive(
->willReturn($view1); [$list, null, null, null, null, $attr1],
$this->decoratedFactory->expects($this->at(1)) [$list, null, null, null, null, $attr2]
->method('createView') )
->with($list, null, null, null, null, $attr2) ->willReturnOnConsecutiveCalls($view1, $view2);
->willReturn($view2);
$this->assertSame($view1, $this->factory->createView($list, null, null, null, null, $attr1)); $this->assertSame($view1, $this->factory->createView($list, null, null, null, null, $attr1));
$this->assertSame($view2, $this->factory->createView($list, null, null, null, null, $attr2)); $this->assertSame($view2, $this->factory->createView($list, null, null, null, null, $attr2));
@ -473,14 +462,13 @@ class CachingFactoryDecoratorTest extends TestCase
$view1 = new ChoiceListView(); $view1 = new ChoiceListView();
$view2 = new ChoiceListView(); $view2 = new ChoiceListView();
$this->decoratedFactory->expects($this->at(0)) $this->decoratedFactory->expects($this->exactly(2))
->method('createView') ->method('createView')
->with($list, null, null, null, null, $attr1) ->withConsecutive(
->willReturn($view1); [$list, null, null, null, null, $attr1],
$this->decoratedFactory->expects($this->at(1)) [$list, null, null, null, null, $attr2]
->method('createView') )
->with($list, null, null, null, null, $attr2) ->willReturnOnConsecutiveCalls($view1, $view2);
->willReturn($view2);
$this->assertSame($view1, $this->factory->createView($list, null, null, null, null, $attr1)); $this->assertSame($view1, $this->factory->createView($list, null, null, null, null, $attr1));
$this->assertSame($view2, $this->factory->createView($list, null, null, null, null, $attr2)); $this->assertSame($view2, $this->factory->createView($list, null, null, null, null, $attr2));

View File

@ -67,15 +67,10 @@ class LazyChoiceListTest extends TestCase
*/ */
public function testGetChoicesUsesLoadedListWhenLoaderDoesNotCacheChoiceListOnFirstCall() public function testGetChoicesUsesLoadedListWhenLoaderDoesNotCacheChoiceListOnFirstCall()
{ {
$this->loader->expects($this->at(0)) $this->loader->expects($this->exactly(2))
->method('loadChoiceList') ->method('loadChoiceList')
->with($this->value) ->with($this->value)
->willReturn($this->loadedList); ->willReturnOnConsecutiveCalls($this->loadedList, new ArrayChoiceList(['a', 'b']));
$this->loader->expects($this->at(1))
->method('loadChoiceList')
->with($this->value)
->willReturn(new ArrayChoiceList(['a', 'b']));
// The same list is returned by the lazy choice list // The same list is returned by the lazy choice list
$this->loadedList->expects($this->exactly(2)) $this->loadedList->expects($this->exactly(2))

View File

@ -92,32 +92,38 @@ class FormDataCollectorTest extends TestCase
{ {
$this->form->add($this->childForm); $this->form->add($this->childForm);
$this->dataExtractor->expects($this->at(0)) $this->dataExtractor->expects($this->exactly(2))
->method('extractConfiguration') ->method('extractConfiguration')
->with($this->form) ->withConsecutive(
->willReturn(['config' => 'foo']); [$this->form],
$this->dataExtractor->expects($this->at(1)) [$this->childForm]
->method('extractConfiguration') )
->with($this->childForm) ->willReturnOnConsecutiveCalls(
->willReturn(['config' => 'bar']); ['config' => 'foo'],
['config' => 'bar']
);
$this->dataExtractor->expects($this->at(2)) $this->dataExtractor->expects($this->exactly(2))
->method('extractDefaultData') ->method('extractDefaultData')
->with($this->form) ->withConsecutive(
->willReturn(['default_data' => 'foo']); [$this->form],
$this->dataExtractor->expects($this->at(3)) [$this->childForm]
->method('extractDefaultData') )
->with($this->childForm) ->willReturnOnConsecutiveCalls(
->willReturn(['default_data' => 'bar']); ['default_data' => 'foo'],
['default_data' => 'bar']
);
$this->dataExtractor->expects($this->at(4)) $this->dataExtractor->expects($this->exactly(2))
->method('extractSubmittedData') ->method('extractSubmittedData')
->with($this->form) ->withConsecutive(
->willReturn(['submitted_data' => 'foo']); [$this->form],
$this->dataExtractor->expects($this->at(5)) [$this->childForm]
->method('extractSubmittedData') )
->with($this->childForm) ->willReturnOnConsecutiveCalls(
->willReturn(['submitted_data' => 'bar']); ['submitted_data' => 'foo'],
['submitted_data' => 'bar']
);
$this->dataCollector->collectConfiguration($this->form); $this->dataCollector->collectConfiguration($this->form);
$this->dataCollector->collectDefaultData($this->form); $this->dataCollector->collectDefaultData($this->form);
@ -158,14 +164,16 @@ class FormDataCollectorTest extends TestCase
$form1 = $this->createForm('form1'); $form1 = $this->createForm('form1');
$form2 = $this->createForm('form2'); $form2 = $this->createForm('form2');
$this->dataExtractor->expects($this->at(0)) $this->dataExtractor->expects($this->exactly(2))
->method('extractConfiguration') ->method('extractConfiguration')
->with($form1) ->withConsecutive(
->willReturn(['config' => 'foo']); [$form1],
$this->dataExtractor->expects($this->at(1)) [$form2]
->method('extractConfiguration') )
->with($form2) ->willReturnOnConsecutiveCalls(
->willReturn(['config' => 'bar']); ['config' => 'foo'],
['config' => 'bar']
);
$this->dataCollector->collectConfiguration($form1); $this->dataCollector->collectConfiguration($form1);
$this->dataCollector->collectConfiguration($form2); $this->dataCollector->collectConfiguration($form2);
@ -208,12 +216,12 @@ class FormDataCollectorTest extends TestCase
public function testBuildSamePreliminaryFormTreeMultipleTimes() public function testBuildSamePreliminaryFormTreeMultipleTimes()
{ {
$this->dataExtractor->expects($this->at(0)) $this->dataExtractor
->method('extractConfiguration') ->method('extractConfiguration')
->with($this->form) ->with($this->form)
->willReturn(['config' => 'foo']); ->willReturn(['config' => 'foo']);
$this->dataExtractor->expects($this->at(1)) $this->dataExtractor
->method('extractDefaultData') ->method('extractDefaultData')
->with($this->form) ->with($this->form)
->willReturn(['default_data' => 'foo']); ->willReturn(['default_data' => 'foo']);
@ -280,42 +288,49 @@ class FormDataCollectorTest extends TestCase
$this->form->add($this->childForm); $this->form->add($this->childForm);
$this->view->children['child'] = $this->childView; $this->view->children['child'] = $this->childView;
$this->dataExtractor->expects($this->at(0)) $this->dataExtractor->expects($this->exactly(2))
->method('extractConfiguration') ->method('extractConfiguration')
->with($this->form) ->withConsecutive(
->willReturn(['config' => 'foo']); [$this->form],
$this->dataExtractor->expects($this->at(1)) [$this->childForm]
->method('extractConfiguration') )
->with($this->childForm) ->willReturnOnConsecutiveCalls(
->willReturn(['config' => 'bar']); ['config' => 'foo'],
['config' => 'bar']
);
$this->dataExtractor->expects($this->at(2)) $this->dataExtractor->expects($this->exactly(2))
->method('extractDefaultData') ->method('extractDefaultData')
->with($this->form) ->withConsecutive(
->willReturn(['default_data' => 'foo']); [$this->form],
$this->dataExtractor->expects($this->at(3)) [$this->childForm]
->method('extractDefaultData') )
->with($this->childForm) ->willReturnOnConsecutiveCalls(
->willReturn(['default_data' => 'bar']); ['default_data' => 'foo'],
['default_data' => 'bar']
);
$this->dataExtractor->expects($this->at(4)) $this->dataExtractor->expects($this->exactly(2))
->method('extractSubmittedData') ->method('extractSubmittedData')
->with($this->form) ->withConsecutive(
->willReturn(['submitted_data' => 'foo']); [$this->form],
$this->dataExtractor->expects($this->at(5)) [$this->childForm]
->method('extractSubmittedData') )
->with($this->childForm) ->willReturnOnConsecutiveCalls(
->willReturn(['submitted_data' => 'bar']); ['submitted_data' => 'foo'],
['submitted_data' => 'bar']
);
$this->dataExtractor->expects($this->at(6)) $this->dataExtractor->expects($this->exactly(2))
->method('extractViewVariables') ->method('extractViewVariables')
->with($this->view) ->withConsecutive(
->willReturn(['view_vars' => 'foo']); [$this->view],
[$this->childView]
$this->dataExtractor->expects($this->at(7)) )
->method('extractViewVariables') ->willReturnOnConsecutiveCalls(
->with($this->childView) ['view_vars' => 'foo'],
->willReturn(['view_vars' => 'bar']); ['view_vars' => 'bar']
);
$this->dataCollector->collectConfiguration($this->form); $this->dataCollector->collectConfiguration($this->form);
$this->dataCollector->collectDefaultData($this->form); $this->dataCollector->collectDefaultData($this->form);
@ -373,79 +388,65 @@ class FormDataCollectorTest extends TestCase
$form1View->children['child1'] = $child1View; $form1View->children['child1'] = $child1View;
$form2View->children['child1'] = $child1View; $form2View->children['child1'] = $child1View;
$this->dataExtractor->expects($this->at(0)) $this->dataExtractor->expects($this->exactly(4))
->method('extractConfiguration') ->method('extractConfiguration')
->with($form1) ->withConsecutive(
->willReturn(['config' => 'foo']); [$form1],
$this->dataExtractor->expects($this->at(1)) [$child1],
->method('extractConfiguration') [$form2],
->with($child1) [$child1]
->willReturn(['config' => 'bar']); )
->willReturnOnConsecutiveCalls(
['config' => 'foo'],
['config' => 'bar'],
['config' => 'foo'],
['config' => 'bar']
);
$this->dataExtractor->expects($this->at(2)) $this->dataExtractor->expects($this->exactly(4))
->method('extractDefaultData') ->method('extractDefaultData')
->with($form1) ->withConsecutive(
->willReturn(['default_data' => 'foo']); [$form1],
$this->dataExtractor->expects($this->at(3)) [$child1],
->method('extractDefaultData') [$form2],
->with($child1) [$child1]
->willReturn(['default_data' => 'bar']); )
->willReturnOnConsecutiveCalls(
['default_data' => 'foo'],
['default_data' => 'bar'],
['default_data' => 'foo'],
['default_data' => 'bar']
);
$this->dataExtractor->expects($this->at(4)) $this->dataExtractor->expects($this->exactly(4))
->method('extractSubmittedData') ->method('extractSubmittedData')
->with($form1) ->withConsecutive(
->willReturn(['submitted_data' => 'foo']); [$form1],
$this->dataExtractor->expects($this->at(5)) [$child1],
->method('extractSubmittedData') [$form2],
->with($child1) [$child1]
->willReturn(['submitted_data' => 'bar']); )
->willReturnOnConsecutiveCalls(
['submitted_data' => 'foo'],
['submitted_data' => 'bar'],
['submitted_data' => 'foo'],
['submitted_data' => 'bar']
);
$this->dataExtractor->expects($this->at(6)) $this->dataExtractor->expects($this->exactly(4))
->method('extractViewVariables') ->method('extractViewVariables')
->with($form1View) ->withConsecutive(
->willReturn(['view_vars' => 'foo']); [$form1View],
[$child1View],
$this->dataExtractor->expects($this->at(7)) [$form2View],
->method('extractViewVariables') [$child1View]
->with($child1View) )
->willReturn(['view_vars' => $child1View->vars]); ->willReturnOnConsecutiveCalls(
['view_vars' => 'foo'],
$this->dataExtractor->expects($this->at(8)) ['view_vars' => $child1View->vars],
->method('extractConfiguration') ['view_vars' => 'foo'],
->with($form2) ['view_vars' => $child1View->vars]
->willReturn(['config' => 'foo']); );
$this->dataExtractor->expects($this->at(9))
->method('extractConfiguration')
->with($child1)
->willReturn(['config' => 'bar']);
$this->dataExtractor->expects($this->at(10))
->method('extractDefaultData')
->with($form2)
->willReturn(['default_data' => 'foo']);
$this->dataExtractor->expects($this->at(11))
->method('extractDefaultData')
->with($child1)
->willReturn(['default_data' => 'bar']);
$this->dataExtractor->expects($this->at(12))
->method('extractSubmittedData')
->with($form2)
->willReturn(['submitted_data' => 'foo']);
$this->dataExtractor->expects($this->at(13))
->method('extractSubmittedData')
->with($child1)
->willReturn(['submitted_data' => 'bar']);
$this->dataExtractor->expects($this->at(14))
->method('extractViewVariables')
->with($form2View)
->willReturn(['view_vars' => 'foo']);
$this->dataExtractor->expects($this->at(15))
->method('extractViewVariables')
->with($child1View)
->willReturn(['view_vars' => $child1View->vars]);
$this->dataCollector->collectConfiguration($form1); $this->dataCollector->collectConfiguration($form1);
$this->dataCollector->collectDefaultData($form1); $this->dataCollector->collectDefaultData($form1);
@ -526,14 +527,16 @@ class FormDataCollectorTest extends TestCase
$this->view->children['child'] = $this->childView; $this->view->children['child'] = $this->childView;
$this->dataExtractor->expects($this->at(0)) $this->dataExtractor->expects($this->exactly(2))
->method('extractConfiguration') ->method('extractConfiguration')
->with($this->form) ->withConsecutive(
->willReturn(['config' => 'foo']); [$this->form],
$this->dataExtractor->expects($this->at(1)) [$this->childForm]
->method('extractConfiguration') )
->with($this->childForm) ->willReturnOnConsecutiveCalls(
->willReturn(['config' => 'bar']); ['config' => 'foo'],
['config' => 'bar']
);
// explicitly call collectConfiguration(), since $this->childForm is not // explicitly call collectConfiguration(), since $this->childForm is not
// contained in the form tree // contained in the form tree
@ -574,14 +577,16 @@ class FormDataCollectorTest extends TestCase
// but associate the two // but associate the two
$this->dataCollector->associateFormWithView($this->childForm, $this->childView); $this->dataCollector->associateFormWithView($this->childForm, $this->childView);
$this->dataExtractor->expects($this->at(0)) $this->dataExtractor->expects($this->exactly(2))
->method('extractConfiguration') ->method('extractConfiguration')
->with($this->form) ->withConsecutive(
->willReturn(['config' => 'foo']); [$this->form],
$this->dataExtractor->expects($this->at(1)) [$this->childForm]
->method('extractConfiguration') )
->with($this->childForm) ->willReturnOnConsecutiveCalls(
->willReturn(['config' => 'bar']); ['config' => 'foo'],
['config' => 'bar']
);
// explicitly call collectConfiguration(), since $this->childForm is not // explicitly call collectConfiguration(), since $this->childForm is not
// contained in the form tree // contained in the form tree
@ -626,18 +631,18 @@ class FormDataCollectorTest extends TestCase
$this->dataExtractor $this->dataExtractor
->method('extractDefaultData') ->method('extractDefaultData')
->willReturn([]); ->willReturn([]);
$this->dataExtractor->expects($this->at(4)) $this->dataExtractor->expects($this->exactly(3))
->method('extractSubmittedData') ->method('extractSubmittedData')
->with($form1) ->withConsecutive(
->willReturn(['errors' => ['foo']]); [$form1],
$this->dataExtractor->expects($this->at(5)) [$childForm1],
->method('extractSubmittedData') [$form2]
->with($childForm1) )
->willReturn(['errors' => ['bar', 'bam']]); ->willReturnOnConsecutiveCalls(
$this->dataExtractor->expects($this->at(8)) ['errors' => ['foo']],
->method('extractSubmittedData') ['errors' => ['bar', 'bam']],
->with($form2) ['errors' => ['baz']]
->willReturn(['errors' => ['baz']]); );
$this->dataCollector->collectSubmittedData($form1); $this->dataCollector->collectSubmittedData($form1);
@ -668,26 +673,22 @@ class FormDataCollectorTest extends TestCase
$this->dataExtractor $this->dataExtractor
->method('extractDefaultData') ->method('extractDefaultData')
->willReturn([]); ->willReturn([]);
$this->dataExtractor->expects($this->at(10)) $this->dataExtractor->expects($this->exactly(5))
->method('extractSubmittedData') ->method('extractSubmittedData')
->with($this->form) ->withConsecutive(
->willReturn(['errors' => []]); [$this->form],
$this->dataExtractor->expects($this->at(11)) [$child1Form],
->method('extractSubmittedData') [$child11Form],
->with($child1Form) [$child2Form],
->willReturn(['errors' => []]); [$child21Form]
$this->dataExtractor->expects($this->at(12)) )
->method('extractSubmittedData') ->willReturnOnConsecutiveCalls(
->with($child11Form) ['errors' => []],
->willReturn(['errors' => ['foo']]); ['errors' => []],
$this->dataExtractor->expects($this->at(13)) ['errors' => ['foo']],
->method('extractSubmittedData') ['errors' => []],
->with($child2Form) ['errors' => []]
->willReturn(['errors' => []]); );
$this->dataExtractor->expects($this->at(14))
->method('extractSubmittedData')
->with($child21Form)
->willReturn(['errors' => []]);
$this->dataCollector->collectSubmittedData($this->form); $this->dataCollector->collectSubmittedData($this->form);
$this->dataCollector->buildPreliminaryFormTree($this->form); $this->dataCollector->buildPreliminaryFormTree($this->form);

View File

@ -144,15 +144,13 @@ class FormRegistryTest extends TestCase
$this->extension1->addType($parentType); $this->extension1->addType($parentType);
$this->extension2->addType($type); $this->extension2->addType($type);
$this->resolvedTypeFactory->expects($this->at(0)) $this->resolvedTypeFactory->expects($this->exactly(2))
->method('createResolvedType') ->method('createResolvedType')
->with($parentType) ->withConsecutive(
->willReturn($parentResolvedType); [$parentType],
[$type, [], $parentResolvedType]
$this->resolvedTypeFactory->expects($this->at(1)) )
->method('createResolvedType') ->willReturnOnConsecutiveCalls($parentResolvedType, $resolvedType);
->with($type, [], $parentResolvedType)
->willReturn($resolvedType);
$this->assertSame($resolvedType, $this->registry->getType(\get_class($type))); $this->assertSame($resolvedType, $this->registry->getType(\get_class($type)));
} }

View File

@ -117,13 +117,26 @@ class SimpleFormTest extends AbstractFormTest
// https://github.com/symfony/symfony/commit/d4f4038f6daf7cf88ca7c7ab089473cce5ebf7d8#commitcomment-1632879 // https://github.com/symfony/symfony/commit/d4f4038f6daf7cf88ca7c7ab089473cce5ebf7d8#commitcomment-1632879
public function testDataIsInitializedFromSubmit() public function testDataIsInitializedFromSubmit()
{ {
$preSetData = false;
$preSubmit = false;
$mock = $this->getMockBuilder('\stdClass') $mock = $this->getMockBuilder('\stdClass')
->setMethods(['preSetData', 'preSubmit']) ->setMethods(['preSetData', 'preSubmit'])
->getMock(); ->getMock();
$mock->expects($this->at(0)) $mock->expects($this->once())
->method('preSetData'); ->method('preSetData')
$mock->expects($this->at(1)) ->with($this->callback(function () use (&$preSetData, $preSubmit) {
->method('preSubmit'); $preSetData = true;
return false === $preSubmit;
}));
$mock->expects($this->once())
->method('preSubmit')
->with($this->callback(function () use ($preSetData, &$preSubmit) {
$preSubmit = true;
return false === $preSetData;
}));
$config = new FormConfigBuilder('name', null, $this->dispatcher); $config = new FormConfigBuilder('name', null, $this->dispatcher);
$config->addEventListener(FormEvents::PRE_SET_DATA, [$mock, 'preSetData']); $config->addEventListener(FormEvents::PRE_SET_DATA, [$mock, 'preSetData']);

View File

@ -461,12 +461,12 @@ class ResponseTest extends ResponseTestCase
public function testDefaultContentType() public function testDefaultContentType()
{ {
$headerMock = $this->getMockBuilder('Symfony\Component\HttpFoundation\ResponseHeaderBag')->setMethods(['set'])->getMock(); $headerMock = $this->getMockBuilder('Symfony\Component\HttpFoundation\ResponseHeaderBag')->setMethods(['set'])->getMock();
$headerMock->expects($this->at(0)) $headerMock->expects($this->exactly(2))
->method('set') ->method('set')
->with('Content-Type', 'text/html'); ->withConsecutive(
$headerMock->expects($this->at(1)) ['Content-Type', 'text/html'],
->method('set') ['Content-Type', 'text/html; charset=UTF-8']
->with('Content-Type', 'text/html; charset=UTF-8'); );
$response = new Response('foo'); $response = new Response('foo');
$response->headers = $headerMock; $response->headers = $headerMock;

View File

@ -15,6 +15,7 @@ use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\Debug\ErrorHandler; use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver; use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver;
@ -117,16 +118,10 @@ class ContainerControllerResolverTest extends ControllerResolverTest
$this->expectException('LogicException'); $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"?'); $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 = $this->getMockBuilder(Container::class)->getMock();
$container->expects($this->at(0)) $container->expects($this->exactly(2))
->method('has') ->method('has')
->with(ImpossibleConstructController::class) ->with(ImpossibleConstructController::class)
->willReturn(true) ->willReturnOnConsecutiveCalls(true, false)
;
$container->expects($this->at(1))
->method('has')
->with(ImpossibleConstructController::class)
->willReturn(false)
; ;
$container->expects($this->atLeastOnce()) $container->expects($this->atLeastOnce())
@ -181,18 +176,10 @@ class ContainerControllerResolverTest extends ControllerResolverTest
{ {
$this->expectException('LogicException'); $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"?'); $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()) $container = new ContainerBuilder();
->method('getRemovedIds') $container->register('app.my_controller');
->with() $container->removeDefinition('app.my_controller');
->willReturn(['app.my_controller' => true])
;
$resolver = $this->createControllerResolver(null, $container); $resolver = $this->createControllerResolver(null, $container);

View File

@ -45,13 +45,15 @@ class TranslatorListenerTest extends TestCase
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest() public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest()
{ {
$this->translator $this->translator
->expects($this->at(0)) ->expects($this->exactly(2))
->method('setLocale') ->method('setLocale')
->willThrowException(new \InvalidArgumentException()); ->withConsecutive(
$this->translator ['fr'],
->expects($this->at(1)) ['en']
->method('setLocale') )
->with($this->equalTo('en')); ->willReturnOnConsecutiveCalls(
$this->throwException(new \InvalidArgumentException())
);
$event = new GetResponseEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); $event = new GetResponseEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
$this->listener->onKernelRequest($event); $this->listener->onKernelRequest($event);
@ -82,13 +84,15 @@ class TranslatorListenerTest extends TestCase
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest() public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest()
{ {
$this->translator $this->translator
->expects($this->at(0)) ->expects($this->exactly(2))
->method('setLocale') ->method('setLocale')
->willThrowException(new \InvalidArgumentException()); ->withConsecutive(
$this->translator ['fr'],
->expects($this->at(1)) ['en']
->method('setLocale') )
->with($this->equalTo('en')); ->willReturnOnConsecutiveCalls(
$this->throwException(new \InvalidArgumentException())
);
$this->setMasterRequest($this->createRequest('fr')); $this->setMasterRequest($this->createRequest('fr'));
$event = new FinishRequestEvent($this->createHttpKernel(), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST); $event = new FinishRequestEvent($this->createHttpKernel(), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST);

View File

@ -314,8 +314,8 @@ class HttpKernelTest extends TestCase
$request = new Request(); $request = new Request();
$stack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->setMethods(['push', 'pop'])->getMock(); $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->once())->method('push')->with($this->equalTo($request));
$stack->expects($this->at(1))->method('pop'); $stack->expects($this->once())->method('pop');
$dispatcher = new EventDispatcher(); $dispatcher = new EventDispatcher();
$kernel = $this->getHttpKernel($dispatcher, null, $stack); $kernel = $this->getHttpKernel($dispatcher, null, $stack);

View File

@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@ -219,9 +220,12 @@ class KernelTest extends TestCase
public function testShutdownGivesNullContainerToAllBundles() public function testShutdownGivesNullContainerToAllBundles()
{ {
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock(); $bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock();
$bundle->expects($this->at(3)) $bundle->expects($this->exactly(2))
->method('setContainer') ->method('setContainer')
->with(null); ->withConsecutive(
[$this->isInstanceOf(ContainerInterface::class)],
[null]
);
$kernel = $this->getKernel(['getBundles']); $kernel = $this->getKernel(['getBundles']);
$kernel->expects($this->any()) $kernel->expects($this->any())

View File

@ -80,15 +80,13 @@ class BundleEntryReaderTest extends TestCase
public function testReadEntireDataFileIfNoIndicesGiven() public function testReadEntireDataFileIfNoIndicesGiven()
{ {
$this->readerImpl->expects($this->at(0)) $this->readerImpl->expects($this->exactly(2))
->method('read') ->method('read')
->with(self::RES_DIR, 'en') ->withConsecutive(
->willReturn(self::$data); [self::RES_DIR, 'en'],
[self::RES_DIR, 'root']
$this->readerImpl->expects($this->at(1)) )
->method('read') ->willReturnOnConsecutiveCalls(self::$data, self::$fallbackData);
->with(self::RES_DIR, 'root')
->willReturn(self::$fallbackData);
$this->assertSame(self::$mergedData, $this->reader->readEntry(self::RES_DIR, 'en', [])); $this->assertSame(self::$mergedData, $this->reader->readEntry(self::RES_DIR, 'en', []));
} }
@ -116,15 +114,13 @@ class BundleEntryReaderTest extends TestCase
public function testFallbackIfEntryDoesNotExist() public function testFallbackIfEntryDoesNotExist()
{ {
$this->readerImpl->expects($this->at(0)) $this->readerImpl->expects($this->exactly(2))
->method('read') ->method('read')
->with(self::RES_DIR, 'en_GB') ->withConsecutive(
->willReturn(self::$data); [self::RES_DIR, 'en_GB'],
[self::RES_DIR, 'en']
$this->readerImpl->expects($this->at(1)) )
->method('read') ->willReturnOnConsecutiveCalls(self::$data, self::$fallbackData);
->with(self::RES_DIR, 'en')
->willReturn(self::$fallbackData);
$this->assertSame('Lah', $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam'])); $this->assertSame('Lah', $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam']));
} }
@ -142,15 +138,13 @@ class BundleEntryReaderTest extends TestCase
public function testFallbackIfLocaleDoesNotExist() public function testFallbackIfLocaleDoesNotExist()
{ {
$this->readerImpl->expects($this->at(0)) $this->readerImpl->expects($this->exactly(2))
->method('read') ->method('read')
->with(self::RES_DIR, 'en_GB') ->withConsecutive(
->willThrowException(new ResourceBundleNotFoundException()); [self::RES_DIR, 'en_GB'],
[self::RES_DIR, 'en']
$this->readerImpl->expects($this->at(1)) )
->method('read') ->willReturnOnConsecutiveCalls(self::$data, self::$fallbackData);
->with(self::RES_DIR, 'en')
->willReturn(self::$fallbackData);
$this->assertSame('Lah', $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam'])); $this->assertSame('Lah', $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam']));
} }
@ -185,15 +179,13 @@ class BundleEntryReaderTest extends TestCase
public function testMergeDataWithFallbackData($childData, $parentData, $result) public function testMergeDataWithFallbackData($childData, $parentData, $result)
{ {
if (null === $childData || \is_array($childData)) { if (null === $childData || \is_array($childData)) {
$this->readerImpl->expects($this->at(0)) $this->readerImpl->expects($this->exactly(2))
->method('read') ->method('read')
->with(self::RES_DIR, 'en') ->withConsecutive(
->willReturn($childData); [self::RES_DIR, 'en'],
[self::RES_DIR, 'root']
$this->readerImpl->expects($this->at(1)) )
->method('read') ->willReturnOnConsecutiveCalls($childData, $parentData);
->with(self::RES_DIR, 'root')
->willReturn($parentData);
} else { } else {
$this->readerImpl->expects($this->once()) $this->readerImpl->expects($this->once())
->method('read') ->method('read')
@ -223,15 +215,16 @@ class BundleEntryReaderTest extends TestCase
public function testMergeExistingEntryWithExistingFallbackEntry($childData, $parentData, $result) public function testMergeExistingEntryWithExistingFallbackEntry($childData, $parentData, $result)
{ {
if (null === $childData || \is_array($childData)) { if (null === $childData || \is_array($childData)) {
$this->readerImpl->expects($this->at(0)) $this->readerImpl->expects($this->exactly(2))
->method('read') ->method('read')
->with(self::RES_DIR, 'en') ->withConsecutive(
->willReturn(['Foo' => ['Bar' => $childData]]); [self::RES_DIR, 'en'],
[self::RES_DIR, 'root']
$this->readerImpl->expects($this->at(1)) )
->method('read') ->willReturnOnConsecutiveCalls(
->with(self::RES_DIR, 'root') ['Foo' => ['Bar' => $childData]],
->willReturn(['Foo' => ['Bar' => $parentData]]); ['Foo' => ['Bar' => $parentData]]
);
} else { } else {
$this->readerImpl->expects($this->once()) $this->readerImpl->expects($this->once())
->method('read') ->method('read')
@ -247,15 +240,13 @@ class BundleEntryReaderTest extends TestCase
*/ */
public function testMergeNonExistingEntryWithExistingFallbackEntry($childData, $parentData, $result) public function testMergeNonExistingEntryWithExistingFallbackEntry($childData, $parentData, $result)
{ {
$this->readerImpl->expects($this->at(0)) $this->readerImpl
->method('read') ->method('read')
->with(self::RES_DIR, 'en_GB') ->withConsecutive(
->willReturn(['Foo' => 'Baz']); [self::RES_DIR, 'en_GB'],
[self::RES_DIR, 'en']
$this->readerImpl->expects($this->at(1)) )
->method('read') ->willReturnOnConsecutiveCalls(['Foo' => 'Baz'], ['Foo' => ['Bar' => $parentData]]);
->with(self::RES_DIR, 'en')
->willReturn(['Foo' => ['Bar' => $parentData]]);
$this->assertSame($parentData, $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true)); $this->assertSame($parentData, $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true));
} }
@ -266,15 +257,13 @@ class BundleEntryReaderTest extends TestCase
public function testMergeExistingEntryWithNonExistingFallbackEntry($childData, $parentData, $result) public function testMergeExistingEntryWithNonExistingFallbackEntry($childData, $parentData, $result)
{ {
if (null === $childData || \is_array($childData)) { if (null === $childData || \is_array($childData)) {
$this->readerImpl->expects($this->at(0)) $this->readerImpl
->method('read') ->method('read')
->with(self::RES_DIR, 'en_GB') ->withConsecutive(
->willReturn(['Foo' => ['Bar' => $childData]]); [self::RES_DIR, 'en_GB'],
[self::RES_DIR, 'en']
$this->readerImpl->expects($this->at(1)) )
->method('read') ->willReturnOnConsecutiveCalls(['Foo' => ['Bar' => $childData]], ['Foo' => 'Bar']);
->with(self::RES_DIR, 'en')
->willReturn(['Foo' => 'Bar']);
} else { } else {
$this->readerImpl->expects($this->once()) $this->readerImpl->expects($this->once())
->method('read') ->method('read')
@ -288,15 +277,13 @@ class BundleEntryReaderTest extends TestCase
public function testFailIfEntryFoundNeitherInParentNorChild() public function testFailIfEntryFoundNeitherInParentNorChild()
{ {
$this->expectException('Symfony\Component\Intl\Exception\MissingResourceException'); $this->expectException('Symfony\Component\Intl\Exception\MissingResourceException');
$this->readerImpl->expects($this->at(0)) $this->readerImpl
->method('read') ->method('read')
->with(self::RES_DIR, 'en_GB') ->withConsecutive(
->willReturn(['Foo' => 'Baz']); [self::RES_DIR, 'en_GB'],
[self::RES_DIR, 'en']
$this->readerImpl->expects($this->at(1)) )
->method('read') ->willReturnOnConsecutiveCalls(['Foo' => 'Baz'], ['Foo' => 'Baz']);
->with(self::RES_DIR, 'en')
->willReturn(['Foo' => 'Bar']);
$this->reader->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true); $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true);
} }
@ -310,15 +297,13 @@ class BundleEntryReaderTest extends TestCase
$childData = \is_array($childData) ? new \ArrayObject($childData) : $childData; $childData = \is_array($childData) ? new \ArrayObject($childData) : $childData;
if (null === $childData || $childData instanceof \ArrayObject) { if (null === $childData || $childData instanceof \ArrayObject) {
$this->readerImpl->expects($this->at(0)) $this->readerImpl
->method('read') ->method('read')
->with(self::RES_DIR, 'en_GB') ->withConsecutive(
->willReturn(['Foo' => ['Bar' => $childData]]); [self::RES_DIR, 'en_GB'],
[self::RES_DIR, 'en']
$this->readerImpl->expects($this->at(1)) )
->method('read') ->willReturnOnConsecutiveCalls(['Foo' => ['Bar' => $childData]], ['Foo' => ['Bar' => $parentData]]);
->with(self::RES_DIR, 'en')
->willReturn(['Foo' => ['Bar' => $parentData]]);
} else { } else {
$this->readerImpl->expects($this->once()) $this->readerImpl->expects($this->once())
->method('read') ->method('read')
@ -337,16 +322,14 @@ class BundleEntryReaderTest extends TestCase
$this->reader->setLocaleAliases(['mo' => 'ro_MD']); $this->reader->setLocaleAliases(['mo' => 'ro_MD']);
if (null === $childData || \is_array($childData)) { if (null === $childData || \is_array($childData)) {
$this->readerImpl->expects($this->at(0)) $this->readerImpl
->method('read') ->method('read')
->with(self::RES_DIR, 'ro_MD') ->withConsecutive(
->willReturn(['Foo' => ['Bar' => $childData]]); [self::RES_DIR, 'ro_MD'],
// Read fallback locale of aliased locale ("ro_MD" -> "ro")
// Read fallback locale of aliased locale ("ro_MD" -> "ro") [self::RES_DIR, 'ro']
$this->readerImpl->expects($this->at(1)) )
->method('read') ->willReturnOnConsecutiveCalls(['Foo' => ['Bar' => $childData]], ['Foo' => ['Bar' => $parentData]]);
->with(self::RES_DIR, 'ro')
->willReturn(['Foo' => ['Bar' => $parentData]]);
} else { } else {
$this->readerImpl->expects($this->once()) $this->readerImpl->expects($this->once())
->method('read') ->method('read')

View File

@ -130,18 +130,18 @@ abstract class PropertyAccessorCollectionTest extends PropertyAccessorArrayAcces
->method('getStructure') ->method('getStructure')
->willReturn($structure); ->willReturn($structure);
$structure->expects($this->at(0)) $structure->expects($this->once())
->method('getAxes') ->method('getAxes')
->willReturn($axesBefore); ->willReturn($axesBefore);
$structure->expects($this->at(1)) $structure->expects($this->once())
->method('removeAxis') ->method('removeAxis')
->with('fourth'); ->with('fourth');
$structure->expects($this->at(2)) $structure->expects($this->exactly(2))
->method('addAxis') ->method('addAxis')
->with('first'); ->withConsecutive(
$structure->expects($this->at(3)) ['first'],
->method('addAxis') ['third']
->with('third'); );
$this->propertyAccessor->setValue($car, 'structure.axes', $axesAfter); $this->propertyAccessor->setValue($car, 'structure.axes', $axesAfter);
} }

View File

@ -76,7 +76,7 @@ class FirewallTest extends TestCase
->getMock() ->getMock()
; ;
$event $event
->expects($this->at(0)) ->expects($this->once())
->method('hasResponse') ->method('hasResponse')
->willReturn(true) ->willReturn(true)
; ;

View File

@ -37,15 +37,16 @@ class ArrayDenormalizerTest extends TestCase
public function testDenormalize() public function testDenormalize()
{ {
$this->serializer->expects($this->at(0)) $this->serializer->expects($this->exactly(2))
->method('denormalize') ->method('denormalize')
->with(['foo' => 'one', 'bar' => 'two']) ->withConsecutive(
->willReturn(new ArrayDummy('one', 'two')); [['foo' => 'one', 'bar' => 'two']],
[['foo' => 'three', 'bar' => 'four']]
$this->serializer->expects($this->at(1)) )
->method('denormalize') ->willReturnOnConsecutiveCalls(
->with(['foo' => 'three', 'bar' => 'four']) new ArrayDummy('one', 'two'),
->willReturn(new ArrayDummy('three', 'four')); new ArrayDummy('three', 'four')
);
$result = $this->denormalizer->denormalize( $result = $this->denormalizer->denormalize(
[ [

View File

@ -12,15 +12,22 @@
namespace Symfony\Component\Validator\Test; namespace Symfony\Component\Validator\Test;
use PHPUnit\Framework\Assert; use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Constraint\IsIdentical;
use PHPUnit\Framework\Constraint\IsInstanceOf;
use PHPUnit\Framework\Constraint\IsNull;
use PHPUnit\Framework\Constraint\LogicalOr;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\ConstraintValidatorInterface;
use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\Context\ExecutionContext; use Symfony\Component\Validator\Context\ExecutionContext;
use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Mapping\ClassMetadata; use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\PropertyMetadata; use Symfony\Component\Validator\Mapping\PropertyMetadata;
use Symfony\Component\Validator\Validator\ContextualValidatorInterface;
/** /**
* A test case to ease testing Constraint Validators. * A test case to ease testing Constraint Validators.
@ -99,7 +106,6 @@ abstract class ConstraintValidatorTestCase extends TestCase
{ {
$translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock(); $translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock();
$validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock(); $validator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ValidatorInterface')->getMock();
$contextualValidator = $this->getMockBuilder('Symfony\Component\Validator\Validator\ContextualValidatorInterface')->getMock();
$context = new ExecutionContext($validator, $this->root, $translator); $context = new ExecutionContext($validator, $this->root, $translator);
$context->setGroup($this->group); $context->setGroup($this->group);
@ -109,7 +115,7 @@ abstract class ConstraintValidatorTestCase extends TestCase
$validator->expects($this->any()) $validator->expects($this->any())
->method('inContext') ->method('inContext')
->with($context) ->with($context)
->willReturn($contextualValidator); ->willReturn(new AssertingContextualValidator());
return $context; return $context;
} }
@ -162,36 +168,26 @@ abstract class ConstraintValidatorTestCase extends TestCase
protected function expectNoValidate() protected function expectNoValidate()
{ {
$validator = $this->context->getValidator()->inContext($this->context); $validator = $this->context->getValidator()->inContext($this->context);
$validator->expects($this->never()) $validator->expectNoValidate();
->method('atPath');
$validator->expects($this->never())
->method('validate');
} }
protected function expectValidateAt($i, $propertyPath, $value, $group) protected function expectValidateAt($i, $propertyPath, $value, $group)
{ {
$validator = $this->context->getValidator()->inContext($this->context); $validator = $this->context->getValidator()->inContext($this->context);
$validator->expects($this->at(2 * $i)) $validator->expectValidation($i, $propertyPath, $value, $group, function ($passedConstraints) {
->method('atPath') $expectedConstraints = new LogicalOr();
->with($propertyPath) $expectedConstraints->setConstraints([new IsNull(), new IsIdentical([]), new IsInstanceOf(Valid::class)]);
->willReturn($validator);
$validator->expects($this->at(2 * $i + 1)) Assert::assertThat($passedConstraints, $expectedConstraints);
->method('validate') });
->with($value, $this->logicalOr(null, [], $this->isInstanceOf('\Symfony\Component\Validator\Constraints\Valid')), $group)
->willReturn($validator);
} }
protected function expectValidateValueAt($i, $propertyPath, $value, $constraints, $group = null) protected function expectValidateValueAt($i, $propertyPath, $value, $constraints, $group = null)
{ {
$contextualValidator = $this->context->getValidator()->inContext($this->context); $contextualValidator = $this->context->getValidator()->inContext($this->context);
$contextualValidator->expects($this->at(2 * $i)) $contextualValidator->expectValidation($i, $propertyPath, $value, $group, function ($passedConstraints) use ($constraints) {
->method('atPath') Assert::assertEquals($constraints, $passedConstraints);
->with($propertyPath) });
->willReturn($contextualValidator);
$contextualValidator->expects($this->at(2 * $i + 1))
->method('validate')
->with($value, $constraints, $group)
->willReturn($contextualValidator);
} }
protected function assertNoViolation() protected function assertNoViolation()
@ -344,3 +340,63 @@ class ConstraintViolationAssertion
); );
} }
} }
class AssertingContextualValidator implements ContextualValidatorInterface
{
private $expectNoValidate = false;
private $atPathCalls = -1;
private $expectedAtPath = [];
private $validateCalls = -1;
private $expectedValidate = [];
public function atPath($path)
{
Assert::assertFalse($this->expectNoValidate, 'No validation calls have been expected.');
if (!isset($this->expectedAtPath[++$this->atPathCalls])) {
throw new ExpectationFailedException(sprintf('Validation for property path "%s" was not expected.', $path));
}
Assert::assertSame($this->expectedAtPath[$this->atPathCalls], $path);
return $this;
}
public function validate($value, $constraints = null, $groups = null)
{
Assert::assertFalse($this->expectNoValidate, 'No validation calls have been expected.');
list($expectedValue, $expectedGroup, $expectedConstraints) = $this->expectedValidate[++$this->validateCalls];
Assert::assertSame($expectedValue, $value);
$expectedConstraints($constraints);
Assert::assertSame($expectedGroup, $groups);
return $this;
}
public function validateProperty($object, $propertyName, $groups = null)
{
return $this;
}
public function validatePropertyValue($objectOrClass, $propertyName, $value, $groups = null)
{
return $this;
}
public function getViolations()
{
}
public function expectNoValidate()
{
$this->expectNoValidate = true;
}
public function expectValidation($call, $propertyPath, $value, $group, $constraints)
{
$this->expectedAtPath[$call] = $propertyPath;
$this->expectedValidate[$call] = [$value, $group, $constraints];
}
}