Skip to content

Commit

Permalink
stop using the deprecated at() PHPUnit matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Aug 12, 2020
1 parent 8ee84f9 commit a031f69
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 35 deletions.
25 changes: 6 additions & 19 deletions Tests/Controller/ContainerControllerResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Psr\Log\LoggerInterface;
use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver;

Expand Down Expand Up @@ -117,16 +118,10 @@ public function testNonConstructController()
$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"?');
$container = $this->getMockBuilder(Container::class)->getMock();
$container->expects($this->at(0))
$container->expects($this->exactly(2))
->method('has')
->with(ImpossibleConstructController::class)
->willReturn(true)
;

$container->expects($this->at(1))
->method('has')
->with(ImpossibleConstructController::class)
->willReturn(false)
->willReturnOnConsecutiveCalls(true, false)
;

$container->expects($this->atLeastOnce())
Expand Down Expand Up @@ -181,18 +176,10 @@ public function testExceptionWhenUsingRemovedControllerService()
{
$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"?');
$container = $this->getMockBuilder(Container::class)->getMock();
$container->expects($this->at(0))
->method('has')
->with('app.my_controller')
->willReturn(false)
;

$container->expects($this->atLeastOnce())
->method('getRemovedIds')
->with()
->willReturn(['app.my_controller' => true])
;
$container = new ContainerBuilder();
$container->register('app.my_controller');
$container->removeDefinition('app.my_controller');

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

Expand Down
28 changes: 16 additions & 12 deletions Tests/EventListener/TranslatorListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ public function testLocaleIsSetInOnKernelRequest()
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest()
{
$this->translator
->expects($this->at(0))
->expects($this->exactly(2))
->method('setLocale')
->willThrowException(new \InvalidArgumentException());
$this->translator
->expects($this->at(1))
->method('setLocale')
->with($this->equalTo('en'));
->withConsecutive(
['fr'],
['en']
)
->willReturnOnConsecutiveCalls(
$this->throwException(new \InvalidArgumentException())
);

$event = new GetResponseEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
$this->listener->onKernelRequest($event);
Expand Down Expand Up @@ -82,13 +84,15 @@ public function testLocaleIsNotSetInOnKernelFinishRequestWhenParentRequestDoesNo
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest()
{
$this->translator
->expects($this->at(0))
->method('setLocale')
->willThrowException(new \InvalidArgumentException());
$this->translator
->expects($this->at(1))
->expects($this->exactly(2))
->method('setLocale')
->with($this->equalTo('en'));
->withConsecutive(
['fr'],
['en']
)
->willReturnOnConsecutiveCalls(
$this->throwException(new \InvalidArgumentException())
);

$this->setMasterRequest($this->createRequest('fr'));
$event = new FinishRequestEvent($this->createHttpKernel(), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST);
Expand Down
4 changes: 2 additions & 2 deletions Tests/HttpKernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ public function testVerifyRequestStackPushPopDuringHandle()
$request = new Request();

$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->at(1))->method('pop');
$stack->expects($this->once())->method('push')->with($this->equalTo($request));
$stack->expects($this->once())->method('pop');

$dispatcher = new EventDispatcher();
$kernel = $this->getHttpKernel($dispatcher, null, $stack);
Expand Down
8 changes: 6 additions & 2 deletions Tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -219,9 +220,12 @@ public function testShutdownCallsShutdownOnAllBundles()
public function testShutdownGivesNullContainerToAllBundles()
{
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock();
$bundle->expects($this->at(3))
$bundle->expects($this->exactly(2))
->method('setContainer')
->with(null);
->withConsecutive(
[$this->isInstanceOf(ContainerInterface::class)],
[null]
);

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

0 comments on commit a031f69

Please sign in to comment.