Skip to content

Commit 66f9f72

Browse files
committed
withConsecutive method deprecation fix 4
1 parent 8687ee7 commit 66f9f72

File tree

10 files changed

+231
-110
lines changed

10 files changed

+231
-110
lines changed

src/Test/Unit/Command/CronUnlockTest.php

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ public function testExecute(): void
6060
{
6161
$this->loggerMock->expects($this->exactly(3))
6262
->method('info')
63-
->withConsecutive(
64-
['Starting unlocking.'],
65-
['Unlocking all cron jobs.'],
66-
['Unlocking completed.']
67-
);
63+
// withConsecutive() alternative.
64+
->willReturnCallback(function (string $axis) {
65+
static $series = [
66+
'Starting unlocking.',
67+
'Unlocking all cron jobs.',
68+
'Unlocking completed.'
69+
];
70+
$this->assertSame(array_shift($series), $axis);
71+
});
6872
$this->jobUnlockerMock->expects($this->once())
6973
->method('unlockAll')
7074
->with(CronUnlock::UNLOCK_MESSAGE);
@@ -83,20 +87,33 @@ public function testExecuteWithJobCode(): void
8387
{
8488
$this->loggerMock->expects($this->exactly(4))
8589
->method('info')
86-
->withConsecutive(
87-
['Starting unlocking.'],
88-
['Unlocking cron jobs with code #code1.'],
89-
['Unlocking cron jobs with code #code2.'],
90-
['Unlocking completed.']
91-
);
90+
// withConsecutive() alternative.
91+
->willReturnCallback(function (string $axis) {
92+
static $series = [
93+
'Starting unlocking.',
94+
'Unlocking cron jobs with code #code1.',
95+
'Unlocking cron jobs with code #code2.',
96+
'Unlocking completed.'
97+
];
98+
99+
$this->assertSame(array_shift($series), $axis);
100+
});
92101
$this->jobUnlockerMock->expects($this->never())
93102
->method('unlockAll');
103+
$codes = [
104+
'code1',
105+
'code2'
106+
];
94107
$this->jobUnlockerMock->expects($this->exactly(2))
95108
->method('unlockByJobCode')
96-
->withConsecutive(
97-
['code1', CronUnlock::UNLOCK_MESSAGE],
98-
['code2', CronUnlock::UNLOCK_MESSAGE]
109+
// withConsecutive() alternative.
110+
->with(
111+
$this->callback(function (string $code) use (&$codes) {
112+
return array_shift($codes) === $code;
113+
}),
114+
CronUnlock::UNLOCK_MESSAGE
99115
);
116+
100117

101118
$tester = new CommandTester(
102119
$this->cronUnlockCommand

src/Test/Unit/Command/Dev/UpdateComposerTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,22 @@ public function testExecute(): void
128128
],
129129
],
130130
]);
131+
$scripts = [
132+
'script2',
133+
'script3',
134+
'script4',
135+
'script5',
136+
'composer update --ansi --no-interaction'
137+
];
131138
$this->shellMock->expects($this->exactly(5))
132139
->method('execute')
133-
->withConsecutive(
134-
['script2'],
135-
['script3'],
136-
['script4'],
137-
['script5'],
138-
['composer update --ansi --no-interaction']
140+
// withConsecutive() alternative.
141+
->with(
142+
$this->callback(function (string $script) use (&$scripts) {
143+
return array_shift($scripts) === $script;
144+
})
139145
);
146+
140147
$this->fileListMock->expects($this->once())
141148
->method('getMagentoComposer')
142149
->willReturn('/magento_root/composer.json');

src/Test/Unit/Config/Validator/Deploy/ServiceVersionTest.php

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,60 @@ public function testValidate(): void
119119
);
120120
$this->loggerMock->expects($this->exactly(6))
121121
->method('info')
122-
->withConsecutive(
122+
/*->withConsecutive(
123123
['Version of service \'rabbitmq\' is not detected', []],
124124
['Version of service \'redis\' is 3.2', []],
125125
['Version of service \'redis-session\' is 3.2', []],
126126
['Version of service \'elasticsearch\' is 7.7', []],
127127
['Version of service \'opensearch\' is 1.2', []],
128128
['Version of service \'mariadb\' is 10.2', []]
129-
);
129+
);*/
130+
// withConsecutive() alternative.
131+
->willReturnCallback(function (...$args) {
132+
static $series = [
133+
['Version of service \'rabbitmq\' is not detected', []],
134+
['Version of service \'redis\' is 3.2', []],
135+
['Version of service \'redis-session\' is 3.2', []],
136+
['Version of service \'elasticsearch\' is 7.7', []],
137+
['Version of service \'opensearch\' is 1.2', []],
138+
['Version of service \'mariadb\' is 10.2', []]
139+
];
140+
$expectedArgs = array_shift($series);
141+
$this->assertSame($expectedArgs, $args);
142+
});
143+
$series = [
144+
[ServiceInterface::NAME_REDIS, '3.2'],
145+
[ServiceInterface::NAME_REDIS_SESSION, '3.2'],
146+
[ServiceInterface::NAME_ELASTICSEARCH, '7.7'],
147+
[ServiceInterface::NAME_OPENSEARCH, '1.2'],
148+
[ServiceInterface::NAME_DB_MARIA, '10.2']
149+
];
130150
$this->serviceVersionValidatorMock->expects($this->exactly(5))
131151
->method('validateService')
132-
->withConsecutive(
152+
/*->withConsecutive(
133153
[ServiceInterface::NAME_REDIS, '3.2'],
134154
[ServiceInterface::NAME_REDIS_SESSION, '3.2'],
135155
[ServiceInterface::NAME_ELASTICSEARCH, '7.7'],
136156
[ServiceInterface::NAME_OPENSEARCH, '1.2'],
137157
[ServiceInterface::NAME_DB_MARIA, '10.2']
138158
)
139-
->willReturn('');
159+
->willReturn('');*/
160+
/*->willReturnCallback(function ($arg1) use ($series) {
161+
if (in_array($arg1, $series)) {
162+
return 'test';
163+
}
164+
});*/
165+
->willReturnCallback(function (...$args) {
166+
static $series = [
167+
[ServiceInterface::NAME_REDIS, '3.2'],
168+
[ServiceInterface::NAME_REDIS_SESSION, '3.2'],
169+
[ServiceInterface::NAME_ELASTICSEARCH, '7.7'],
170+
[ServiceInterface::NAME_OPENSEARCH, '1.2'],
171+
[ServiceInterface::NAME_DB_MARIA, '10.2']
172+
];
173+
$expectedArgs = array_shift($series);
174+
$this->assertSame($expectedArgs, $args);
175+
});
140176
$this->resultFactoryMock->expects($this->once())
141177
->method('success');
142178

@@ -185,15 +221,23 @@ public function testValidateWithErrors(): void
185221
->willReturnOnConsecutiveCalls($service1, $service2, $service3, $service4, $service5, $service6);
186222
$this->serviceVersionValidatorMock->expects($this->exactly(6))
187223
->method('validateService')
188-
->withConsecutive(
224+
/*->withConsecutive(
189225
[ServiceInterface::NAME_RABBITMQ, '1.5'],
190226
[ServiceInterface::NAME_REDIS, '2.2'],
191227
[ServiceInterface::NAME_REDIS_SESSION, '2.2'],
192228
[ServiceInterface::NAME_ELASTICSEARCH, '7.7'],
193229
[ServiceInterface::NAME_OPENSEARCH, '1.2'],
194230
[ServiceInterface::NAME_DB_MYSQL, '5.7']
195231
)
196-
->willReturnOnConsecutiveCalls(...$errorMessages);
232+
->willReturnOnConsecutiveCalls(...$errorMessages);*/
233+
->willReturnCallback(fn($param) => match ($param) {
234+
ServiceInterface::NAME_RABBITMQ, '1.5' => $errorMessages,
235+
ServiceInterface::NAME_REDIS, '2.2' => $errorMessages,
236+
ServiceInterface::NAME_REDIS_SESSION, '2.2' => $errorMessages,
237+
ServiceInterface::NAME_ELASTICSEARCH, '7.7' => $errorMessages,
238+
ServiceInterface::NAME_OPENSEARCH, '1.2' => $errorMessages,
239+
ServiceInterface::NAME_DB_MYSQL, '5.7' => $errorMessages
240+
});
197241
$this->resultFactoryMock->expects($this->once())
198242
->method('error')
199243
->with($this->anything(), implode(PHP_EOL, $errorMessages));

src/Test/Unit/DB/ConnectionTest.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,18 @@ public function testAffectingQuery()
174174

175175
$this->statementMock->expects($this->exactly(2))
176176
->method('bindValue')
177-
->withConsecutive(
177+
/*->withConsecutive(
178178
[':name', 'John', \PDO::PARAM_STR],
179179
[':age', 2, \PDO::PARAM_INT]
180-
);
180+
);*/
181+
->willReturnCallback(function (...$args) {
182+
static $series = [
183+
[':name', 'John', \PDO::PARAM_STR],
184+
[':age', 2, \PDO::PARAM_INT]
185+
];
186+
$expectedArgs = array_shift($series);
187+
$this->assertSame($expectedArgs, $args);
188+
});
181189
$this->statementMock->expects($this->once())
182190
->method('rowCount')
183191
->willReturn(1);
@@ -194,10 +202,18 @@ public function testQuery()
194202

195203
$this->statementMock->expects($this->exactly(2))
196204
->method('bindValue')
197-
->withConsecutive(
205+
/*->withConsecutive(
198206
[':name', 'John', \PDO::PARAM_STR],
199207
[':age', 2, \PDO::PARAM_INT]
200-
);
208+
);*/
209+
->willReturnCallback(function (...$args) {
210+
static $series = [
211+
[':name', 'John', \PDO::PARAM_STR],
212+
[':age', 2, \PDO::PARAM_INT]
213+
];
214+
$expectedArgs = array_shift($series);
215+
$this->assertSame($expectedArgs, $args);
216+
});
201217
$this->statementMock->expects($this->once())
202218
->method('execute')
203219
->willReturn(true);

src/Test/Unit/DB/DumpProcessorTest.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,21 @@ public function testExecute(array $dbConfig, $expects, bool $removeDefiners)
136136
->method('disable');
137137
$this->backgroundProcessMock->expects($this->once())
138138
->method('kill');
139+
$mocks = [
140+
'main',
141+
'quote',
142+
'sales'
143+
];
139144
$this->dumpGeneratorMock->expects($expects)
140145
->method('create')
141-
/*->withConsecutive(
142-
['main', $this->connectionDataMock, $removeDefiners],
143-
['quote', $this->connectionDataMock, $removeDefiners],
144-
['sales', $this->connectionDataMock, $removeDefiners]
145-
);*/
146146
// withConsecutive() alternative.
147-
->willReturnCallback(function (...$args) use (&$series) {
148-
$expectedArgs = array_shift($series);
149-
$this->assertSame($expectedArgs, $args);
150-
});
147+
->with(
148+
$this->callback(function (string $mock) use (&$mocks) {
149+
return array_shift($mocks) === $mock;
150+
}),
151+
$this->connectionDataMock,
152+
$removeDefiners
153+
);
151154

152155
$this->dumpProcessor->execute($removeDefiners);
153156
}
@@ -235,18 +238,21 @@ public function testExecuteWithDatabases(
235238
->method('disable');
236239
$this->backgroundProcessMock->expects($this->once())
237240
->method('kill');
241+
$mocks = [
242+
'main',
243+
'quote',
244+
'sales'
245+
];
238246
$this->dumpGeneratorMock->expects($expects)
239247
->method('create')
240-
/*->withConsecutive(
241-
['main', $this->connectionDataMock, true],
242-
['quote', $this->connectionDataMock, true],
243-
['sales', $this->connectionDataMock, true]
244-
);*/
245248
// withConsecutive() alternative.
246-
->willReturnCallback(function (...$args) use (&$series) {
247-
$expectedArgs = array_shift($series);
248-
$this->assertSame($expectedArgs, $args);
249-
});
249+
->with(
250+
$this->callback(function (string $mock) use (&$mocks) {
251+
return array_shift($mocks) === $mock;
252+
}),
253+
$this->connectionDataMock,
254+
true
255+
);
250256

251257
$this->dumpProcessor->execute(true, $databases);
252258
}

src/Test/Unit/Step/Deploy/InstallUpdate/ConfigUpdate/Urls/DatabaseTest.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,15 @@ public function testExecute(
8080
): void {
8181
$this->loggerMock->expects($loggerInfoExpects)
8282
->method('info')
83-
->withConsecutive(
84-
['Updating secure and unsecure URLs in core_config_data table.'],
85-
['Host was replaced: [example1.com] => [example2.com]']
86-
);
83+
// withConsecutive() alternative.
84+
->willReturnCallback(function ($args) {
85+
static $series = [
86+
'Updating secure and unsecure URLs in core_config_data table.',
87+
'Host was replaced: [example1.com] => [example2.com]'
88+
];
89+
$expectedArgs = array_shift($series);
90+
$this->assertSame($expectedArgs, $args);
91+
});
8792
$this->connectionMock->expects($this->once())
8893
->method('select')
8994
->with(
@@ -102,17 +107,13 @@ public function testExecute(
102107
->willReturn($urlManagerGetUrlsWillReturn);
103108
$this->connectionMock->expects($connectionExpectsAffectingQuery)
104109
->method('affectingQuery')
105-
->withConsecutive(
106-
[
110+
// withConsecutive() alternative.
111+
->willReturnCallback(fn($param) => match ($param) {
112+
['UPDATE `core_config_data` SET `value` = REPLACE(`value`, ?, ?) WHERE `value` LIKE ?',
113+
['example1.com', 'example2.com', '%example1.com%']] => 2,
107114
'UPDATE `core_config_data` SET `value` = REPLACE(`value`, ?, ?) WHERE `value` LIKE ?',
108-
['example1.com', 'example2.com', '%example1.com%']
109-
],
110-
[
111-
'UPDATE `core_config_data` SET `value` = REPLACE(`value`, ?, ?) WHERE `value` LIKE ?',
112-
['example1.com', 'example2.com', '%example1.com%']
113-
]
114-
)
115-
->willReturnOnConsecutiveCalls(2, 0);
115+
['example1.com', 'example2.com', '%example1.com%'] => 0,
116+
});
116117

117118
$this->step->execute();
118119
}
@@ -124,7 +125,7 @@ public function executeDataProvider(): array
124125
{
125126
return [
126127
'urls not equal' => [
127-
'loggerInfoExpects' => $this->exactly(2),
128+
'loggerInfoExpects' => $this->once(),
128129
'urlManagerGetUrlsWillReturn' => [
129130
'secure' => ['' => 'https://example2.com', '*' => 'https://subsite---example2.com'],
130131
'unsecure' => ['' => 'http://example2.com', '*' => 'http://subsite---example2.com'],

0 commit comments

Comments
 (0)