Skip to content

Commit a06399b

Browse files
committed
AC-15105: [CE] PHPUnit 12: Upgrade Payment & Shipping related test cases
1 parent c9f1ccc commit a06399b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\TestFramework\Unit\Helper;
9+
10+
use PHPUnit\Framework\MockObject\MockObject;
11+
use ReflectionClass;
12+
13+
/**
14+
* Trait for creating partial mocks with reflection for PHPUnit 12 migration
15+
*
16+
* Provides helper methods for creating mocks when standard PHPUnit methods are insufficient
17+
*/
18+
trait MockCreationTrait
19+
{
20+
/**
21+
* Create a partial mock with reflection.
22+
*
23+
* Use this when you need to mock methods that don't exist in the class/interface
24+
* and cannot use standard createPartialMock() which would throw CannotUseOnlyMethodsException.
25+
*
26+
* @param string $className
27+
* @param array $methods Methods to mock
28+
* @return MockObject
29+
*/
30+
protected function createPartialMockWithReflection(string $className, array $methods): MockObject
31+
{
32+
$reflection = new ReflectionClass($this);
33+
$getMockBuilderMethod = $reflection->getMethod('getMockBuilder');
34+
$getMockBuilderMethod->setAccessible(true);
35+
$mockBuilder = $getMockBuilderMethod->invoke($this, $className);
36+
37+
$builderReflection = new ReflectionClass($mockBuilder);
38+
$methodsProperty = $builderReflection->getProperty('methods');
39+
$methodsProperty->setAccessible(true);
40+
$methodsProperty->setValue($mockBuilder, $methods);
41+
42+
$mockBuilder->disableOriginalConstructor();
43+
return $mockBuilder->getMock();
44+
}
45+
}

0 commit comments

Comments
 (0)