Skip to content

Commit 8687ee7

Browse files
committed
withConsecutive method deprecation fix 3
1 parent fd22437 commit 8687ee7

File tree

19 files changed

+365
-178
lines changed

19 files changed

+365
-178
lines changed

src/Test/Unit/App/Logger/PoolTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,22 @@ public function testGetHandlers(): void
125125
->with($jsonErrorFormatterMock)
126126
->willReturnSelf();
127127

128+
$series = [
129+
[['slack'], $slackHandlerMock],
130+
[['email'], $emailHandlerMock],
131+
[['syslog'], $syslogHandler],
132+
[['error-logger'], $errorHandler],
133+
];
134+
128135
$this->handlerFactoryMock->expects($this->exactly(4))
129136
->method('create')
130-
->withConsecutive(['slack'], ['email'], ['syslog'], ['error-logger'])
131-
->willReturnOnConsecutiveCalls($slackHandlerMock, $emailHandlerMock, $syslogHandler, $errorHandler);
137+
// withConsecutive() alternative.
138+
->willReturnCallback(function (...$args) use (&$series) {
139+
[$expectedArgs, $return] = array_shift($series);
140+
$this->assertSame($expectedArgs, $args);
141+
142+
return $return;
143+
});
132144

133145
$this->pool->getHandlers();
134146
// Lazy load.

src/Test/Unit/Command/ConfigDumpTest.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use PHPUnit\Framework\TestCase;
2020
use Psr\Log\LoggerInterface;
2121
use Symfony\Component\Console\Tester\CommandTester;
22+
use Magento\MagentoCloud\Shell\ProcessInterface;
2223

2324
/**
2425
* @inheritdoc
@@ -71,6 +72,11 @@ class ConfigDumpTest extends TestCase
7172
*/
7273
private $stageConfigMock;
7374

75+
/**
76+
* @var ProcessInterface|MockObject
77+
*/
78+
private $processMock;
79+
7480
/**
7581
* @inheritdoc
7682
*/
@@ -84,6 +90,7 @@ protected function setUp(): void
8490
$this->writerMock = $this->getMockForAbstractClass(WriterInterface::class);
8591
$this->magentoVersionMock = $this->createMock(MagentoVersion::class);
8692
$this->stageConfigMock = $this->createMock(PostDeployInterface::class);
93+
$this->processMock = $this->getMockForAbstractClass(ProcessInterface::class);
8794

8895
$this->shellFactoryMock->method('createMagento')
8996
->willReturn($this->shellMock);
@@ -95,18 +102,20 @@ protected function setUp(): void
95102
$this->readerMock,
96103
$this->writerMock,
97104
$this->magentoVersionMock,
98-
$this->stageConfigMock
105+
$this->stageConfigMock,
106+
$this->processMock
99107
);
100108
}
101109

102110
public function testExecute()
103111
{
104112
$this->loggerMock->expects($this->exactly(2))
105113
->method('info')
106-
->withConsecutive(
107-
['Starting dump.'],
108-
['Dump completed.']
109-
);
114+
// withConsecutive() alternative.
115+
->willReturnCallback(fn($param) => match ([$param]) {
116+
['Starting dump.'] => $this->loggerMock,
117+
['Dump completed.'] => $this->loggerMock
118+
});
110119
$this->generateMock->expects($this->once())
111120
->method('execute');
112121
$this->readerMock->expects($this->once())
@@ -118,7 +127,11 @@ public function testExecute()
118127
->willReturn(true);
119128
$this->shellMock->expects($this->exactly(2))
120129
->method('execute')
121-
->withConsecutive(['app:config:dump'], ['app:config:import']);
130+
// withConsecutive() alternative.
131+
->willReturnCallback(fn($param) => match ([$param]) {
132+
['app:config:dump'] => $this->processMock,
133+
['app:config:import'] => $this->processMock
134+
});
122135

123136
$tester = new CommandTester(
124137
$this->command
@@ -135,10 +148,11 @@ public function testExecute21Version()
135148
->willReturn('-v');
136149
$this->loggerMock->expects($this->exactly(2))
137150
->method('info')
138-
->withConsecutive(
139-
['Starting dump.'],
140-
['Dump completed.']
141-
);
151+
// withConsecutive() alternative.
152+
->willReturnCallback(fn($param) => match ([$param]) {
153+
['Starting dump.'] => $this->loggerMock,
154+
['Dump completed.'] => $this->loggerMock
155+
});
142156
$this->generateMock->expects($this->once())
143157
->method('execute');
144158
$this->readerMock->expects($this->once())

src/Test/Unit/Config/Factory/CacheTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ public function testGetWithoutRedisAndWithNotValidEnvConfig(): void
119119
{
120120
$this->stageConfigMock->expects(self::exactly(2))
121121
->method('get')
122-
->withConsecutive([DeployInterface::VAR_CACHE_CONFIGURATION], [DeployInterface::VAR_CACHE_REDIS_BACKEND])
123-
->willReturnOnConsecutiveCalls([], '');
122+
// withConsecutive() alternative.
123+
->willReturnCallback(fn($param) => match ([$param]) {
124+
[DeployInterface::VAR_CACHE_CONFIGURATION] => [],
125+
[DeployInterface::VAR_CACHE_REDIS_BACKEND] => ''
126+
});
124127
$this->redisMock->expects(self::once())
125128
->method('getConfiguration')
126129
->willReturn([]);

src/Test/Unit/Config/StateTest.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,18 @@ public function testInstalledWithCryptKeyOnlyInEnvironmentVar(): void
190190
{
191191
$date = 'Wed, 12 Sep 2017 10:40:30 +0000';
192192
$config = ['install' => ['date' => $date]];
193-
193+
$series = [
194+
'Checking if db exists and has tables',
195+
'Magento was installed on ' . $date
196+
];
197+
194198
$this->loggerMock->expects($this->exactly(2))
195199
->method('info')
196-
->withConsecutive(
197-
['Checking if db exists and has tables'],
198-
['Magento was installed on ' . $date]
199-
);
200+
// withConsecutive() alternative.
201+
->willReturnCallback(function ($args) use (&$series) {
202+
$expectedArgs = array_shift($series);
203+
$this->assertSame($expectedArgs, $args);
204+
});
200205
$this->mockForTablesExist($config);
201206
$this->environmentMock->expects($this->once())
202207
->method('getCryptKey')
@@ -217,13 +222,18 @@ public function testIsInstalledWithFullData(): void
217222
'install' => ['date' => $date],
218223
'crypt' => ['key' => 'crypt_key_value']
219224
];
225+
$series = [
226+
'Checking if db exists and has tables',
227+
'Magento was installed on ' . $date
228+
];
220229

221230
$this->loggerMock->expects($this->exactly(2))
222231
->method('info')
223-
->withConsecutive(
224-
['Checking if db exists and has tables'],
225-
['Magento was installed on ' . $date]
226-
);
232+
// withConsecutive() alternative.
233+
->willReturnCallback(function ($args) use (&$series) {
234+
$expectedArgs = array_shift($series);
235+
$this->assertSame($expectedArgs, $args);
236+
});
227237
$this->mockForTablesExist($config);
228238
$this->writerMock->expects($this->never())
229239
->method('update');
@@ -238,8 +248,11 @@ private function mockForTablesExist($config = [])
238248
->willReturn(['core_config_data', 'setup_module']);
239249
$this->connectionMock->expects($this->exactly(2))
240250
->method('getTableName')
241-
->withConsecutive(['core_config_data'], ['setup_module'])
242-
->willReturnOnConsecutiveCalls('core_config_data', 'setup_module');
251+
// withConsecutive() alternative.
252+
->willReturnCallback(fn($param) => match ([$param]) {
253+
['core_config_data'] => 'core_config_data',
254+
['setup_module'] => 'setup_module'
255+
});
243256
$this->readerMock->expects($this->once())
244257
->method('read')
245258
->willReturn($config);

src/Test/Unit/Config/Validator/Build/OpcacheExcludePathsTest.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ public function testValidateSuccess(): void
8585
->willReturn($excludeListPath);
8686
$this->fileMock->expects($this->exactly(2))
8787
->method('isExists')
88-
->withConsecutive([$phpIniPath], [$excludeListPath])
89-
->willReturn(true);
88+
// withConsecutive() alternative.
89+
->willReturnCallback(fn($param) => match ([$param]) {
90+
[$phpIniPath] => true,
91+
[$excludeListPath] => true
92+
});
9093
$this->fileMock->expects($this->once())
9194
->method('parseIni')
9295
->with($phpIniPath)
@@ -132,8 +135,11 @@ public function testValidateFilesDoNotExist(
132135
->willReturn($excludeListPath);
133136
$this->fileMock->expects($this->exactly($invokeCount))
134137
->method('isExists')
135-
->withConsecutive([$phpIniPath], [$excludeListPath])
136-
->willReturnOnConsecutiveCalls($phpIniExists, $opCacheExcludeListExists);
138+
// withConsecutive() alternative.
139+
->willReturnCallback(fn($param) => match ([$param]) {
140+
[$phpIniPath] => $phpIniExists,
141+
[$excludeListPath] => $opCacheExcludeListExists
142+
});
137143
$this->resultFactoryMock->expects($this->never())
138144
->method('create');
139145
$this->resultFactoryMock->expects($this->once())
@@ -194,8 +200,11 @@ public function testValidatePhpIniWrongConfiguration($phpIni): void
194200
->willReturn($excludeListPath);
195201
$this->fileMock->expects($this->exactly(2))
196202
->method('isExists')
197-
->withConsecutive([$phpIniPath], [$excludeListPath])
198-
->willReturn(true);
203+
// withConsecutive() alternative.
204+
->willReturnCallback(fn($param) => match ([$param]) {
205+
[$phpIniPath] => true,
206+
[$excludeListPath] => true
207+
});
199208
$this->fileMock->expects($this->once())
200209
->method('parseIni')
201210
->with($phpIniPath)
@@ -254,8 +263,11 @@ public function testValidateMissedPaths(): void
254263
->willReturn($excludeListPath);
255264
$this->fileMock->expects($this->exactly(2))
256265
->method('isExists')
257-
->withConsecutive([$phpIniPath], [$excludeListPath])
258-
->willReturn(true);
266+
// withConsecutive() alternative.
267+
->willReturnCallback(fn($param) => match ([$param]) {
268+
[$phpIniPath] => true,
269+
[$excludeListPath] => true
270+
});
259271
$this->fileMock->expects($this->once())
260272
->method('parseIni')
261273
->with($phpIniPath)

src/Test/Unit/DB/DumpProcessorTest.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ protected function setUp(): void
122122
*/
123123
public function testExecute(array $dbConfig, $expects, bool $removeDefiners)
124124
{
125+
$series = [
126+
['main', $this->connectionDataMock, $removeDefiners],
127+
['quote', $this->connectionDataMock, $removeDefiners],
128+
['sales', $this->connectionDataMock, $removeDefiners]
129+
];
125130
$this->dbConfigMock->expects($this->once())
126131
->method('get')
127132
->willReturn($dbConfig);
@@ -133,11 +138,16 @@ public function testExecute(array $dbConfig, $expects, bool $removeDefiners)
133138
->method('kill');
134139
$this->dumpGeneratorMock->expects($expects)
135140
->method('create')
136-
->withConsecutive(
141+
/*->withConsecutive(
137142
['main', $this->connectionDataMock, $removeDefiners],
138143
['quote', $this->connectionDataMock, $removeDefiners],
139144
['sales', $this->connectionDataMock, $removeDefiners]
140-
);
145+
);*/
146+
// withConsecutive() alternative.
147+
->willReturnCallback(function (...$args) use (&$series) {
148+
$expectedArgs = array_shift($series);
149+
$this->assertSame($expectedArgs, $args);
150+
});
141151

142152
$this->dumpProcessor->execute($removeDefiners);
143153
}
@@ -204,6 +214,11 @@ public function testExecuteWithDatabases(
204214
array $databases,
205215
$expects
206216
) {
217+
$series = [
218+
['main', $this->connectionDataMock, true],
219+
['quote', $this->connectionDataMock, true],
220+
['sales', $this->connectionDataMock, true]
221+
];
207222
$this->dbConfigMock->expects($this->once())
208223
->method('get')
209224
->willReturn([
@@ -222,11 +237,16 @@ public function testExecuteWithDatabases(
222237
->method('kill');
223238
$this->dumpGeneratorMock->expects($expects)
224239
->method('create')
225-
->withConsecutive(
240+
/*->withConsecutive(
226241
['main', $this->connectionDataMock, true],
227242
['quote', $this->connectionDataMock, true],
228243
['sales', $this->connectionDataMock, true]
229-
);
244+
);*/
245+
// withConsecutive() alternative.
246+
->willReturnCallback(function (...$args) use (&$series) {
247+
$expectedArgs = array_shift($series);
248+
$this->assertSame($expectedArgs, $args);
249+
});
230250

231251
$this->dumpProcessor->execute(true, $databases);
232252
}

src/Test/Unit/Filesystem/DirectoryCopier/CopyStrategyTest.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public function testCopy(): void
5050
{
5151
$this->fileMock->expects($this->exactly(2))
5252
->method('isExists')
53-
->withConsecutive(
54-
['fromDir'],
55-
['toDir']
56-
)
57-
->willReturn(true);
53+
// withConsecutive() alternative.
54+
->willReturnCallback(fn($param) => match ([$param]) {
55+
['fromDir'] => true,
56+
['toDir'] => true
57+
});
5858
$this->fileMock->expects($this->once())
5959
->method('isLink')
6060
->with('toDir')
@@ -72,14 +72,11 @@ public function testCopyToDirectoryIsLink(): void
7272
{
7373
$this->fileMock->expects($this->exactly(2))
7474
->method('isExists')
75-
->withConsecutive(
76-
['fromDir'],
77-
['toDir']
78-
)
79-
->willReturnOnConsecutiveCalls(
80-
true,
81-
false
82-
);
75+
// withConsecutive() alternative.
76+
->willReturnCallback(fn($param) => match ([$param]) {
77+
['fromDir'] => true,
78+
['toDir'] => false
79+
});
8380
$this->fileMock->expects($this->once())
8481
->method('isLink')
8582
->with('toDir')

src/Test/Unit/Filesystem/DirectoryCopier/SubSymlinkStrategyTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,15 @@ public function testCopy(): void
7676
->willReturn($directoryIteratorMock);
7777
$this->fileMock->expects($this->exactly(2))
7878
->method('symlink')
79-
->withConsecutive(
80-
['realFromDir/file1', 'toDir/file1'],
81-
['realFromDir/file2', 'toDir/file2']
82-
);
79+
// withConsecutive() alternative.
80+
->willReturnCallback(function (...$args) {
81+
static $series = [
82+
['realFromDir/file1', 'toDir/file1'],
83+
['realFromDir/file2', 'toDir/file2']
84+
];
85+
$expectedArgs = array_shift($series);
86+
$this->assertSame($expectedArgs, $args);
87+
});
8388

8489
$this->assertTrue($this->subSymlinkStrategy->copy('fromDir', 'toDir'));
8590
}

src/Test/Unit/Filesystem/Flag/ManagerTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,21 @@ public function testDelete(
219219
->willReturn($deleteResult);
220220
$this->loggerMock->expects($this->exactly(count($logs)))
221221
->method('info')
222-
->withConsecutive($logs);
222+
// withConsecutive() alternative.
223+
->willReturnCallback(function ($logs) {
224+
if (!empty($args)) {
225+
return null;
226+
}
227+
});
223228
} else {
224229
$this->loggerMock->expects($this->exactly(count($logs)))
225230
->method('debug')
226-
->withConsecutive($logs);
231+
// withConsecutive() alternative.
232+
->willReturnCallback(function ($logs) {
233+
if (!empty($args)) {
234+
return null;
235+
}
236+
});
227237
}
228238

229239
$this->assertSame(

0 commit comments

Comments
 (0)