From 1ecf001b834ce25a21c37594883213b4a29f7eb0 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 6 Mar 2023 20:42:33 +0100 Subject: [PATCH] [Tests] Remove occurrences of `withConsecutive()` --- .../DefaultAuthenticationFailureHandlerTest.php | 13 +++++++++---- .../PasswordMigratingListenerTest.php | 14 +++++++++++++- Tests/LoginLink/LoginLinkHandlerTest.php | 16 +++++++++++++++- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php b/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php index 46ac7243..bcd18740 100644 --- a/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php +++ b/Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php @@ -197,10 +197,15 @@ public function testFailurePathFromRequestWithInvalidUrl() $this->logger->expects($this->exactly(2)) ->method('debug') - ->withConsecutive( - ['Ignoring query parameter "_my_failure_path": not a valid URL.'], - ['Authentication failure, redirect triggered.', ['failure_path' => '/login']] - ); + ->willReturnCallback(function (...$args) { + static $series = [ + ['Ignoring query parameter "_my_failure_path": not a valid URL.', []], + ['Authentication failure, redirect triggered.', ['failure_path' => '/login']], + ]; + + $expectedArgs = array_shift($series); + $this->assertSame($expectedArgs, $args); + }); $handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, $options, $this->logger); diff --git a/Tests/EventListener/PasswordMigratingListenerTest.php b/Tests/EventListener/PasswordMigratingListenerTest.php index 70725c20..6fc48b7a 100644 --- a/Tests/EventListener/PasswordMigratingListenerTest.php +++ b/Tests/EventListener/PasswordMigratingListenerTest.php @@ -85,7 +85,19 @@ public function testUnsupportedPassport() // A custom Passport, without an UserBadge $passport = $this->createMock(UserPassportInterface::class); $passport->method('getUser')->willReturn($this->user); - $passport->method('hasBadge')->withConsecutive([PasswordUpgradeBadge::class], [UserBadge::class])->willReturnOnConsecutiveCalls(true, false); + $passport->method('hasBadge') + ->willReturnCallback(function (...$args) { + static $series = [ + [[PasswordUpgradeBadge::class], true], + [[UserBadge::class], false], + ]; + + [$expectedArgs, $return] = array_shift($series); + $this->assertSame($expectedArgs, $args); + + return $return; + }) + ; $passport->expects($this->once())->method('getBadge')->with(PasswordUpgradeBadge::class)->willReturn(new PasswordUpgradeBadge('pa$$word')); // We should never "getBadge" for "UserBadge::class" diff --git a/Tests/LoginLink/LoginLinkHandlerTest.php b/Tests/LoginLink/LoginLinkHandlerTest.php index 0d698362..6574a684 100644 --- a/Tests/LoginLink/LoginLinkHandlerTest.php +++ b/Tests/LoginLink/LoginLinkHandlerTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Security\Http\Tests\LoginLink; +use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Cache\CacheItemPoolInterface; @@ -80,9 +81,22 @@ public function testCreateLoginLink($user, array $extraProperties, Request $requ ->method('getContext') ->willReturn($currentRequestContext = new RequestContext()); + $series = [ + $this->equalTo((new RequestContext())->fromRequest($request)->setParameter('_locale', $request->getLocale())), + $currentRequestContext, + ]; + $this->router->expects($this->exactly(2)) ->method('setContext') - ->withConsecutive([$this->equalTo((new RequestContext())->fromRequest($request)->setParameter('_locale', $request->getLocale()))], [$currentRequestContext]); + ->willReturnCallback(function (RequestContext $context) use (&$series) { + $expectedContext = array_shift($series); + + if ($expectedContext instanceof Constraint) { + $expectedContext->evaluate($context); + } else { + $this->assertSame($expectedContext, $context); + } + }); } $loginLink = $this->createLinker([], array_keys($extraProperties))->createLoginLink($user, $request);