Skip to content

Commit 1ecf001

Browse files
alexandre-dauboisnicolas-grekas
authored andcommitted
[Tests] Remove occurrences of withConsecutive()
1 parent 7c71908 commit 1ecf001

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,15 @@ public function testFailurePathFromRequestWithInvalidUrl()
197197

198198
$this->logger->expects($this->exactly(2))
199199
->method('debug')
200-
->withConsecutive(
201-
['Ignoring query parameter "_my_failure_path": not a valid URL.'],
202-
['Authentication failure, redirect triggered.', ['failure_path' => '/login']]
203-
);
200+
->willReturnCallback(function (...$args) {
201+
static $series = [
202+
['Ignoring query parameter "_my_failure_path": not a valid URL.', []],
203+
['Authentication failure, redirect triggered.', ['failure_path' => '/login']],
204+
];
205+
206+
$expectedArgs = array_shift($series);
207+
$this->assertSame($expectedArgs, $args);
208+
});
204209

205210
$handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, $options, $this->logger);
206211

Tests/EventListener/PasswordMigratingListenerTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,19 @@ public function testUnsupportedPassport()
8585
// A custom Passport, without an UserBadge
8686
$passport = $this->createMock(UserPassportInterface::class);
8787
$passport->method('getUser')->willReturn($this->user);
88-
$passport->method('hasBadge')->withConsecutive([PasswordUpgradeBadge::class], [UserBadge::class])->willReturnOnConsecutiveCalls(true, false);
88+
$passport->method('hasBadge')
89+
->willReturnCallback(function (...$args) {
90+
static $series = [
91+
[[PasswordUpgradeBadge::class], true],
92+
[[UserBadge::class], false],
93+
];
94+
95+
[$expectedArgs, $return] = array_shift($series);
96+
$this->assertSame($expectedArgs, $args);
97+
98+
return $return;
99+
})
100+
;
89101
$passport->expects($this->once())->method('getBadge')->with(PasswordUpgradeBadge::class)->willReturn(new PasswordUpgradeBadge('pa$$word'));
90102
// We should never "getBadge" for "UserBadge::class"
91103

Tests/LoginLink/LoginLinkHandlerTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Security\Http\Tests\LoginLink;
1313

14+
use PHPUnit\Framework\Constraint\Constraint;
1415
use PHPUnit\Framework\MockObject\MockObject;
1516
use PHPUnit\Framework\TestCase;
1617
use Psr\Cache\CacheItemPoolInterface;
@@ -80,9 +81,22 @@ public function testCreateLoginLink($user, array $extraProperties, Request $requ
8081
->method('getContext')
8182
->willReturn($currentRequestContext = new RequestContext());
8283

84+
$series = [
85+
$this->equalTo((new RequestContext())->fromRequest($request)->setParameter('_locale', $request->getLocale())),
86+
$currentRequestContext,
87+
];
88+
8389
$this->router->expects($this->exactly(2))
8490
->method('setContext')
85-
->withConsecutive([$this->equalTo((new RequestContext())->fromRequest($request)->setParameter('_locale', $request->getLocale()))], [$currentRequestContext]);
91+
->willReturnCallback(function (RequestContext $context) use (&$series) {
92+
$expectedContext = array_shift($series);
93+
94+
if ($expectedContext instanceof Constraint) {
95+
$expectedContext->evaluate($context);
96+
} else {
97+
$this->assertSame($expectedContext, $context);
98+
}
99+
});
86100
}
87101

88102
$loginLink = $this->createLinker([], array_keys($extraProperties))->createLoginLink($user, $request);

0 commit comments

Comments
 (0)