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 1bac251 + 80479fe commit 7fdbb6b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
8 changes: 7 additions & 1 deletion Tests/EventListener/DebugHandlersListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,13 @@ public function testLevelsAssignedToLoggers(bool $hasLogger, bool $hasDeprecatio
$handler
->expects($this->exactly(\count($expectedCalls)))
->method('setDefaultLogger')
->withConsecutive(...$expectedCalls);
->willReturnCallback(function (LoggerInterface $logger, $levels) use (&$expectedCalls) {
[$expectedLogger, $expectedLevels] = array_shift($expectedCalls);

$this->assertSame($expectedLogger, $logger);
$this->assertSame($expectedLevels, $levels);
})
;

$sut = new DebugHandlersListener(null, $logger, $levels, null, true, true, $deprecationLogger);
$prevHander = set_exception_handler([$handler, 'handleError']);
Expand Down
36 changes: 20 additions & 16 deletions Tests/EventListener/LocaleAwareListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ public function testLocaleIsSetInOnKernelRequest()

public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest()
{
$matcher = $this->exactly(2);
$this->localeAwareService
->expects($this->exactly(2))
->expects($matcher)
->method('setLocale')
->withConsecutive(
[$this->anything()],
['en']
)
->willReturnOnConsecutiveCalls(
$this->throwException(new \InvalidArgumentException())
);
->willReturnCallback(function (string $locale) use ($matcher) {
if (1 === $matcher->getInvocationCount()) {
throw new \InvalidArgumentException();
}

$this->assertSame('en', $locale);
})
;

$event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MAIN_REQUEST);
$this->listener->onKernelRequest($event);
Expand Down Expand Up @@ -90,16 +92,18 @@ public function testLocaleIsSetToDefaultOnKernelFinishRequestWhenParentRequestDo

public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest()
{
$matcher = $this->exactly(2);
$this->localeAwareService
->expects($this->exactly(2))
->expects($matcher)
->method('setLocale')
->withConsecutive(
[$this->anything()],
['en']
)
->willReturnOnConsecutiveCalls(
$this->throwException(new \InvalidArgumentException())
);
->willReturnCallback(function (string $locale) use ($matcher) {
if (1 === $matcher->getInvocationCount()) {
throw new \InvalidArgumentException();
}

$this->assertSame('en', $locale);
})
;

$this->requestStack->push($this->createRequest('fr'));
$this->requestStack->push($subRequest = $this->createRequest('de'));
Expand Down
10 changes: 6 additions & 4 deletions Tests/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ public function testShutdownGivesNullContainerToAllBundles()
$bundle = $this->createMock(Bundle::class);
$bundle->expects($this->exactly(2))
->method('setContainer')
->withConsecutive(
[$this->isInstanceOf(ContainerInterface::class)],
[null]
);
->willReturnCallback(function ($container) {
if (null !== $container) {
$this->assertInstanceOf(ContainerInterface::class, $container);
}
})
;

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

0 comments on commit 7fdbb6b

Please sign in to comment.