Skip to content

Commit a1c363e

Browse files
committed
withConsecutive method deprecation fix 7
1 parent 61d35f0 commit a1c363e

File tree

2 files changed

+47
-32
lines changed

2 files changed

+47
-32
lines changed

src/Test/Unit/App/Logger/Gelf/HandlerFactoryTest.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,32 @@ public function testCreate(): void
5959

6060
$this->repositoryMock->expects($this->exactly(2))
6161
->method('get')
62-
->withConsecutive(
63-
['transport'],
64-
['additional']
65-
)
66-
->willReturnOnConsecutiveCalls(
67-
[
62+
// withConsecutive() alternative.
63+
->willReturnCallback(fn($param) => match ([$param]) {
64+
['transport'] => [
6865
'http' => [
6966
'host' => 'localhost'
7067
],
7168
'tcp' => [
7269
'host' => '127.0.0.1'
7370
]
7471
],
75-
[
72+
['additional'] => [
7673
'project' => 'some_project'
7774
]
78-
);
75+
});
76+
$series = [
77+
[['http', ['host' => 'localhost']], $httpTransportMock],
78+
[['tcp', ['host' => '127.0.0.1']], $tcpTransportMock],
79+
];
7980
$this->transportFactoryMock->expects($this->exactly(2))
8081
->method('create')
81-
->withConsecutive(
82-
['http', ['host' => 'localhost']],
83-
['tcp', ['host' => '127.0.0.1']]
84-
)
85-
->willReturnOnConsecutiveCalls(
86-
$httpTransportMock,
87-
$tcpTransportMock
88-
);
82+
// withConsecutive() alternative.
83+
->willReturnCallback(function (...$args) use (&$series) {
84+
[$expectedArgs, $return] = array_shift($series);
85+
$this->assertSame($expectedArgs, $args);
86+
return $return;
87+
});
8988

9089
$this->handlerFactory->create($this->repositoryMock, Logger::INFO);
9190
}

src/Test/Unit/StaticContent/CommandFactoryTest.php

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,18 @@ public function testCreate(array $optionConfig, bool $useScdStrategy, string $ex
7777
->expects($this->exactly(3))
7878
->method('satisfies')
7979
->willReturn($useScdStrategy);
80+
$arguments = array_chunk($optionConfig['excluded_themes'], 1);
81+
$results = $optionConfig['resolve_return'];
8082
$this->themeResolverMock
8183
->expects($this->exactly(count($optionConfig['excluded_themes'])))
8284
->method('resolve')
83-
->withConsecutive(...array_chunk($optionConfig['excluded_themes'], 1))
84-
->willReturnOnConsecutiveCalls(...$optionConfig['resolve_return']);
85-
85+
// withConsecutive() alternative.
86+
->willReturnCallback(function ($arguments) use ($results) {
87+
static $callCount = 0;
88+
$returnValue = $results[$callCount] ?? null;
89+
$callCount++;
90+
return $returnValue;
91+
});
8692
$this->assertEquals(
8793
$expected,
8894
$this->commandFactory->create(
@@ -274,12 +280,18 @@ public function testMatrix(array $optionConfig, array $matrix, array $expected)
274280
->expects($this->any())
275281
->method('satisfies')
276282
->willReturn(true);
283+
$arguments = $optionConfig['resolve_pass'];
284+
$results = $optionConfig['resolve_return'];
277285
$this->themeResolverMock
278286
->expects($this->exactly(count($optionConfig['resolve_pass'])))
279287
->method('resolve')
280-
->withConsecutive(...$optionConfig['resolve_pass'])
281-
->willReturnOnConsecutiveCalls(...$optionConfig['resolve_return']);
282-
288+
// withConsecutive() alternative.
289+
->willReturnCallback(function ($arguments) use ($results) {
290+
static $callCount = 0;
291+
$returnValue = $results[$callCount] ?? null;
292+
$callCount++;
293+
return $returnValue;
294+
});
283295
$this->assertSame(
284296
$expected,
285297
$this->commandFactory->matrix($optionMock, $matrix)
@@ -390,11 +402,18 @@ public function testCreateNoResolve()
390402
->expects($this->exactly(3))
391403
->method('satisfies')
392404
->willReturn($useScdStrategy);
405+
$arguments = array_chunk($excludedThemes, 1);
406+
$results = $optionConfig['resolve_return'];
393407
$this->themeResolverMock
394408
->expects($this->exactly($this->count($excludedThemes)))
395409
->method('resolve')
396-
->withConsecutive(...array_chunk($excludedThemes, 1))
397-
->willReturnOnConsecutiveCalls(...$optionConfig['resolve_return']);
410+
// withConsecutive() alternative.
411+
->willReturnCallback(function ($arguments) use ($results) {
412+
static $callCount = 0;
413+
$returnValue = $results[$callCount] ?? null;
414+
$callCount++;
415+
return $returnValue;
416+
});
398417

399418
$this->assertEquals(
400419
$expected,
@@ -436,14 +455,11 @@ public function testMatrixNoResolve(): void
436455
$this->themeResolverMock
437456
->expects($this->exactly(2))
438457
->method('resolve')
439-
->withConsecutive(
440-
['Magento/Backend'],
441-
['Magento/Backend']
442-
)
443-
->willReturnOnConsecutiveCalls(
444-
'',
445-
''
446-
);
458+
// withConsecutive() alternative.
459+
->willReturnCallback(fn($param) => match ([$param]) {
460+
['Magento/Backend'] => '',
461+
['Magento/Backend'] => ''
462+
});
447463
$this->loggerMock
448464
->expects($this->once())
449465
->method('warning')

0 commit comments

Comments
 (0)