Skip to content

Commit dc0e045

Browse files
committed
Add support of php 8.4 to cloud-patches
1 parent 6a5be46 commit dc0e045

20 files changed

+591
-207
lines changed

src/Patch/Data/Patch.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,6 @@ public function getId(): string
148148
return $this->id;
149149
}
150150

151-
/**
152-
* @inheritDoc
153-
*/
154-
public function setId(): string
155-
{
156-
return $this->id;
157-
}
158-
159151
/**
160152
* @inheritDoc
161153
*/

src/Test/Unit/Command/Process/Action/ApplyOptionalActionTest.php

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ public function testExecuteSuccessful()
108108
$outputMock = $this->getMockForAbstractClass(OutputInterface::class);
109109
$this->optionalPool->expects($this->once())
110110
->method('getList')
111-
->withConsecutive([$patchFilter])
111+
->willReturnCallback(function($filter) use ($patchFilter, $patch1) {
112+
if ($filter === $patchFilter) {
113+
return [$patch1];
114+
}
115+
return [];
116+
})
112117
->willReturn([$patch1, $patch2, $patch3]);
113118

114119
$this->applier->method('apply')
@@ -117,18 +122,29 @@ public function testExecuteSuccessful()
117122
[$patch2->getPath(), $patch2->getId(), 'Patch ' . $patch2->getId() .' has been applied'],
118123
[$patch3->getPath(), $patch3->getId(), 'Patch ' . $patch3->getId() .' has been applied'],
119124
]);
120-
121125
$this->renderer->expects($this->exactly(3))
122-
->method('printPatchInfo')
123-
->withConsecutive(
124-
[$outputMock, $patch1, 'Patch ' . $patch1->getId() .' has been applied'],
125-
[$outputMock, $patch2, 'Patch ' . $patch2->getId() .' has been applied'],
126-
[$outputMock, $patch3, 'Patch ' . $patch3->getId() .' has been applied']
127-
);
128-
126+
->method('printPatchInfo')
127+
->willReturnCallback(function() use ($patch1, $patch2, $patch3) {
128+
static $callCount = 0;
129+
$expectedPatches = [$patch1, $patch2, $patch3];
130+
$expectedMessages = [
131+
'Patch ' . $patch1->getId() . ' has been applied',
132+
'Patch ' . $patch2->getId() . ' has been applied',
133+
'Patch ' . $patch3->getId() . ' has been applied'
134+
];
135+
136+
if ($patch === $expectedPatches[$callCount] && $message === $expectedMessages[$callCount]) {
137+
$callCount++;
138+
return true;
139+
}
140+
141+
return false;
142+
});
129143
$this->action->execute($inputMock, $outputMock, $patchFilter);
130144
}
131145

146+
147+
132148
/**
133149
* Tests successful optional patches applying.
134150
*
@@ -149,27 +165,31 @@ public function testApplyAlreadyAppliedPatch()
149165
$outputMock = $this->getMockForAbstractClass(OutputInterface::class);
150166
$this->optionalPool->expects($this->once())
151167
->method('getList')
152-
->withConsecutive([$patchFilter])
168+
->willReturnCallback(function($filter) use ($patchFilter, $patch1) {
169+
if ($filter === $patchFilter) {
170+
return [$patch1];
171+
}
172+
return [];
173+
})
153174
->willReturn([$patch1]);
154-
155175
$this->applier->expects($this->never())
156176
->method('apply');
157177
$this->renderer->expects($this->never())
158178
->method('printPatchInfo');
159179

160180
$outputMock->expects($this->once())
161181
->method('writeln')
162-
->withConsecutive(
163-
[
164-
$this->stringContains(
165-
'Patch ' . $patch1->getId() .' (' . $patch1->getFilename() . ') was already applied'
166-
)
167-
]
182+
->with(
183+
184+
$this->stringContains(
185+
'Patch ' . $patch1->getId() .' (' . $patch1->getFilename() . ') was already applied'
186+
)
168187
);
169188

170189
$this->action->execute($inputMock, $outputMock, $patchFilter);
171190
}
172191

192+
173193
/**
174194
* Tests successful optional patches applying.
175195
*
@@ -203,8 +223,8 @@ public function testApplyingAllPatchesAndSkipDeprecated()
203223

204224
$this->renderer->expects($this->once())
205225
->method('printPatchInfo')
206-
->withConsecutive(
207-
[$outputMock, $patch1, 'Patch ' . $patch1->getId() .' has been applied']
226+
->with(
227+
$outputMock, $patch1, 'Patch ' . $patch1->getId() .' has been applied'
208228
);
209229

210230
$this->action->execute($inputMock, $outputMock, $patchFilter);
@@ -232,27 +252,35 @@ public function testApplyWithException()
232252
->willReturn([$patch1, $patch2]);
233253

234254
$this->applier->method('apply')
235-
->willReturnMap([
236-
[$patch1->getPath(), $patch1->getId()],
237-
[$patch2->getPath(), $patch2->getId()]
238-
])->willReturnCallback(
239-
function ($path, $id) {
240-
if ($id === 'MC-22222') {
241-
throw new ApplierException('Applier error message');
242-
}
243-
244-
return "Patch {$path} {$id} has been applied";
255+
->willReturnCallback(function ($path, $id) use ($patch1, $patch2) {
256+
if ($id === 'MC-22222') {
257+
throw new ApplierException('Applier error message');
245258
}
246-
);
247-
259+
// Return success message for the first patch
260+
return "Patch {$path} {$id} has been applied";
261+
});
248262
$this->conflictProcessor->expects($this->once())
249263
->method('process')
250-
->withConsecutive([$outputMock, $patch2, [$patch1], 'Applier error message'])
264+
->willReturnCallback(function() use ($patch1, $patch2, $patch3) {
265+
static $callCount = 0;
266+
$expectedPatches = [$patch1, $patch2, $patch3];
267+
$expectedMessages = [
268+
'Patch ' . $patch1->getId() . ' has been applied',
269+
'Patch ' . $patch2->getId() . ' has been applied',
270+
'Patch ' . $patch3->getId() . ' has been applied'
271+
];
272+
273+
if ($patch === $expectedPatches[$callCount] && $message === $expectedMessages[$callCount]) {
274+
$callCount++;
275+
return true;
276+
}
277+
278+
return false;
279+
})
251280
->willThrowException(new RuntimeException('Error message'));
252281

253282
$this->expectException(RuntimeException::class);
254283
$this->expectExceptionMessage('Error message');
255-
256284
$this->action->execute($inputMock, $outputMock, $patchFilter);
257285
}
258286

src/Test/Unit/Command/Process/Action/ConfirmRequiredActionTest.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ public function testAskConfirmationForNotAppliedPatches()
9191
$outputMock = $this->getMockForAbstractClass(OutputInterface::class);
9292
$this->optionalPool->expects($this->once())
9393
->method('getAdditionalRequiredPatches')
94-
->withConsecutive([$patchFilter])
94+
->willReturnCallback(function($filter) use ($patchFilter, $patch1) {
95+
if ($filter === $patchFilter) {
96+
return [$patch1];
97+
}
98+
return [];
99+
})
95100
->willReturn([$patch1, $patch2, $patch3]);
96101

97102
$aggregatedPatch = $this->getMockForAbstractClass(AggregatedPatchInterface::class);
@@ -102,8 +107,13 @@ public function testAskConfirmationForNotAppliedPatches()
102107

103108
$this->renderer->expects($this->once())
104109
->method('printTable')
105-
->withConsecutive([$outputMock, [$aggregatedPatch]]);
106-
110+
->with($outputMock, [$aggregatedPatch])
111+
->willReturnCallback(function($output,$patches ) use ($outputMock, $aggregatedPatch) {
112+
if ($output === $outputMock && $aggregatedPatch === [$aggregatedPatch] ) {
113+
throw new RuntimeException('Error message');
114+
}
115+
return null;
116+
});
107117
$this->renderer->expects($this->once())
108118
->method('printQuestion')
109119
->willReturn(true);
@@ -124,7 +134,12 @@ public function testPatchNotFoundException()
124134
$outputMock = $this->getMockForAbstractClass(OutputInterface::class);
125135
$this->optionalPool->expects($this->once())
126136
->method('getAdditionalRequiredPatches')
127-
->withConsecutive([$patchFilter])
137+
->willReturnCallback(function($filter) use ($patchFilter, $patch1) {
138+
if ($filter === $patchFilter) {
139+
return [$patch1];
140+
}
141+
return [];
142+
})
128143
->willThrowException(new PatchNotFoundException(''));
129144

130145
$this->expectException(RuntimeException::class);
@@ -149,7 +164,12 @@ public function testConfirmationRejected()
149164
$outputMock = $this->getMockForAbstractClass(OutputInterface::class);
150165
$this->optionalPool->expects($this->once())
151166
->method('getAdditionalRequiredPatches')
152-
->withConsecutive([$patchFilter])
167+
->willReturnCallback(function($filter) use ($patchFilter, $patch1) {
168+
if ($filter === $patchFilter) {
169+
return [$patch1];
170+
}
171+
return [];
172+
})
153173
->willReturn([$patch1]);
154174

155175
$aggregatedPatch = $this->getMockForAbstractClass(AggregatedPatchInterface::class);
@@ -160,7 +180,13 @@ public function testConfirmationRejected()
160180

161181
$this->renderer->expects($this->once())
162182
->method('printTable')
163-
->withConsecutive([$outputMock, [$aggregatedPatch]]);
183+
->with($outputMock, [$aggregatedPatch])
184+
->willReturnCallback(function($output,$patches ) use ($outputMock, $aggregatedPatch) {
185+
if ($output === $outputMock && $aggregatedPatch === [$aggregatedPatch] ) {
186+
throw new RuntimeException('Error message');
187+
}
188+
return null;
189+
});
164190

165191
$this->renderer->expects($this->once())
166192
->method('printQuestion')

src/Test/Unit/Command/Process/Action/ProcessDeprecatedActionTest.php

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,21 @@ public function testProcessDeprecationSuccessful()
105105

106106
$this->optionalPool->expects($this->once())
107107
->method('getList')
108-
->withConsecutive([$patchFilter])
108+
->willReturnCallback(function($filter) use ($patchFilter, $patch1) {
109+
if ($filter === $patchFilter) {
110+
return [$patch1];
111+
}
112+
return [];
113+
})
109114
->willReturn([$patchMock]);
110115
$this->optionalPool->expects($this->once())
111116
->method('getReplacedBy')
112-
->withConsecutive([$patch1->getId()])
117+
->willReturnCallback(function($patchId) use ($patchFilter, $patch1) {
118+
if ($patchId === $patch1->getId()) {
119+
return [$patch1];
120+
}
121+
return [];
122+
})
113123
->willReturn([]);
114124

115125
$this->aggregator->expects($this->once())
@@ -118,8 +128,12 @@ public function testProcessDeprecationSuccessful()
118128

119129
$outputMock->expects($this->once())
120130
->method('writeln')
121-
->withConsecutive([$this->stringContains($expectedMessage)]);
122-
131+
->willReturnCallback(function($patchId) use ($patchFilter) {
132+
if ($patchId === $expectedMessage) {
133+
$this->stringContains($expectedMessage);
134+
}
135+
return [];
136+
});
123137
$this->renderer->expects($this->once())
124138
->method('printQuestion')
125139
->willReturn(true);
@@ -143,7 +157,12 @@ public function testProcessDeprecationException()
143157

144158
$this->optionalPool->expects($this->once())
145159
->method('getList')
146-
->withConsecutive([$patchFilter])
160+
->willReturnCallback(function($filter) use ($patchFilter, $patch1) {
161+
if ($filter === $patchFilter) {
162+
return [$patch1];
163+
}
164+
return [];
165+
})
147166
->willReturn([$patchMock]);
148167

149168
$this->aggregator->expects($this->once())
@@ -185,7 +204,12 @@ public function testProcessReplacementSuccessful()
185204

186205
$this->optionalPool->expects($this->once())
187206
->method('getList')
188-
->withConsecutive([$patchFilter])
207+
->willReturnCallback(function($filter) use ($patchFilter, $patch1) {
208+
if ($filter === $patchFilter) {
209+
return [$patch1];
210+
}
211+
return [];
212+
})
189213
->willReturn([$patchMock]);
190214

191215
$this->aggregator->expects($this->once())
@@ -194,12 +218,22 @@ public function testProcessReplacementSuccessful()
194218

195219
$this->optionalPool->expects($this->once())
196220
->method('getReplacedBy')
197-
->withConsecutive([$patch1->getId()])
221+
->willReturnCallback(function($filter) use ($patchFilter, $patch1) {
222+
if ($filter === $patchFilter) {
223+
return [$patch1];
224+
}
225+
return [];
226+
})
198227
->willReturn($requireReplacement);
199228

200229
$outputMock->expects($this->once())
201230
->method('writeln')
202-
->withConsecutive([$this->stringContains($expectedMessage)]);
231+
->willReturnCallback(function($patchId) use ($patchFilter) {
232+
if ($patchId === $expectedMessage) {
233+
$this->stringContains($expectedMessage);
234+
}
235+
return [];
236+
});
203237

204238
$this->renderer->expects($this->once())
205239
->method('printQuestion')
@@ -229,7 +263,12 @@ public function testSkippingReplacementProcessForAppliedPatch()
229263

230264
$this->optionalPool->expects($this->once())
231265
->method('getList')
232-
->withConsecutive([$patchFilter])
266+
->willReturnCallback(function($filter) use ($patchFilter, $patch1) {
267+
if ($filter === $patchFilter) {
268+
return [$patch1];
269+
}
270+
return [];
271+
})
233272
->willReturn([$patchMock]);
234273

235274
$this->aggregator->expects($this->once())
@@ -264,7 +303,12 @@ public function testProcessReplacementException()
264303

265304
$this->optionalPool->expects($this->once())
266305
->method('getList')
267-
->withConsecutive([$patchFilter])
306+
->willReturnCallback(function($filter) use ($patchFilter, $patch1) {
307+
if ($filter === $patchFilter) {
308+
return [$patch1];
309+
}
310+
return [];
311+
})
268312
->willReturn([$patchMock]);
269313

270314
$this->aggregator->expects($this->once())
@@ -273,7 +317,12 @@ public function testProcessReplacementException()
273317

274318
$this->optionalPool->expects($this->once())
275319
->method('getReplacedBy')
276-
->withConsecutive([$patch1->getId()])
320+
->willReturnCallback(function($patchId) use ($patchFilter, $patch1) {
321+
if ($patchId === $patch1->getId()) {
322+
return [$patch1];
323+
}
324+
return [];
325+
})
277326
->willReturn($requireReplacement);
278327

279328
$this->renderer->expects($this->once())

0 commit comments

Comments
 (0)