Skip to content

Commit b6e9554

Browse files
MCLOUD-13149: Fixes for private property $id in test class + cosmetic fix
1 parent dc0e045 commit b6e9554

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function testApplyWithException()
152152
$this->conflictProcessor->expects($this->once())
153153
->method('process')
154154
->with($outputMock, $patch, [], 'Applier error message')
155-
->willReturnCallback(function($output, $patch, $data = '', string $errorMessage) use ($outputMock, $patch2, $patch1) {
155+
->willReturnCallback(function($output, $patch, string $errorMessage, $data = '') use ($outputMock, $patch2, $patch1) {
156156
if ($output === $outputMock && $patch === $patch2 && $data === $patch1 && $errorMessage === 'Applier error message') {
157157
throw new RuntimeException('Error message');
158158
}

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,31 @@ private function caseReturnPatchListUnique(): array
319319
*/
320320
private function createPatch(string $id, array $require = [], string $replacedWith = '')
321321
{
322-
$patch = $this->createMock(Patch::class);
322+
//$patch = $this->createMock(Patch::class);
323+
$patch = $this->getMockBuilder(Patch::class)
324+
->disableOriginalConstructor()
325+
->getMock();
326+
323327
$patch->method('getId')->willReturn($id);
324328
$patch->method('getRequire')->willReturn($require);
325329
$patch->method('getReplacedWith')->willReturn($replacedWith);
326330
$patch->method('getOrigin')->willReturn(SupportCollector::ORIGIN);
327331

328332
// To make mock object unique for assertions and array operations.
329-
$patch->id = microtime();
330-
$patch->method('__toString')->willReturn($patch->id);
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);
331347

332348
return $patch;
333349
}

0 commit comments

Comments
 (0)