Skip to content

Commit 7fdbb6b

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 1bac251 + 80479fe commit 7fdbb6b

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

Tests/EventListener/DebugHandlersListenerTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,13 @@ public function testLevelsAssignedToLoggers(bool $hasLogger, bool $hasDeprecatio
222222
$handler
223223
->expects($this->exactly(\count($expectedCalls)))
224224
->method('setDefaultLogger')
225-
->withConsecutive(...$expectedCalls);
225+
->willReturnCallback(function (LoggerInterface $logger, $levels) use (&$expectedCalls) {
226+
[$expectedLogger, $expectedLevels] = array_shift($expectedCalls);
227+
228+
$this->assertSame($expectedLogger, $logger);
229+
$this->assertSame($expectedLevels, $levels);
230+
})
231+
;
226232

227233
$sut = new DebugHandlersListener(null, $logger, $levels, null, true, true, $deprecationLogger);
228234
$prevHander = set_exception_handler([$handler, 'handleError']);

Tests/EventListener/LocaleAwareListenerTest.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ public function testLocaleIsSetInOnKernelRequest()
4646

4747
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest()
4848
{
49+
$matcher = $this->exactly(2);
4950
$this->localeAwareService
50-
->expects($this->exactly(2))
51+
->expects($matcher)
5152
->method('setLocale')
52-
->withConsecutive(
53-
[$this->anything()],
54-
['en']
55-
)
56-
->willReturnOnConsecutiveCalls(
57-
$this->throwException(new \InvalidArgumentException())
58-
);
53+
->willReturnCallback(function (string $locale) use ($matcher) {
54+
if (1 === $matcher->getInvocationCount()) {
55+
throw new \InvalidArgumentException();
56+
}
57+
58+
$this->assertSame('en', $locale);
59+
})
60+
;
5961

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

9193
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest()
9294
{
95+
$matcher = $this->exactly(2);
9396
$this->localeAwareService
94-
->expects($this->exactly(2))
97+
->expects($matcher)
9598
->method('setLocale')
96-
->withConsecutive(
97-
[$this->anything()],
98-
['en']
99-
)
100-
->willReturnOnConsecutiveCalls(
101-
$this->throwException(new \InvalidArgumentException())
102-
);
99+
->willReturnCallback(function (string $locale) use ($matcher) {
100+
if (1 === $matcher->getInvocationCount()) {
101+
throw new \InvalidArgumentException();
102+
}
103+
104+
$this->assertSame('en', $locale);
105+
})
106+
;
103107

104108
$this->requestStack->push($this->createRequest('fr'));
105109
$this->requestStack->push($subRequest = $this->createRequest('de'));

Tests/KernelTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,12 @@ public function testShutdownGivesNullContainerToAllBundles()
182182
$bundle = $this->createMock(Bundle::class);
183183
$bundle->expects($this->exactly(2))
184184
->method('setContainer')
185-
->withConsecutive(
186-
[$this->isInstanceOf(ContainerInterface::class)],
187-
[null]
188-
);
185+
->willReturnCallback(function ($container) {
186+
if (null !== $container) {
187+
$this->assertInstanceOf(ContainerInterface::class, $container);
188+
}
189+
})
190+
;
189191

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

0 commit comments

Comments
 (0)