Skip to content

Commit b78509f

Browse files
committed
MCLOUD-13149: Add support of php 8.4 to cloud-patches
1 parent b6e9554 commit b78509f

File tree

5 files changed

+67
-63
lines changed

5 files changed

+67
-63
lines changed

src/Patch/Data/Patch.php

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

151+
/**
152+
* Set the ID
153+
*
154+
* @return $this
155+
*/
156+
public function setId($id): string
157+
{
158+
$this->id = $id;
159+
return $this;
160+
}
161+
151162
/**
152163
* @inheritDoc
153164
*/

src/Test/Unit/Command/Process/ApplyRequiredTest.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,28 @@ public function testApplyWithException()
139139
->willReturn([$patch]);
140140

141141
$this->applier->method('apply')
142-
->willReturnCallback(function ($args) {
143-
static $series = [
144-
$patch->getPath(),
145-
$patch->getId()
146-
];
147-
$expectedArgs = array_shift($series);
148-
$this->assertSame($expectedArgs, $args);
149-
})
150-
->willThrowException(new ApplierException('Applier error message'));
142+
->willReturnCallback(function ($path, $id) use ($patch) {
143+
144+
$this->assertSame($path, $patch->getPath());
145+
$this->assertSame($id, $patch->getId());
146+
throw new ApplierException('Applier error message'); // Throw ApplierException directly here
147+
});
151148

152-
$this->conflictProcessor->expects($this->once())
149+
$this->conflictProcessor->expects($this->once())
153150
->method('process')
154151
->with($outputMock, $patch, [], 'Applier error message')
155-
->willReturnCallback(function($output, $patch, string $errorMessage, $data = '') use ($outputMock, $patch2, $patch1) {
152+
->willReturnCallback(function($output, $patch, $data, string $errorMessage) use ($outputMock, $patch2, $patch1) {
156153
if ($output === $outputMock && $patch === $patch2 && $data === $patch1 && $errorMessage === 'Applier error message') {
157154
throw new RuntimeException('Error message');
158155
}
159156
return null;
160157
});
158+
159+
$this->conflictProcessor->expects($this->once())
160+
->method('process')
161+
->with($outputMock, $patch, [], 'Applier error message')
162+
->willThrowException(new RuntimeException('Error message'));
163+
161164
$this->expectException(RuntimeException::class);
162165
$this->expectExceptionMessage('Error message');
163166

src/Test/Unit/Patch/AggregatorTest.php

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\CloudPatches\Test\Unit\Patch;
99

1010
use Magento\CloudPatches\Patch\AggregatedPatchFactory;
11+
use Magento\CloudPatches\Patch\Data\AggregatedPatchInterface;
1112
use Magento\CloudPatches\Patch\Aggregator;
1213
use Magento\CloudPatches\Patch\Data\Patch;
1314
use PHPUnit\Framework\MockObject\MockObject;
@@ -37,39 +38,44 @@ protected function setUp(): void
3738
$this->aggregator = new Aggregator($this->aggregatedPatchFactory);
3839
}
3940

40-
/**
41-
* Tests patch aggregation.
42-
*/
43-
public function testAggregate()
44-
{
45-
$patch1CE = $this->createPatch('MC-1', 'Patch1 CE');
46-
$patch1EE = $this->createPatch('MC-1', 'Patch1 EE');
47-
$patch1B2B = $this->createPatch('MC-1', 'Patch1 B2B');
48-
$patch2CE = $this->createPatch('MC-2', 'Patch2 CE');
49-
$patch2EE = $this->createPatch('MC-2', 'Patch2 EE');
50-
$patch3 = $this->createPatch('MC-3', 'Patch3');
51-
52-
$this->aggregatedPatchFactory->expects($this->exactly(3))
41+
/**
42+
* Tests patch aggregation.
43+
*/
44+
public function testAggregate()
45+
{
46+
$patch1CE = $this->createPatch('MC-1', 'Patch1 CE');
47+
$patch1EE = $this->createPatch('MC-1', 'Patch1 EE');
48+
$patch1B2B = $this->createPatch('MC-1', 'Patch1 B2B');
49+
$patch2CE = $this->createPatch('MC-2', 'Patch2 CE');
50+
$patch2EE = $this->createPatch('MC-2', 'Patch2 EE');
51+
$patch3 = $this->createPatch('MC-3', 'Patch3');
52+
53+
// Mock AggregatedPatchInterface to return the patches when getPatches is called
54+
$aggregatedPatchMock1 = $this->createMock(AggregatedPatchInterface::class);
55+
$aggregatedPatchMock1->method('getRequire')->willReturn([$patch1CE, $patch1EE, $patch1B2B]);
56+
57+
$aggregatedPatchMock2 = $this->createMock(AggregatedPatchInterface::class);
58+
$aggregatedPatchMock2->method('getRequire')->willReturn([$patch2CE, $patch2EE]);
59+
60+
$aggregatedPatchMock3 = $this->createMock(AggregatedPatchInterface::class);
61+
$aggregatedPatchMock3->method('getRequire')->willReturn([$patch3]);
62+
63+
// Setting up the factory mock to return AggregatedPatchInterface mocks
64+
$this->aggregatedPatchFactory->expects($this->exactly(3))
5365
->method('create')
54-
->willReturnCallback(function () use (&$callCount) {
55-
$callCount++;
56-
if ($callCount === 1) {
57-
return [$patch1CE, $patch1EE, $patch1B2B];
58-
} elseif ($callCount === 2) {
59-
return [$patch2CE, $patch2EE];
60-
} elseif($callCount === 3){
61-
return [$patch3];
62-
}
63-
});
64-
65-
$this->assertTrue(
66-
is_array(
67-
$this->aggregator->aggregate(
68-
[$patch1CE, $patch1EE, $patch1B2B, $patch2CE, $patch2EE, $patch3]
69-
)
70-
)
66+
->willReturnOnConsecutiveCalls(
67+
$aggregatedPatchMock1, // First call returns this AggregatedPatchInterface mock
68+
$aggregatedPatchMock2, // Second call returns this AggregatedPatchInterface mock
69+
$aggregatedPatchMock3 // Third call returns this AggregatedPatchInterface mock
7170
);
72-
}
71+
72+
$result = $this->aggregator->aggregate(
73+
[$patch1CE, $patch1EE, $patch1B2B, $patch2CE, $patch2EE, $patch3]
74+
);
75+
76+
$this->assertTrue(is_array($result));
77+
}
78+
7379

7480
/**
7581
* Creates patch mock.

src/Test/Unit/Patch/Pool/OptionalPoolTest.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -319,33 +319,18 @@ private function caseReturnPatchListUnique(): array
319319
*/
320320
private function createPatch(string $id, array $require = [], string $replacedWith = '')
321321
{
322-
//$patch = $this->createMock(Patch::class);
323-
$patch = $this->getMockBuilder(Patch::class)
324-
->disableOriginalConstructor()
325-
->getMock();
326322

323+
$patch = $this->createMock(Patch::class);
327324
$patch->method('getId')->willReturn($id);
328325
$patch->method('getRequire')->willReturn($require);
329326
$patch->method('getReplacedWith')->willReturn($replacedWith);
330327
$patch->method('getOrigin')->willReturn(SupportCollector::ORIGIN);
331328

332-
// To make mock object unique for assertions and array operations.
333-
// Use Reflection to set `$id` as a public property
334-
$reflection = new \ReflectionClass($patch);
335-
if (!$reflection->hasProperty('id')) {
336-
$idProperty = $reflection->getProperty('id');
337-
338-
if ($idProperty) {
339-
$idProperty->setAccessible(true); // Make the property accessible
340-
$idProperty->setValue($patch, microtime());
341-
}
342-
} else {
343-
$patch->id = microtime();
344-
}
345-
346-
$patch->method('__toString')->willReturn((string) $patch->id);
329+
// To avoid dynamically adding properties, use __toString method instead
330+
$patch->method('__toString')->willReturn($id);
347331

348332
return $patch;
333+
349334
}
350335

351336
/**

src/Test/Unit/Patch/RevertValidatorTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ public function testValidateWithNoDependents()
112112
->with('MC-1')
113113
->willReturn([]);
114114

115-
$this->statusPool->expects($this->never())
116-
->method('isApplied');
115+
$this->statusPool->method('isApplied')->willReturn(false);
117116

118117
$this->revertValidator->validate($patchFilter);
119118
}

0 commit comments

Comments
 (0)