File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
lib/internal/Magento/Framework/TestFramework/Unit/Helper Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -393,4 +393,27 @@ public function prepareObjectManager(array $map = [])
393393 $ reflectionProperty ->setAccessible (true );
394394 $ reflectionProperty ->setValue ($ objectManagerMock , $ objectManagerMock );
395395 }
396+
397+ /**
398+ * Create a partial mock with reflection.
399+ *
400+ * @param string $className
401+ * @param array $methods
402+ * @return MockObject
403+ */
404+ public function createPartialMockWithReflection (string $ className , array $ methods ): MockObject
405+ {
406+ $ reflection = new \ReflectionClass ($ this ->_testObject );
407+ $ getMockBuilderMethod = $ reflection ->getMethod ('getMockBuilder ' );
408+ $ getMockBuilderMethod ->setAccessible (true );
409+ $ mockBuilder = $ getMockBuilderMethod ->invoke ($ this ->_testObject , $ className );
410+
411+ $ builderReflection = new \ReflectionClass ($ mockBuilder );
412+ $ methodsProperty = $ builderReflection ->getProperty ('methods ' );
413+ $ methodsProperty ->setAccessible (true );
414+ $ methodsProperty ->setValue ($ mockBuilder , $ methods );
415+
416+ $ mockBuilder ->disableOriginalConstructor ();
417+ return $ mockBuilder ->getMock ();
418+ }
396419}
You can’t perform that action at this time.
0 commit comments