Skip to content

Commit

Permalink
minor #49621 [Tests] Remove occurrences of withConsecutive() (alexa…
Browse files Browse the repository at this point in the history
…ndre-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()`
  • Loading branch information
nicolas-grekas committed Mar 10, 2023
2 parents 6ab8f21 + 1ecf001 commit 428c849
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
13 changes: 9 additions & 4 deletions Tests/Authentication/DefaultAuthenticationFailureHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
14 changes: 13 additions & 1 deletion Tests/EventListener/PasswordMigratingListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
16 changes: 15 additions & 1 deletion Tests/LoginLink/LoginLinkHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 428c849

Please sign in to comment.