Skip to content

Commit 428c849

Browse files
minor #49621 [Tests] Remove occurrences of withConsecutive() (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [Tests] Remove occurrences of `withConsecutive()` | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - `withConsecutive()` has been deprecated in PHPUnit 9.6 and removed in PHP 10 (sebastianbergmann/phpunit#4564). This PR aims at starting the work to remove these occurrences. There is unfortunately no given migration path, and this requires manual work. I'll create a meta issue referencing remaining occurrences if this one's merged, to keep track. Some seems pretty hard to remove. cc `@OskarStark` this might interest you, as we worked a lot on tests lately 😄 Commits ------- 2047763649 [Tests] Remove occurrences of `withConsecutive()`
2 parents 6ab8f21 + 1ecf001 commit 428c849

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)